Skip to content

Commit afc27a5

Browse files
fix: update google/genai to v1.9.0 and switch to parametersJsonSchema for MCP related tools (QwenLM#4176)
Co-authored-by: Jack Wotherspoon <jackwoth@google.com>
1 parent 15ce4e3 commit afc27a5

6 files changed

Lines changed: 35 additions & 13 deletions

File tree

packages/cli/src/ui/commands/mcpCommand.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,13 @@ const getMcpStatus = async (
170170
// Use cyan color for the tool name even when not showing descriptions
171171
message += ` - ${COLOR_CYAN}${tool.name}${RESET_COLOR}\n`;
172172
}
173-
if (showSchema && tool.parameterSchema) {
173+
const parameters =
174+
tool.schema.parametersJsonSchema ?? tool.schema.parameters;
175+
if (showSchema && parameters) {
174176
// Prefix the parameters in cyan
175177
message += ` ${COLOR_CYAN}Parameters:${RESET_COLOR}\n`;
176178

177-
const paramsLines = JSON.stringify(tool.parameterSchema, null, 2)
179+
const paramsLines = JSON.stringify(parameters, null, 2)
178180
.trim()
179181
.split('\n');
180182
if (paramsLines) {

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"dist"
2121
],
2222
"dependencies": {
23-
"@google/genai": "1.8.0",
23+
"@google/genai": "1.9.0",
2424
"@modelcontextprotocol/sdk": "^1.11.0",
2525
"@opentelemetry/api": "^1.9.0",
2626
"@opentelemetry/exporter-logs-otlp-grpc": "^0.52.0",

packages/core/src/tools/mcp-client.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ import {
1818
import { parse } from 'shell-quote';
1919
import { MCPServerConfig } from '../config/config.js';
2020
import { DiscoveredMCPTool } from './mcp-tool.js';
21-
import { FunctionDeclaration, Type, mcpToTool } from '@google/genai';
22-
import { sanitizeParameters, ToolRegistry } from './tool-registry.js';
21+
22+
import { FunctionDeclaration, mcpToTool } from '@google/genai';
23+
import { ToolRegistry } from './tool-registry.js';
2324
import {
2425
ActiveFileNotificationSchema,
2526
IDE_SERVER_NAME,
@@ -275,15 +276,13 @@ export async function discoverTools(
275276

276277
const toolNameForModel = generateValidName(funcDecl, mcpServerName);
277278

278-
sanitizeParameters(funcDecl.parameters);
279-
280279
discoveredTools.push(
281280
new DiscoveredMCPTool(
282281
mcpCallableTool,
283282
mcpServerName,
284283
toolNameForModel,
285284
funcDecl.description ?? '',
286-
funcDecl.parameters ?? { type: Type.OBJECT, properties: {} },
285+
funcDecl.parametersJsonSchema ?? { type: 'object', properties: {} },
287286
funcDecl.name!,
288287
mcpServerConfig.timeout ?? MCP_DEFAULT_TIMEOUT_MSEC,
289288
mcpServerConfig.trust,

packages/core/src/tools/mcp-tool.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ describe('DiscoveredMCPTool', () => {
6565
expect(tool.name).toBe(toolNameForModel);
6666
expect(tool.schema.name).toBe(toolNameForModel);
6767
expect(tool.schema.description).toBe(baseDescription);
68-
expect(tool.schema.parameters).toEqual(inputSchema);
68+
expect(tool.schema.parameters).toBeUndefined();
69+
expect(tool.schema.parametersJsonSchema).toEqual(inputSchema);
6970
expect(tool.serverToolName).toBe(serverToolName);
7071
expect(tool.timeout).toBeUndefined();
7172
});
@@ -81,6 +82,8 @@ describe('DiscoveredMCPTool', () => {
8182
serverToolName,
8283
);
8384
expect(tool.schema.description).toBe(baseDescription);
85+
expect(tool.schema.parameters).toBeUndefined();
86+
expect(tool.schema.parametersJsonSchema).toEqual(inputSchema);
8487
});
8588

8689
it('should accept and store a custom timeout', () => {

packages/core/src/tools/mcp-tool.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ import {
1111
ToolConfirmationOutcome,
1212
ToolMcpConfirmationDetails,
1313
} from './tools.js';
14-
import { CallableTool, Part, FunctionCall, Schema } from '@google/genai';
14+
import {
15+
CallableTool,
16+
Part,
17+
FunctionCall,
18+
FunctionDeclaration,
19+
Type,
20+
} from '@google/genai';
1521

1622
type ToolParams = Record<string, unknown>;
1723

@@ -23,7 +29,7 @@ export class DiscoveredMCPTool extends BaseTool<ToolParams, ToolResult> {
2329
readonly serverName: string,
2430
readonly name: string,
2531
readonly description: string,
26-
readonly parameterSchema: Schema,
32+
readonly parameterSchemaJson: unknown,
2733
readonly serverToolName: string,
2834
readonly timeout?: number,
2935
readonly trust?: boolean,
@@ -32,12 +38,24 @@ export class DiscoveredMCPTool extends BaseTool<ToolParams, ToolResult> {
3238
name,
3339
`${serverToolName} (${serverName} MCP Server)`,
3440
description,
35-
parameterSchema,
41+
{ type: Type.OBJECT }, // this is a dummy Schema for MCP, will be not be used to construct the FunctionDeclaration
3642
true, // isOutputMarkdown
3743
false, // canUpdateOutput
3844
);
3945
}
4046

47+
/**
48+
* Overrides the base schema to use parametersJsonSchema when building
49+
* FunctionDeclaration
50+
*/
51+
override get schema(): FunctionDeclaration {
52+
return {
53+
name: this.name,
54+
description: this.description,
55+
parametersJsonSchema: this.parameterSchemaJson,
56+
};
57+
}
58+
4159
async shouldConfirmExecute(
4260
_params: ToolParams,
4361
_abortSignal: AbortSignal,

packages/core/src/tools/tools.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export abstract class BaseTool<
9797
* @param description Description of what the tool does
9898
* @param isOutputMarkdown Whether the tool's output should be rendered as markdown
9999
* @param canUpdateOutput Whether the tool supports live (streaming) output
100-
* @param parameterSchema JSON Schema defining the parameters
100+
* @param parameterSchema Open API 3.0 Schema defining the parameters
101101
*/
102102
constructor(
103103
readonly name: string,

0 commit comments

Comments
 (0)