-
Notifications
You must be signed in to change notification settings - Fork 150
Expand file tree
/
Copy pathCallToolRequest.php
More file actions
71 lines (60 loc) · 1.79 KB
/
Copy pathCallToolRequest.php
File metadata and controls
71 lines (60 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/*
* This file is part of the official PHP MCP SDK.
*
* A collaboration between Symfony and the PHP Foundation.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mcp\Schema\Request;
use Mcp\Exception\InvalidArgumentException;
use Mcp\Schema\JsonRpc\Request;
/**
* Used by the client to invoke a tool provided by the server.
*
* @author Kyrian Obikwelu <koshnawaza@gmail.com>
*/
final class CallToolRequest extends Request
{
/**
* @param string $name the name of the tool to invoke
* @param array<string, mixed> $arguments the arguments to pass to the tool
*/
public function __construct(
public readonly string $name,
public readonly array $arguments,
) {
}
public static function getMethod(): string
{
return 'tools/call';
}
protected static function fromParams(?array $params): static
{
if (!isset($params['name']) || !\is_string($params['name'])) {
throw new InvalidArgumentException('Missing or invalid "name" parameter for tools/call.');
}
$arguments = $params['arguments'] ?? [];
if ($arguments instanceof \stdClass) {
$arguments = (array) $arguments;
}
if (!\is_array($arguments)) {
throw new InvalidArgumentException('Parameter "arguments" must be an array.');
}
return new self(
$params['name'],
$arguments,
);
}
/**
* @return array{name: string, arguments: array<string, mixed>}
*/
protected function getParams(): array
{
return [
'name' => $this->name,
'arguments' => $this->arguments ?: new \stdClass(),
];
}
}