diff options
| author | BigUncle <[email protected]> | 2025-07-06 05:58:51 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-07-05 21:58:51 +0000 |
| commit | b564d4a088d11ae5a90291e642b104761d72ee61 (patch) | |
| tree | 2423d004716aa77f05e55b019fe652a18d539f1d /packages/core/src/tools/mcp-client.ts | |
| parent | 5c9372372c73afcff893499e538cf5522a4400e2 (diff) | |
fix(core): Sanitize tool parameters to fix 400 API errors (#3300)
Diffstat (limited to 'packages/core/src/tools/mcp-client.ts')
| -rw-r--r-- | packages/core/src/tools/mcp-client.ts | 37 |
1 files changed, 2 insertions, 35 deletions
diff --git a/packages/core/src/tools/mcp-client.ts b/packages/core/src/tools/mcp-client.ts index 359ce30a..bb92ab05 100644 --- a/packages/core/src/tools/mcp-client.ts +++ b/packages/core/src/tools/mcp-client.ts @@ -14,13 +14,8 @@ import { import { parse } from 'shell-quote'; import { MCPServerConfig } from '../config/config.js'; import { DiscoveredMCPTool } from './mcp-tool.js'; -import { - CallableTool, - FunctionDeclaration, - mcpToTool, - Schema, -} from '@google/genai'; -import { ToolRegistry } from './tool-registry.js'; +import { CallableTool, FunctionDeclaration, mcpToTool } from '@google/genai'; +import { sanitizeParameters, ToolRegistry } from './tool-registry.js'; export const MCP_DEFAULT_TIMEOUT_MSEC = 10 * 60 * 1000; // default to 10 minutes @@ -384,31 +379,3 @@ async function connectAndDiscover( } } } - -/** - * Sanitizes a JSON schema object to ensure compatibility with Vertex AI. - * This function recursively processes the schema to remove problematic properties - * that can cause issues with the Gemini API. - * - * @param schema The JSON schema object to sanitize (modified in-place) - */ -export function sanitizeParameters(schema?: Schema) { - if (!schema) { - return; - } - if (schema.anyOf) { - // Vertex AI gets confused if both anyOf and default are set. - schema.default = undefined; - for (const item of schema.anyOf) { - sanitizeParameters(item); - } - } - if (schema.items) { - sanitizeParameters(schema.items); - } - if (schema.properties) { - for (const item of Object.values(schema.properties)) { - sanitizeParameters(item); - } - } -} |
