mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-29 06:25:16 -07:00
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
This commit is contained in:
committed by
N. Taylor Mullen
parent
0e25fdd56e
commit
e0b88dc8da
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user