From d79ae915c3111a187c0679fcb3885ef134da43d9 Mon Sep 17 00:00:00 2001 From: Szana Szabolcs Date: Mon, 13 Oct 2025 09:36:13 +0200 Subject: [PATCH] Add meta data option to Tool --- src/Server/Tool.php | 12 +++++++++++- tests/Pest.php | 2 ++ tests/Unit/Methods/ListToolsTest.php | 1 + tests/Unit/Resources/ListToolsTest.php | 1 + tests/Unit/Tools/ToolTest.php | 22 ++++++++++++++++++++++ 5 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/Server/Tool.php b/src/Server/Tool.php index 593cff7..4fd8b45 100644 --- a/src/Server/Tool.php +++ b/src/Server/Tool.php @@ -19,6 +19,14 @@ public function schema(JsonSchema $schema): array return []; } + /** + * @return array + */ + public function meta(): array + { + return []; + } + /** * @return array */ @@ -51,7 +59,8 @@ public function toMethodCall(): array * title?: string|null, * description?: string|null, * inputSchema?: array, - * annotations?: array|object + * annotations?: array|object, + * _meta?: array * } */ public function toArray(): array @@ -66,6 +75,7 @@ public function toArray(): array fn (JsonSchema $schema): array => $this->schema($schema), )->toArray(), 'annotations' => $annotations === [] ? (object) [] : $annotations, + '_meta' => $this->meta(), ]; } } diff --git a/tests/Pest.php b/tests/Pest.php index 3f55746..731c29a 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -111,6 +111,7 @@ function expectedListToolsResponse(): array ], 'annotations' => [], 'title' => 'Say Hi Tool', + '_meta' => [], ], [ 'name' => 'streaming-tool', @@ -127,6 +128,7 @@ function expectedListToolsResponse(): array ], 'annotations' => [], 'title' => 'Streaming Tool', + '_meta' => [], ], ], ], diff --git a/tests/Unit/Methods/ListToolsTest.php b/tests/Unit/Methods/ListToolsTest.php index 027a742..046fa04 100644 --- a/tests/Unit/Methods/ListToolsTest.php +++ b/tests/Unit/Methods/ListToolsTest.php @@ -68,6 +68,7 @@ public function handle(array \$arguments): ToolResult|Generator { return []; } ], 'annotations' => (object) [], 'title' => 'Say Hi Tool', + '_meta' => [], ], ], ]); diff --git a/tests/Unit/Resources/ListToolsTest.php b/tests/Unit/Resources/ListToolsTest.php index 027a742..046fa04 100644 --- a/tests/Unit/Resources/ListToolsTest.php +++ b/tests/Unit/Resources/ListToolsTest.php @@ -68,6 +68,7 @@ public function handle(array \$arguments): ToolResult|Generator { return []; } ], 'annotations' => (object) [], 'title' => 'Say Hi Tool', + '_meta' => [], ], ], ]); diff --git a/tests/Unit/Tools/ToolTest.php b/tests/Unit/Tools/ToolTest.php index 11f7a8a..ff34cda 100644 --- a/tests/Unit/Tools/ToolTest.php +++ b/tests/Unit/Tools/ToolTest.php @@ -62,6 +62,18 @@ expect($tool->annotations()['openWorldHint'])->toBeTrue(); }); +it('returns empty array when meta not defined', function (): void { + $tool = new TestTool; + expect($tool->meta())->toEqual([]); +}); + +it('returns meta when defined', function (): void { + $tool = new ToolWithMeta; + expect($tool->meta())->toEqual([ + 'foo' => 'bar', + ]); +}); + it('can have multiple annotations', function (): void { $tool = new KitchenSinkTool; expect($tool->annotations())->toEqual([ @@ -123,3 +135,13 @@ class CustomToolName extends TestTool { protected string $name = 'my_custom_tool_name'; } + +class ToolWithMeta extends TestTool +{ + public function meta(): array + { + return [ + 'foo' => 'bar', + ]; + } +}