feat(mcp): log include MCP request with error (#6778)

This commit is contained in:
Lee James
2025-08-22 14:10:30 -04:00
committed by GitHub
parent d35abdab99
commit 240830afac
2 changed files with 13 additions and 7 deletions

View File

@@ -14,6 +14,7 @@ import {
afterEach, afterEach,
Mocked, Mocked,
} from 'vitest'; } from 'vitest';
import { safeJsonStringify } from '../utils/safeJsonStringify.js';
import { DiscoveredMCPTool, generateValidName } from './mcp-tool.js'; // Added getStringifiedResultForDisplay import { DiscoveredMCPTool, generateValidName } from './mcp-tool.js'; // Added getStringifiedResultForDisplay
import { ToolResult, ToolConfirmationOutcome } from './tools.js'; // Added ToolConfirmationOutcome import { ToolResult, ToolConfirmationOutcome } from './tools.js'; // Added ToolConfirmationOutcome
import { CallableTool, Part } from '@google/genai'; import { CallableTool, Part } from '@google/genai';
@@ -200,6 +201,10 @@ describe('DiscoveredMCPTool', () => {
inputSchema, inputSchema,
); );
const params = { param: 'isErrorTrueCase' }; const params = { param: 'isErrorTrueCase' };
const functionCall = {
name: serverToolName,
args: params,
};
const errorResponse = { isError: isErrorValue }; const errorResponse = { isError: isErrorValue };
const mockMcpToolResponseParts: Part[] = [ const mockMcpToolResponseParts: Part[] = [
@@ -211,10 +216,11 @@ describe('DiscoveredMCPTool', () => {
}, },
]; ];
mockCallTool.mockResolvedValue(mockMcpToolResponseParts); mockCallTool.mockResolvedValue(mockMcpToolResponseParts);
const expectedErrorMessage = `MCP tool '${serverToolName}' reported tool error with response: ${JSON.stringify( const expectedErrorMessage = `MCP tool '${
mockMcpToolResponseParts, serverToolName
)}`; }' reported tool error for function call: ${safeJsonStringify(
functionCall,
)} with response: ${safeJsonStringify(mockMcpToolResponseParts)}`;
const invocation = tool.build(params); const invocation = tool.build(params);
const result = await invocation.execute(new AbortController().signal); const result = await invocation.execute(new AbortController().signal);

View File

@@ -142,9 +142,9 @@ class DiscoveredMCPToolInvocation extends BaseToolInvocation<
if (this.isMCPToolError(rawResponseParts)) { if (this.isMCPToolError(rawResponseParts)) {
const errorMessage = `MCP tool '${ const errorMessage = `MCP tool '${
this.serverToolName this.serverToolName
}' reported tool error with response: ${JSON.stringify( }' reported tool error for function call: ${safeJsonStringify(
rawResponseParts, functionCalls[0],
)}`; )} with response: ${safeJsonStringify(rawResponseParts)}`;
return { return {
llmContent: errorMessage, llmContent: errorMessage,
returnDisplay: `Error: MCP tool '${this.serverToolName}' reported an error.`, returnDisplay: `Error: MCP tool '${this.serverToolName}' reported an error.`,