fix: cast empty properties arrays to stdClass to prevent JSON [] instead of {}

This commit is contained in:
2026-05-14 15:15:36 +00:00
parent 67915591ad
commit 580e2ef193
+12 -5
View File
@@ -29,11 +29,18 @@ class Registry {
/** Returns MCP-formatted tool definitions for tools/list response */ /** Returns MCP-formatted tool definitions for tools/list response */
public function getToolDefinitions(): array { public function getToolDefinitions(): array {
return array_values(array_map(fn($t) => [ return array_values(array_map(function($t) {
'name' => $t['name'], $schema = $t['inputSchema'];
'description' => $t['description'], // PHP encodes empty [] as JSON array — cast to stdClass to get {}
'inputSchema' => $t['inputSchema'], if (isset($schema['properties']) && $schema['properties'] === []) {
], $this->tools)); $schema['properties'] = new \stdClass();
}
return [
'name' => $t['name'],
'description' => $t['description'],
'inputSchema' => $schema,
];
}, $this->tools));
} }
/** Returns callable handler for a tool, or null if not found */ /** Returns callable handler for a tool, or null if not found */