Skip to content

Commit 63ffeed

Browse files
authored
[Server] Fix wrong parameter order when creating the tool from array (#147)
Previously, the meta parameter was incorrectly passed to the icons position due to missing icons argument. Also adds icons support to Builder::addTool() for consistency with the Tool schema.
1 parent 8daca81 commit 63ffeed

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/Capability/Registry/Loader/ArrayLoader.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ final class ArrayLoader implements LoaderInterface
4545
* name: ?string,
4646
* description: ?string,
4747
* annotations: ?ToolAnnotations,
48+
* icons: ?array<int, \Mcp\Schema\Icon>,
4849
* meta: ?array<string, mixed>
4950
* }[] $tools
5051
* @param array{
@@ -106,7 +107,14 @@ public function load(ReferenceRegistryInterface $registry): void
106107

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

109-
$tool = new Tool($name, $inputSchema, $description, $data['annotations'], $data['meta'] ?? null);
110+
$tool = new Tool(
111+
name: $name,
112+
inputSchema: $inputSchema,
113+
description: $description,
114+
annotations: $data['annotations'] ?? null,
115+
icons: $data['icons'] ?? null,
116+
meta: $data['meta'] ?? null,
117+
);
110118
$registry->registerTool($tool, $data['handler'], true);
111119

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

src/Server/Builder.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ final class Builder
8383
* name: ?string,
8484
* description: ?string,
8585
* annotations: ?ToolAnnotations,
86+
* icons: ?array<int, Icon>,
8687
* meta: ?array<string, mixed>
8788
* }[]
8889
*/
@@ -315,6 +316,7 @@ public function setProtocolVersion(ProtocolVersion $protocolVersion): self
315316
*
316317
* @param Handler $handler
317318
* @param array<string, mixed>|null $inputSchema
319+
* @param Icon[]|null $icons
318320
* @param array<string, mixed>|null $meta
319321
*/
320322
public function addTool(
@@ -323,9 +325,10 @@ public function addTool(
323325
?string $description = null,
324326
?ToolAnnotations $annotations = null,
325327
?array $inputSchema = null,
328+
?array $icons = null,
326329
?array $meta = null,
327330
): self {
328-
$this->tools[] = compact('handler', 'name', 'description', 'annotations', 'inputSchema', 'meta');
331+
$this->tools[] = compact('handler', 'name', 'description', 'annotations', 'inputSchema', 'icons', 'meta');
329332

330333
return $this;
331334
}

0 commit comments

Comments
 (0)