Skip to content
Merged
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
3 changes: 2 additions & 1 deletion src/MCP/McpConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ protected function createTool(array $item): ToolInterface
{
$tool = Tool::make(
name: $item['name'],
description: $item['description'] ?? null
description: $item['description'] ?? null,
annotations: $item['annotations'] ?? [],
)->setCallable(function (...$arguments) use ($item) {
$response = \call_user_func($this->client->callTool(...), $item['name'], $arguments);

Expand Down
14 changes: 12 additions & 2 deletions src/Tools/Tool.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use NeuronAI\StructuredOutput\Deserializer\DeserializerException;

/**
* @method static static make(?string $name = null, ?string $description = null, array $properties = [])
* @method static static make(?string $name = null, ?string $description = null, array $properties = [], array $annotations = [])
*/
class Tool implements ToolInterface
{
Expand Down Expand Up @@ -51,11 +51,13 @@ class Tool implements ToolInterface
* Tool constructor.
*
* @param ToolPropertyInterface[] $properties
* @param array<string, mixed> $annotations
*/
public function __construct(
protected string $name,
protected ?string $description = null,
array $properties = []
array $properties = [],
protected array $annotations = [],
) {
if ($properties !== []) {
$this->properties = $properties;
Expand Down Expand Up @@ -86,6 +88,14 @@ protected function properties(): array
return [];
}

/**
* @return array<string, mixed>
*/
public function getAnnotations(): array
{
return $this->annotations;
}

/**
* @return ToolPropertyInterface[]
*/
Expand Down
6 changes: 6 additions & 0 deletions src/Tools/ToolInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ public function addProperty(ToolPropertyInterface $property): ToolInterface;
*/
public function getProperties(): array;

/**
* Get the annotations present on the tool.
* @return array<string, mixed>
*/
public function getAnnotations(): array;

/**
* Names of the required properties.
*
Expand Down
12 changes: 12 additions & 0 deletions tests/Tools/ToolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -465,4 +465,16 @@ public function test_properties_declaration_on_constructor_with_parent_construct
$this->assertEquals('test tool', $tool->getDescription());
$this->assertEquals('test', $tool->getKey());
}

public function test_annotations(): void
{
$tool = Tool::make('foo-bar', 'description', annotations: [
'readOnly' => true,
'idempotent' => false,
]);
$this->assertEquals([
'readOnly' => true,
'idempotent' => false,
], $tool->getAnnotations());
}
}