mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
feat(mcp): log include MCP request with error (#6778)
This commit is contained in:
@@ -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);
|
||||||
|
|
||||||
|
|||||||
@@ -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.`,
|
||||||
|
|||||||
Reference in New Issue
Block a user