PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / trunk
Booking for Appointments and Events Calendar – Amelia vtrunk
2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / vendor / wordpress / php-mcp-schema / src / Server / Tools / DTO / CallToolResult.php
ameliabooking / vendor / wordpress / php-mcp-schema / src / Server / Tools / DTO Last commit date
CallToolRequest.php 1 month ago CallToolRequestParams.php 1 month ago CallToolResult.php 1 month ago ListToolsRequest.php 1 month ago ListToolsResult.php 1 month ago Tool.php 1 month ago ToolAnnotations.php 1 month ago ToolExecution.php 1 month ago ToolInputSchema.php 1 month ago ToolListChangedNotification.php 1 month ago ToolOutputSchema.php 1 month ago
CallToolResult.php
159 lines
1 <?php
2
3 declare(strict_types=1);
4
5 namespace WP\McpSchema\Server\Tools\DTO;
6
7 use WP\McpSchema\Common\Protocol\DTO\Result;
8 use WP\McpSchema\Common\Protocol\Factory\ContentBlockFactory;
9 use WP\McpSchema\Common\Protocol\Union\ContentBlockInterface;
10 use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
11 use WP\McpSchema\Server\Lifecycle\Union\ServerResultInterface;
12
13 /**
14 * The server's response to a tool call.
15 *
16 * @since 2024-11-05
17 * @last-updated 2025-11-25 (modified property: content)
18 *
19 * @mcp-domain Server
20 * @mcp-subdomain Tools
21 * @mcp-version 2025-11-25
22 */
23 class CallToolResult extends Result implements ServerResultInterface
24 {
25 use ValidatesRequiredFields;
26
27 /**
28 * A list of content objects that represent the unstructured result of the tool call.
29 *
30 * @since 2024-11-05
31 *
32 * @var array<\WP\McpSchema\Common\Protocol\Union\ContentBlockInterface>
33 */
34 protected array $content;
35
36 /**
37 * An optional JSON object that represents the structured result of the tool call.
38 *
39 * @since 2025-06-18
40 *
41 * @var array<string, mixed>|null
42 */
43 protected ?array $structuredContent;
44
45 /**
46 * Whether the tool call ended in an error.
47 *
48 * If not set, this is assumed to be false (the call was successful).
49 *
50 * Any errors that originate from the tool SHOULD be reported inside the result
51 * object, with `isError` set to true, _not_ as an MCP protocol-level error
52 * response. Otherwise, the LLM would not be able to see that an error occurred
53 * and self-correct.
54 *
55 * However, any errors in _finding_ the tool, an error indicating that the
56 * server does not support tool calls, or any other exceptional conditions,
57 * should be reported as an MCP error response.
58 *
59 * @since 2024-11-05
60 *
61 * @var bool|null
62 */
63 protected ?bool $isError;
64
65 /**
66 * @param array<\WP\McpSchema\Common\Protocol\Union\ContentBlockInterface> $content @since 2024-11-05
67 * @param array<string, mixed>|null $_meta @since 2024-11-05
68 * @param array<string, mixed>|null $structuredContent @since 2025-06-18
69 * @param bool|null $isError @since 2024-11-05
70 */
71 public function __construct(
72 array $content,
73 ?array $_meta = null,
74 ?array $structuredContent = null,
75 ?bool $isError = null
76 ) {
77 parent::__construct($_meta);
78 $this->content = $content;
79 $this->structuredContent = $structuredContent;
80 $this->isError = $isError;
81 }
82
83 /**
84 * Creates an instance from an array.
85 *
86 * @param array{
87 * _meta?: array<string, mixed>|null,
88 * content: array<array<string, mixed>|\WP\McpSchema\Common\Protocol\Union\ContentBlockInterface>,
89 * structuredContent?: array<string, mixed>|null,
90 * isError?: bool|null
91 * } $data
92 * @phpstan-param array<string, mixed> $data
93 * @return self
94 */
95 public static function fromArray(array $data): self
96 {
97 self::assertRequired($data, ['content']);
98
99 /** @var array<\WP\McpSchema\Common\Protocol\Union\ContentBlockInterface> $content */
100 $content = array_map(
101 static fn($item) => is_array($item)
102 ? ContentBlockFactory::fromArray($item)
103 : $item,
104 self::asArray($data['content'])
105 );
106
107 return new self(
108 $content,
109 self::asArrayOrNull($data['_meta'] ?? null),
110 self::asArrayOrNull($data['structuredContent'] ?? null),
111 self::asBoolOrNull($data['isError'] ?? null)
112 );
113 }
114
115 /**
116 * Converts the instance to an array.
117 *
118 * @return array<string, mixed>
119 */
120 public function toArray(): array
121 {
122 $result = parent::toArray();
123
124 $result['content'] = array_map(static fn($item) => $item->toArray(), $this->content);
125 if ($this->structuredContent !== null) {
126 $result['structuredContent'] = $this->structuredContent;
127 }
128 if ($this->isError !== null) {
129 $result['isError'] = $this->isError;
130 }
131
132 return $result;
133 }
134
135 /**
136 * @return array<\WP\McpSchema\Common\Protocol\Union\ContentBlockInterface>
137 */
138 public function getContent(): array
139 {
140 return $this->content;
141 }
142
143 /**
144 * @return array<string, mixed>|null
145 */
146 public function getStructuredContent(): ?array
147 {
148 return $this->structuredContent;
149 }
150
151 /**
152 * @return bool|null
153 */
154 public function getIsError(): ?bool
155 {
156 return $this->isError;
157 }
158 }
159