Skip to content

Commit 86cad84

Browse files
committed
Add _meta field for Tool
1 parent cbae9b9 commit 86cad84

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

src/Capability/Attribute/McpTool.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public function __construct(
2828
public ?string $name = null,
2929
public ?string $description = null,
3030
public ?ToolAnnotations $annotations = null,
31+
public ?array $_meta = null,
3132
) {
3233
}
3334
}

src/Capability/Discovery/Discoverer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@ private function processMethod(\ReflectionMethod $method, array &$discoveredCoun
222222
$name = $instance->name ?? ('__invoke' === $methodName ? $classShortName : $methodName);
223223
$description = $instance->description ?? $this->docBlockParser->getSummary($docBlock) ?? null;
224224
$inputSchema = $this->schemaGenerator->generate($method);
225-
$tool = new Tool($name, $inputSchema, $description, $instance->annotations);
225+
$_meta = $instance->_meta ?? null;
226+
$tool = new Tool($name, $inputSchema, $description, $instance->annotations, $_meta);
226227
$tools[$name] = new ToolReference($tool, [$className, $methodName], false);
227228
++$discoveredCount['tools'];
228229
break;

src/Capability/Registry/Loader/ArrayLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function load(ReferenceRegistryInterface $registry): void
102102

103103
$inputSchema = $data['inputSchema'] ?? $schemaGenerator->generate($reflection);
104104

105-
$tool = new Tool($name, $inputSchema, $description, $data['annotations']);
105+
$tool = new Tool($name, $inputSchema, $description, $data['annotations'], $data['_meta'] ?? null);
106106
$registry->registerTool($tool, $data['handler'], true);
107107

108108
$handlerDesc = $this->getHandlerDescription($data['handler']);

src/Schema/Tool.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public function __construct(
4747
public readonly array $inputSchema,
4848
public readonly ?string $description,
4949
public readonly ?ToolAnnotations $annotations,
50+
public readonly ?array $_meta = null,
5051
) {
5152
if (!isset($inputSchema['type']) || 'object' !== $inputSchema['type']) {
5253
throw new InvalidArgumentException('Tool inputSchema must be a JSON Schema of type "object".');
@@ -75,7 +76,8 @@ public static function fromArray(array $data): self
7576
$data['name'],
7677
$data['inputSchema'],
7778
isset($data['description']) && \is_string($data['description']) ? $data['description'] : null,
78-
isset($data['annotations']) && \is_array($data['annotations']) ? ToolAnnotations::fromArray($data['annotations']) : null
79+
isset($data['annotations']) && \is_array($data['annotations']) ? ToolAnnotations::fromArray($data['annotations']) : null,
80+
isset($data['_meta']) && \is_array($data['_meta']) ? $data['_meta'] : null
7981
);
8082
}
8183

@@ -99,6 +101,9 @@ public function jsonSerialize(): array
99101
if (null !== $this->annotations) {
100102
$data['annotations'] = $this->annotations;
101103
}
104+
if (null !== $this->_meta) {
105+
$data['_meta'] = $this->_meta;
106+
}
102107

103108
return $data;
104109
}

0 commit comments

Comments
 (0)