fix: update google/genai to v1.9.0 and switch to parametersJsonSchema for MCP related tools (#4176)

Co-authored-by: Jack Wotherspoon <jackwoth@google.com>
This commit is contained in:
Wanlin Du 2025-07-16 14:32:34 -07:00 committed by GitHub
parent 21eb44b242
commit f6ee0d182b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 40 additions and 20 deletions

12
package-lock.json generated
View File

@ -930,15 +930,13 @@
"link": true "link": true
}, },
"node_modules/@google/genai": { "node_modules/@google/genai": {
"version": "1.8.0", "version": "1.9.0",
"resolved": "https://registry.npmjs.org/@google/genai/-/genai-1.8.0.tgz", "resolved": "https://registry.npmjs.org/@google/genai/-/genai-1.9.0.tgz",
"integrity": "sha512-n3KiMFesQCy2R9iSdBIuJ0JWYQ1HZBJJkmt4PPZMGZKvlgHhBAGw1kUMyX+vsAIzprN3lK45DI755lm70wPOOg==", "integrity": "sha512-w9P93OXKPMs9H1mfAx9+p3zJqQGrWBGdvK/SVc7cLZEXNHr/3+vW2eif7ZShA6wU24rNLn9z9MK2vQFUvNRI2Q==",
"license": "Apache-2.0", "license": "Apache-2.0",
"dependencies": { "dependencies": {
"google-auth-library": "^9.14.2", "google-auth-library": "^9.14.2",
"ws": "^8.18.0", "ws": "^8.18.0"
"zod": "^3.22.4",
"zod-to-json-schema": "^3.22.4"
}, },
"engines": { "engines": {
"node": ">=20.0.0" "node": ">=20.0.0"
@ -11925,7 +11923,7 @@
"name": "@google/gemini-cli-core", "name": "@google/gemini-cli-core",
"version": "0.1.12", "version": "0.1.12",
"dependencies": { "dependencies": {
"@google/genai": "1.8.0", "@google/genai": "1.9.0",
"@modelcontextprotocol/sdk": "^1.11.0", "@modelcontextprotocol/sdk": "^1.11.0",
"@opentelemetry/api": "^1.9.0", "@opentelemetry/api": "^1.9.0",
"@opentelemetry/exporter-logs-otlp-grpc": "^0.52.0", "@opentelemetry/exporter-logs-otlp-grpc": "^0.52.0",

View File

@ -170,11 +170,13 @@ const getMcpStatus = async (
// Use cyan color for the tool name even when not showing descriptions // Use cyan color for the tool name even when not showing descriptions
message += ` - ${COLOR_CYAN}${tool.name}${RESET_COLOR}\n`; 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 // Prefix the parameters in cyan
message += ` ${COLOR_CYAN}Parameters:${RESET_COLOR}\n`; message += ` ${COLOR_CYAN}Parameters:${RESET_COLOR}\n`;
const paramsLines = JSON.stringify(tool.parameterSchema, null, 2) const paramsLines = JSON.stringify(parameters, null, 2)
.trim() .trim()
.split('\n'); .split('\n');
if (paramsLines) { if (paramsLines) {

View File

@ -20,7 +20,7 @@
"dist" "dist"
], ],
"dependencies": { "dependencies": {
"@google/genai": "1.8.0", "@google/genai": "1.9.0",
"@modelcontextprotocol/sdk": "^1.11.0", "@modelcontextprotocol/sdk": "^1.11.0",
"@opentelemetry/api": "^1.9.0", "@opentelemetry/api": "^1.9.0",
"@opentelemetry/exporter-logs-otlp-grpc": "^0.52.0", "@opentelemetry/exporter-logs-otlp-grpc": "^0.52.0",

View File

@ -18,8 +18,9 @@ import {
import { parse } from 'shell-quote'; import { parse } from 'shell-quote';
import { MCPServerConfig } from '../config/config.js'; import { MCPServerConfig } from '../config/config.js';
import { DiscoveredMCPTool } from './mcp-tool.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 { import {
ActiveFileNotificationSchema, ActiveFileNotificationSchema,
IDE_SERVER_NAME, IDE_SERVER_NAME,
@ -275,15 +276,13 @@ export async function discoverTools(
const toolNameForModel = generateValidName(funcDecl, mcpServerName); const toolNameForModel = generateValidName(funcDecl, mcpServerName);
sanitizeParameters(funcDecl.parameters);
discoveredTools.push( discoveredTools.push(
new DiscoveredMCPTool( new DiscoveredMCPTool(
mcpCallableTool, mcpCallableTool,
mcpServerName, mcpServerName,
toolNameForModel, toolNameForModel,
funcDecl.description ?? '', funcDecl.description ?? '',
funcDecl.parameters ?? { type: Type.OBJECT, properties: {} }, funcDecl.parametersJsonSchema ?? { type: 'object', properties: {} },
funcDecl.name!, funcDecl.name!,
mcpServerConfig.timeout ?? MCP_DEFAULT_TIMEOUT_MSEC, mcpServerConfig.timeout ?? MCP_DEFAULT_TIMEOUT_MSEC,
mcpServerConfig.trust, mcpServerConfig.trust,

View File

@ -65,7 +65,8 @@ describe('DiscoveredMCPTool', () => {
expect(tool.name).toBe(toolNameForModel); expect(tool.name).toBe(toolNameForModel);
expect(tool.schema.name).toBe(toolNameForModel); expect(tool.schema.name).toBe(toolNameForModel);
expect(tool.schema.description).toBe(baseDescription); 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.serverToolName).toBe(serverToolName);
expect(tool.timeout).toBeUndefined(); expect(tool.timeout).toBeUndefined();
}); });
@ -81,6 +82,8 @@ describe('DiscoveredMCPTool', () => {
serverToolName, serverToolName,
); );
expect(tool.schema.description).toBe(baseDescription); 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', () => { it('should accept and store a custom timeout', () => {

View File

@ -11,7 +11,13 @@ import {
ToolConfirmationOutcome, ToolConfirmationOutcome,
ToolMcpConfirmationDetails, ToolMcpConfirmationDetails,
} from './tools.js'; } from './tools.js';
import { CallableTool, Part, FunctionCall, Schema } from '@google/genai'; import {
CallableTool,
Part,
FunctionCall,
FunctionDeclaration,
Type,
} from '@google/genai';
type ToolParams = Record<string, unknown>; type ToolParams = Record<string, unknown>;
@ -23,7 +29,7 @@ export class DiscoveredMCPTool extends BaseTool<ToolParams, ToolResult> {
readonly serverName: string, readonly serverName: string,
readonly name: string, readonly name: string,
readonly description: string, readonly description: string,
readonly parameterSchema: Schema, readonly parameterSchemaJson: unknown,
readonly serverToolName: string, readonly serverToolName: string,
readonly timeout?: number, readonly timeout?: number,
readonly trust?: boolean, readonly trust?: boolean,
@ -32,12 +38,24 @@ export class DiscoveredMCPTool extends BaseTool<ToolParams, ToolResult> {
name, name,
`${serverToolName} (${serverName} MCP Server)`, `${serverToolName} (${serverName} MCP Server)`,
description, description,
parameterSchema, { type: Type.OBJECT }, // this is a dummy Schema for MCP, will be not be used to construct the FunctionDeclaration
true, // isOutputMarkdown true, // isOutputMarkdown
false, // canUpdateOutput 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( async shouldConfirmExecute(
_params: ToolParams, _params: ToolParams,
_abortSignal: AbortSignal, _abortSignal: AbortSignal,

View File

@ -97,7 +97,7 @@ export abstract class BaseTool<
* @param description Description of what the tool does * @param description Description of what the tool does
* @param isOutputMarkdown Whether the tool's output should be rendered as markdown * @param isOutputMarkdown Whether the tool's output should be rendered as markdown
* @param canUpdateOutput Whether the tool supports live (streaming) output * @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( constructor(
readonly name: string, readonly name: string,