diff --git a/packages/core/src/tools/mcp-tool.test.ts b/packages/core/src/tools/mcp-tool.test.ts index dc1d5c57..02c74214 100644 --- a/packages/core/src/tools/mcp-tool.test.ts +++ b/packages/core/src/tools/mcp-tool.test.ts @@ -14,6 +14,7 @@ import { afterEach, Mocked, } from 'vitest'; +import { safeJsonStringify } from '../utils/safeJsonStringify.js'; import { DiscoveredMCPTool, generateValidName } from './mcp-tool.js'; // Added getStringifiedResultForDisplay import { ToolResult, ToolConfirmationOutcome } from './tools.js'; // Added ToolConfirmationOutcome import { CallableTool, Part } from '@google/genai'; @@ -200,6 +201,10 @@ describe('DiscoveredMCPTool', () => { inputSchema, ); const params = { param: 'isErrorTrueCase' }; + const functionCall = { + name: serverToolName, + args: params, + }; const errorResponse = { isError: isErrorValue }; const mockMcpToolResponseParts: Part[] = [ @@ -211,10 +216,11 @@ describe('DiscoveredMCPTool', () => { }, ]; mockCallTool.mockResolvedValue(mockMcpToolResponseParts); - const expectedErrorMessage = `MCP tool '${serverToolName}' reported tool error with response: ${JSON.stringify( - mockMcpToolResponseParts, - )}`; - + const expectedErrorMessage = `MCP tool '${ + serverToolName + }' reported tool error for function call: ${safeJsonStringify( + functionCall, + )} with response: ${safeJsonStringify(mockMcpToolResponseParts)}`; const invocation = tool.build(params); const result = await invocation.execute(new AbortController().signal); diff --git a/packages/core/src/tools/mcp-tool.ts b/packages/core/src/tools/mcp-tool.ts index 6ad1da78..c16bc7a1 100644 --- a/packages/core/src/tools/mcp-tool.ts +++ b/packages/core/src/tools/mcp-tool.ts @@ -142,9 +142,9 @@ class DiscoveredMCPToolInvocation extends BaseToolInvocation< if (this.isMCPToolError(rawResponseParts)) { const errorMessage = `MCP tool '${ this.serverToolName - }' reported tool error with response: ${JSON.stringify( - rawResponseParts, - )}`; + }' reported tool error for function call: ${safeJsonStringify( + functionCalls[0], + )} with response: ${safeJsonStringify(rawResponseParts)}`; return { llmContent: errorMessage, returnDisplay: `Error: MCP tool '${this.serverToolName}' reported an error.`,