File tree Expand file tree Collapse file tree 3 files changed +40
-3
lines changed Expand file tree Collapse file tree 3 files changed +40
-3
lines changed Original file line number Diff line number Diff line change 1818use Mcp \Schema \Content \AudioContent ;
1919use Mcp \Schema \Content \EmbeddedResource ;
2020use Mcp \Schema \Content \ImageContent ;
21+ use Mcp \Schema \Content \StructuredContent ;
2122use Mcp \Schema \Content \TextContent ;
2223use Mcp \Schema \Request \CallToolRequest ;
2324use Mcp \Schema \Result \CallToolResult ;
@@ -59,7 +60,16 @@ public function call(CallToolRequest $request): CallToolResult
5960
6061 try {
6162 $ result = $ this ->referenceHandler ->handle ($ toolReference , $ arguments );
62- /** @var TextContent[]|ImageContent[]|EmbeddedResource[]|AudioContent[] $formattedResult */
63+
64+ if ($ result instanceof CallToolResult) {
65+ $ this ->logger ->debug ('Tool executed successfully ' , [
66+ 'name ' => $ toolName ,
67+ 'result_type ' => \gettype ($ result ),
68+ ]);
69+
70+ return $ result ;
71+ }
72+ /** @var array<int, TextContent|ImageContent|EmbeddedResource|AudioContent|StructuredContent> $formattedResult */
6373 $ formattedResult = $ toolReference ->formatResult ($ result );
6474
6575 $ this ->logger ->debug ('Tool executed successfully ' , [
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /*
4+ * This file is part of the official PHP MCP SDK.
5+ *
6+ * A collaboration between Symfony and the PHP Foundation.
7+ *
8+ * For the full copyright and license information, please view the LICENSE
9+ * file that was distributed with this source code.
10+ */
11+
12+ namespace Mcp \Schema \Content ;
13+
14+ class StructuredContent extends Content
15+ {
16+ public function __construct (
17+ private array $ data = [],
18+ ) {
19+ parent ::__construct ('structured ' );
20+ }
21+
22+ public function jsonSerialize (): mixed
23+ {
24+ return json_encode ($ this ->data );
25+ }
26+ }
Original file line number Diff line number Diff line change 1616use Mcp \Schema \Content \Content ;
1717use Mcp \Schema \Content \EmbeddedResource ;
1818use Mcp \Schema \Content \ImageContent ;
19+ use Mcp \Schema \Content \StructuredContent ;
1920use Mcp \Schema \Content \TextContent ;
2021use Mcp \Schema \JsonRpc \Response ;
2122use Mcp \Schema \JsonRpc \ResultInterface ;
@@ -44,7 +45,7 @@ class CallToolResult implements ResultInterface
4445 /**
4546 * Create a new CallToolResult.
4647 *
47- * @param array<TextContent|ImageContent|AudioContent|EmbeddedResource> $content The content of the tool result
48+ * @param array<TextContent|ImageContent|AudioContent|EmbeddedResource|StructuredContent > $content The content of the tool result
4849 * @param bool $isError Whether the tool execution resulted in an error. If not set, this is assumed to be false (the call was successful).
4950 */
5051 public function __construct (
@@ -107,7 +108,7 @@ public static function fromArray(array $data): self
107108
108109 /**
109110 * @return array{
110- * content: array<TextContent|ImageContent|AudioContent|EmbeddedResource>,
111+ * content: array<TextContent|ImageContent|AudioContent|EmbeddedResource|StructuredContent >,
111112 * isError: bool,
112113 * }
113114 */
You can’t perform that action at this time.
0 commit comments