| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | /** |
| 6: | * This file is part of the Nexus MCP SDK package. |
| 7: | * |
| 8: | * (c) 2025 John Paul E. Balandan, CPA <paulbalandan@gmail.com> |
| 9: | * |
| 10: | * For the full copyright and license information, please view |
| 11: | * the LICENSE file that was distributed with this source code. |
| 12: | */ |
| 13: | |
| 14: | namespace Nexus\Mcp\Schema\Request; |
| 15: | |
| 16: | use Nexus\Mcp\Schema\Message\JsonRpcRequest; |
| 17: | use Nexus\Mcp\Schema\Message\RequestId; |
| 18: | |
| 19: | /** |
| 20: | * Used by the client to invoke a tool provided by the server. |
| 21: | * |
| 22: | * @extends JsonRpcRequest<array{ |
| 23: | * jsonrpc: '2.0', |
| 24: | * id: int|non-empty-string, |
| 25: | * method: 'tools/call', |
| 26: | * params: array{ |
| 27: | * _meta?: array<string, mixed>, |
| 28: | * name: non-empty-string, |
| 29: | * arguments?: array<string, mixed>, |
| 30: | * }, |
| 31: | * }> |
| 32: | */ |
| 33: | final readonly class CallToolRequest extends JsonRpcRequest implements ClientRequest |
| 34: | { |
| 35: | /** |
| 36: | * @param non-empty-string $name The name of the tool to invoke. |
| 37: | * @param null|array<string, mixed> $arguments The arguments to pass to the tool, if any. |
| 38: | * @param null|array<string, mixed> $meta Reserved by MCP to allow clients and servers to attach |
| 39: | * additional metadata to their interactions. |
| 40: | */ |
| 41: | public function __construct(RequestId $id, string $name, ?array $arguments = null, ?array $meta = null) |
| 42: | { |
| 43: | parent::__construct(self::JSON_RPC_VERSION, $id, 'tools/call', array_filter([ |
| 44: | '_meta' => $meta, |
| 45: | 'name' => $name, |
| 46: | 'arguments' => $arguments, |
| 47: | ], static fn(mixed $value): bool => null !== $value)); |
| 48: | } |
| 49: | } |
| 50: |