From 13ac5d564a55f0fc98f1aa94600a2863ffd1d176 Mon Sep 17 00:00:00 2001 From: defi-failure <159208748+defi-failure@users.noreply.github.com> Date: Fri, 28 Nov 2025 20:46:52 +0800 Subject: [PATCH] fix: match tool-call chunk with tool id (#11533) --- src/renderer/src/aiCore/chunk/handleToolCallChunk.ts | 3 ++- src/renderer/src/utils/mcp-tools.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/renderer/src/aiCore/chunk/handleToolCallChunk.ts b/src/renderer/src/aiCore/chunk/handleToolCallChunk.ts index 32c7e534e3..b5acbb690b 100644 --- a/src/renderer/src/aiCore/chunk/handleToolCallChunk.ts +++ b/src/renderer/src/aiCore/chunk/handleToolCallChunk.ts @@ -212,8 +212,9 @@ export class ToolCallChunkHandler { description: toolName, type: 'builtin' } as BaseTool - } else if ((mcpTool = this.mcpTools.find((t) => t.name === toolName) as MCPTool)) { + } else if ((mcpTool = this.mcpTools.find((t) => t.id === toolName) as MCPTool)) { // 如果是客户端执行的 MCP 工具,沿用现有逻辑 + // toolName is mcpTool.id (registered with id as key in convertMcpToolsToAiSdkTools) logger.info(`[ToolCallChunkHandler] Handling client-side MCP tool: ${toolName}`) // mcpTool = this.mcpTools.find((t) => t.name === toolName) as MCPTool // if (!mcpTool) { diff --git a/src/renderer/src/utils/mcp-tools.ts b/src/renderer/src/utils/mcp-tools.ts index 49628628d4..364b22e651 100644 --- a/src/renderer/src/utils/mcp-tools.ts +++ b/src/renderer/src/utils/mcp-tools.ts @@ -90,7 +90,8 @@ export function openAIToolsToMcpTool( return undefined } const tools = mcpTools.filter((mcpTool) => { - return mcpTool.id === toolName || mcpTool.name === toolName + // toolName is mcpTool.id (registered with id as function name) + return mcpTool.id === toolName }) if (tools.length > 1) { logger.warn(`Multiple MCP Tools found for tool call: ${toolName}`)