diff options
Diffstat (limited to 'packages/core/src')
| -rw-r--r-- | packages/core/src/tools/mcp-client.ts | 9 | ||||
| -rw-r--r-- | packages/core/src/tools/mcp-tool.test.ts | 5 | ||||
| -rw-r--r-- | packages/core/src/tools/mcp-tool.ts | 24 | ||||
| -rw-r--r-- | packages/core/src/tools/tools.ts | 2 |
4 files changed, 30 insertions, 10 deletions
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<string, unknown>; @@ -23,7 +29,7 @@ export class DiscoveredMCPTool extends BaseTool<ToolParams, ToolResult> { 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<ToolParams, ToolResult> { 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, |
