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
+10 -3
View File
@@ -29,11 +29,18 @@ class Registry {
/** Returns MCP-formatted tool definitions for tools/list response */
public function getToolDefinitions(): array {
return array_values(array_map(fn($t) => [
return array_values(array_map(function($t) {
$schema = $t['inputSchema'];
// PHP encodes empty [] as JSON array — cast to stdClass to get {}
if (isset($schema['properties']) && $schema['properties'] === []) {
$schema['properties'] = new \stdClass();
}
return [
'name' => $t['name'],
'description' => $t['description'],
'inputSchema' => $t['inputSchema'],
], $this->tools));
'inputSchema' => $schema,
];
}, $this->tools));
}
/** Returns callable handler for a tool, or null if not found */