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,
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);

View File

@@ -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.`,