summaryrefslogtreecommitdiff
path: root/packages/server/src/tools/tool-registry.ts
diff options
context:
space:
mode:
authorTaylor Mullen <[email protected]>2025-05-16 22:09:24 -0700
committerN. Taylor Mullen <[email protected]>2025-05-16 22:14:51 -0700
commite0b88dc8da3667bf4ba172a334a176d08fb0129d (patch)
tree8fec045eb4277a7b1361aca45f0c8cbc1925f690 /packages/server/src/tools/tool-registry.ts
parent0e25fdd56e99aaa51f805a075e45634cb7f2c02a (diff)
feat: Strip schema props from MCP tool definitions
- This change modifies the tool discovery process for MCP (Model Context Protocol) tools. - When tools are fetched from an MCP server, the `additionalProperties` and `$schema` fields are now recursively removed from their input schemas. This ensures cleaner and more concise tool definitions within the CLI, aligning with the expected schema structure and preventing potential conflicts or verbose outputs. - The corresponding tests in `tool-registry.test.ts` have been updated to reflect this new behavior and verify the correct stripping of these properties. Workaround for https://github.com/google-gemini/gemini-cli/issues/398
Diffstat (limited to 'packages/server/src/tools/tool-registry.ts')
-rw-r--r--packages/server/src/tools/tool-registry.ts16
1 files changed, 16 insertions, 0 deletions
diff --git a/packages/server/src/tools/tool-registry.ts b/packages/server/src/tools/tool-registry.ts
index 6a737482..7bc04432 100644
--- a/packages/server/src/tools/tool-registry.ts
+++ b/packages/server/src/tools/tool-registry.ts
@@ -226,6 +226,22 @@ export class ToolRegistry {
});
const result = await mcpClient.listTools();
for (const tool of result.tools) {
+ // Recursively remove additionalProperties and $schema from the inputSchema
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- This function recursively navigates a deeply nested and potentially heterogeneous JSON schema object. Using 'any' is a pragmatic choice here to avoid overly complex type definitions for all possible schema variations.
+ const removeSchemaProps = (obj: any) => {
+ if (typeof obj !== 'object' || obj === null) {
+ return;
+ }
+ if (Array.isArray(obj)) {
+ obj.forEach(removeSchemaProps);
+ } else {
+ delete obj.additionalProperties;
+ delete obj.$schema;
+ Object.values(obj).forEach(removeSchemaProps);
+ }
+ };
+ removeSchemaProps(tool.inputSchema);
+
this.registerTool(
new DiscoveredMCPTool(
mcpClient,