Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/Server/Tool.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ public function schema(JsonSchema $schema): array
return [];
}

/**
* @return array<string, string>
*/
public function meta(): array
{
return [];
}

/**
* @return array<string, mixed>
*/
Expand Down Expand Up @@ -51,7 +59,8 @@ public function toMethodCall(): array
* title?: string|null,
* description?: string|null,
* inputSchema?: array<string, mixed>,
* annotations?: array<string, mixed>|object
* annotations?: array<string, mixed>|object,
* _meta?: array<string, string>
* }
*/
public function toArray(): array
Expand All @@ -66,6 +75,7 @@ public function toArray(): array
fn (JsonSchema $schema): array => $this->schema($schema),
)->toArray(),
'annotations' => $annotations === [] ? (object) [] : $annotations,
'_meta' => $this->meta(),
];
}
}
2 changes: 2 additions & 0 deletions tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ function expectedListToolsResponse(): array
],
'annotations' => [],
'title' => 'Say Hi Tool',
'_meta' => [],
],
[
'name' => 'streaming-tool',
Expand All @@ -127,6 +128,7 @@ function expectedListToolsResponse(): array
],
'annotations' => [],
'title' => 'Streaming Tool',
'_meta' => [],
],
],
],
Expand Down
1 change: 1 addition & 0 deletions tests/Unit/Methods/ListToolsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public function handle(array \$arguments): ToolResult|Generator { return []; }
],
'annotations' => (object) [],
'title' => 'Say Hi Tool',
'_meta' => [],
],
],
]);
Expand Down
1 change: 1 addition & 0 deletions tests/Unit/Resources/ListToolsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public function handle(array \$arguments): ToolResult|Generator { return []; }
],
'annotations' => (object) [],
'title' => 'Say Hi Tool',
'_meta' => [],
],
],
]);
Expand Down
22 changes: 22 additions & 0 deletions tests/Unit/Tools/ToolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down Expand Up @@ -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',
];
}
}