convertkit
/
vendor
/
wordpress
/
php-mcp-schema
/
src
/
Server
/
Tools
/
DTO
/
CallToolRequestParams.php
CallToolRequestParams.php in Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages 3.4.3, at vendor/wordpress/php-mcp-schema/src/Server/Tools/DTO/CallToolRequestParams.php
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace WP\McpSchema\Server\Tools\DTO; |
| 6 | |
| 7 | use WP\McpSchema\Client\Tasks\DTO\TaskMetadata; |
| 8 | use WP\McpSchema\Common\JsonRpc\DTO\RequestParamsMeta; |
| 9 | use WP\McpSchema\Common\Tasks\DTO\TaskAugmentedRequestParams; |
| 10 | use WP\McpSchema\Common\Traits\ValidatesRequiredFields; |
| 11 | |
| 12 | /** |
| 13 | * Parameters for a `tools/call` request. |
| 14 | * |
| 15 | * @since 2025-11-25 |
| 16 | * |
| 17 | * @mcp-domain Server |
| 18 | * @mcp-subdomain Tools |
| 19 | * @mcp-version 2025-11-25 |
| 20 | */ |
| 21 | class CallToolRequestParams extends TaskAugmentedRequestParams |
| 22 | { |
| 23 | use ValidatesRequiredFields; |
| 24 | |
| 25 | /** |
| 26 | * The name of the tool. |
| 27 | * |
| 28 | * @since 2025-11-25 |
| 29 | * |
| 30 | * @var string |
| 31 | */ |
| 32 | protected string $name; |
| 33 | |
| 34 | /** |
| 35 | * Arguments to use for the tool call. |
| 36 | * |
| 37 | * @since 2025-11-25 |
| 38 | * |
| 39 | * @var array<string, mixed>|null |
| 40 | */ |
| 41 | protected ?array $arguments; |
| 42 | |
| 43 | /** |
| 44 | * @param string $name @since 2025-11-25 |
| 45 | * @param \WP\McpSchema\Client\Tasks\DTO\TaskMetadata|null $task @since 2025-11-25 |
| 46 | * @param \WP\McpSchema\Common\JsonRpc\DTO\RequestParamsMeta|null $_meta @since 2025-11-25 |
| 47 | * @param array<string, mixed>|null $arguments @since 2025-11-25 |
| 48 | */ |
| 49 | public function __construct( |
| 50 | string $name, |
| 51 | ?TaskMetadata $task = null, |
| 52 | ?RequestParamsMeta $_meta = null, |
| 53 | ?array $arguments = null |
| 54 | ) { |
| 55 | parent::__construct($_meta, $task); |
| 56 | $this->name = $name; |
| 57 | $this->arguments = $arguments; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Creates an instance from an array. |
| 62 | * |
| 63 | * @param array{ |
| 64 | * task?: array<string, mixed>|\WP\McpSchema\Client\Tasks\DTO\TaskMetadata|null, |
| 65 | * _meta?: array<string, mixed>|\WP\McpSchema\Common\JsonRpc\DTO\RequestParamsMeta|null, |
| 66 | * name: string, |
| 67 | * arguments?: array<string, mixed>|null |
| 68 | * } $data |
| 69 | * @phpstan-param array<string, mixed> $data |
| 70 | * @return self |
| 71 | */ |
| 72 | public static function fromArray(array $data): self |
| 73 | { |
| 74 | self::assertRequired($data, ['name']); |
| 75 | |
| 76 | /** @var \WP\McpSchema\Client\Tasks\DTO\TaskMetadata|null $task */ |
| 77 | $task = isset($data['task']) |
| 78 | ? (is_array($data['task']) |
| 79 | ? TaskMetadata::fromArray(self::asArray($data['task'])) |
| 80 | : $data['task']) |
| 81 | : null; |
| 82 | |
| 83 | /** @var \WP\McpSchema\Common\JsonRpc\DTO\RequestParamsMeta|null $_meta */ |
| 84 | $_meta = isset($data['_meta']) |
| 85 | ? (is_array($data['_meta']) |
| 86 | ? RequestParamsMeta::fromArray(self::asArray($data['_meta'])) |
| 87 | : $data['_meta']) |
| 88 | : null; |
| 89 | |
| 90 | return new self( |
| 91 | self::asString($data['name']), |
| 92 | $task, |
| 93 | $_meta, |
| 94 | self::asArrayOrNull($data['arguments'] ?? null) |
| 95 | ); |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Converts the instance to an array. |
| 100 | * |
| 101 | * @return array<string, mixed> |
| 102 | */ |
| 103 | public function toArray(): array |
| 104 | { |
| 105 | $result = parent::toArray(); |
| 106 | |
| 107 | $result['name'] = $this->name; |
| 108 | if ($this->arguments !== null) { |
| 109 | $result['arguments'] = $this->arguments; |
| 110 | } |
| 111 | |
| 112 | return $result; |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * @return string |
| 117 | */ |
| 118 | public function getName(): string |
| 119 | { |
| 120 | return $this->name; |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * @return array<string, mixed>|null |
| 125 | */ |
| 126 | public function getArguments(): ?array |
| 127 | { |
| 128 | return $this->arguments; |
| 129 | } |
| 130 | } |
| 131 |