diff --git a/package-lock.json b/package-lock.json index 99269519..05c4e713 100644 --- a/package-lock.json +++ b/package-lock.json @@ -930,15 +930,13 @@ "link": true }, "node_modules/@google/genai": { - "version": "1.8.0", - "resolved": "https://registry.npmjs.org/@google/genai/-/genai-1.8.0.tgz", - "integrity": "sha512-n3KiMFesQCy2R9iSdBIuJ0JWYQ1HZBJJkmt4PPZMGZKvlgHhBAGw1kUMyX+vsAIzprN3lK45DI755lm70wPOOg==", + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/@google/genai/-/genai-1.9.0.tgz", + "integrity": "sha512-w9P93OXKPMs9H1mfAx9+p3zJqQGrWBGdvK/SVc7cLZEXNHr/3+vW2eif7ZShA6wU24rNLn9z9MK2vQFUvNRI2Q==", "license": "Apache-2.0", "dependencies": { "google-auth-library": "^9.14.2", - "ws": "^8.18.0", - "zod": "^3.22.4", - "zod-to-json-schema": "^3.22.4" + "ws": "^8.18.0" }, "engines": { "node": ">=20.0.0" @@ -11925,7 +11923,7 @@ "name": "@google/gemini-cli-core", "version": "0.1.12", "dependencies": { - "@google/genai": "1.8.0", + "@google/genai": "1.9.0", "@modelcontextprotocol/sdk": "^1.11.0", "@opentelemetry/api": "^1.9.0", "@opentelemetry/exporter-logs-otlp-grpc": "^0.52.0", diff --git a/packages/cli/src/ui/commands/mcpCommand.ts b/packages/cli/src/ui/commands/mcpCommand.ts index fc266362..5ff77c4b 100644 --- a/packages/cli/src/ui/commands/mcpCommand.ts +++ b/packages/cli/src/ui/commands/mcpCommand.ts @@ -170,11 +170,13 @@ const getMcpStatus = async ( // Use cyan color for the tool name even when not showing descriptions message += ` - ${COLOR_CYAN}${tool.name}${RESET_COLOR}\n`; } - if (showSchema && tool.parameterSchema) { + const parameters = + tool.schema.parametersJsonSchema ?? tool.schema.parameters; + if (showSchema && parameters) { // Prefix the parameters in cyan message += ` ${COLOR_CYAN}Parameters:${RESET_COLOR}\n`; - const paramsLines = JSON.stringify(tool.parameterSchema, null, 2) + const paramsLines = JSON.stringify(parameters, null, 2) .trim() .split('\n'); if (paramsLines) { diff --git a/packages/core/package.json b/packages/core/package.json index 5c8e2dbe..c34e62fd 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -20,7 +20,7 @@ "dist" ], "dependencies": { - "@google/genai": "1.8.0", + "@google/genai": "1.9.0", "@modelcontextprotocol/sdk": "^1.11.0", "@opentelemetry/api": "^1.9.0", "@opentelemetry/exporter-logs-otlp-grpc": "^0.52.0", diff --git a/packages/core/src/tools/mcp-client.ts b/packages/core/src/tools/mcp-client.ts index beb70549..24c975c3 100644 --- a/packages/core/src/tools/mcp-client.ts +++ b/packages/core/src/tools/mcp-client.ts @@ -18,8 +18,9 @@ import { import { parse } from 'shell-quote'; import { MCPServerConfig } from '../config/config.js'; import { DiscoveredMCPTool } from './mcp-tool.js'; -import { FunctionDeclaration, Type, mcpToTool } from '@google/genai'; -import { sanitizeParameters, ToolRegistry } from './tool-registry.js'; + +import { FunctionDeclaration, mcpToTool } from '@google/genai'; +import { ToolRegistry } from './tool-registry.js'; import { ActiveFileNotificationSchema, IDE_SERVER_NAME, @@ -275,15 +276,13 @@ export async function discoverTools( const toolNameForModel = generateValidName(funcDecl, mcpServerName); - sanitizeParameters(funcDecl.parameters); - discoveredTools.push( new DiscoveredMCPTool( mcpCallableTool, mcpServerName, toolNameForModel, funcDecl.description ?? '', - funcDecl.parameters ?? { type: Type.OBJECT, properties: {} }, + funcDecl.parametersJsonSchema ?? { type: 'object', properties: {} }, funcDecl.name!, mcpServerConfig.timeout ?? MCP_DEFAULT_TIMEOUT_MSEC, mcpServerConfig.trust, diff --git a/packages/core/src/tools/mcp-tool.test.ts b/packages/core/src/tools/mcp-tool.test.ts index d972efdb..4411e674 100644 --- a/packages/core/src/tools/mcp-tool.test.ts +++ b/packages/core/src/tools/mcp-tool.test.ts @@ -65,7 +65,8 @@ describe('DiscoveredMCPTool', () => { expect(tool.name).toBe(toolNameForModel); expect(tool.schema.name).toBe(toolNameForModel); expect(tool.schema.description).toBe(baseDescription); - expect(tool.schema.parameters).toEqual(inputSchema); + expect(tool.schema.parameters).toBeUndefined(); + expect(tool.schema.parametersJsonSchema).toEqual(inputSchema); expect(tool.serverToolName).toBe(serverToolName); expect(tool.timeout).toBeUndefined(); }); @@ -81,6 +82,8 @@ describe('DiscoveredMCPTool', () => { serverToolName, ); expect(tool.schema.description).toBe(baseDescription); + expect(tool.schema.parameters).toBeUndefined(); + expect(tool.schema.parametersJsonSchema).toEqual(inputSchema); }); it('should accept and store a custom timeout', () => { diff --git a/packages/core/src/tools/mcp-tool.ts b/packages/core/src/tools/mcp-tool.ts index cc4739a4..663ec6ee 100644 --- a/packages/core/src/tools/mcp-tool.ts +++ b/packages/core/src/tools/mcp-tool.ts @@ -11,7 +11,13 @@ import { ToolConfirmationOutcome, ToolMcpConfirmationDetails, } from './tools.js'; -import { CallableTool, Part, FunctionCall, Schema } from '@google/genai'; +import { + CallableTool, + Part, + FunctionCall, + FunctionDeclaration, + Type, +} from '@google/genai'; type ToolParams = Record; @@ -23,7 +29,7 @@ export class DiscoveredMCPTool extends BaseTool { readonly serverName: string, readonly name: string, readonly description: string, - readonly parameterSchema: Schema, + readonly parameterSchemaJson: unknown, readonly serverToolName: string, readonly timeout?: number, readonly trust?: boolean, @@ -32,12 +38,24 @@ export class DiscoveredMCPTool extends BaseTool { name, `${serverToolName} (${serverName} MCP Server)`, description, - parameterSchema, + { type: Type.OBJECT }, // this is a dummy Schema for MCP, will be not be used to construct the FunctionDeclaration true, // isOutputMarkdown false, // canUpdateOutput ); } + /** + * Overrides the base schema to use parametersJsonSchema when building + * FunctionDeclaration + */ + override get schema(): FunctionDeclaration { + return { + name: this.name, + description: this.description, + parametersJsonSchema: this.parameterSchemaJson, + }; + } + async shouldConfirmExecute( _params: ToolParams, _abortSignal: AbortSignal, diff --git a/packages/core/src/tools/tools.ts b/packages/core/src/tools/tools.ts index 68739d0e..6f6d3f58 100644 --- a/packages/core/src/tools/tools.ts +++ b/packages/core/src/tools/tools.ts @@ -97,7 +97,7 @@ export abstract class BaseTool< * @param description Description of what the tool does * @param isOutputMarkdown Whether the tool's output should be rendered as markdown * @param canUpdateOutput Whether the tool supports live (streaming) output - * @param parameterSchema JSON Schema defining the parameters + * @param parameterSchema Open API 3.0 Schema defining the parameters */ constructor( readonly name: string,