From d78d8373d7ae23dbd803efd2b2344de8faefaeae Mon Sep 17 00:00:00 2001 From: MyPrototypeWhat <43230886+MyPrototypeWhat@users.noreply.github.com> Date: Thu, 1 May 2025 18:06:53 +0800 Subject: [PATCH] =?UTF-8?q?fix(mcp-tools):=20improve=20error=20message=20f?= =?UTF-8?q?ormatting=20and=20response=20handlin=E2=80=A6=20(#5565)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix(mcp-tools): improve error message formatting and response handling in upsertMCPToolResponse function --- src/renderer/src/utils/mcp-tools.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/renderer/src/utils/mcp-tools.ts b/src/renderer/src/utils/mcp-tools.ts index a9c48a7f61..5eeb7201c0 100644 --- a/src/renderer/src/utils/mcp-tools.ts +++ b/src/renderer/src/utils/mcp-tools.ts @@ -228,7 +228,7 @@ export async function callMCPTool(tool: MCPTool): Promise { content: [ { type: 'text', - text: `Error calling tool ${tool.name}: ${e instanceof Error ? (e.stack || e.message || "No error details available") : JSON.stringify(e)}` + text: `Error calling tool ${tool.name}: ${e instanceof Error ? e.stack || e.message || 'No error details available' : JSON.stringify(e)}` } ] }) @@ -309,18 +309,21 @@ export function upsertMCPToolResponse( onChunk: (chunk: MCPToolInProgressChunk | MCPToolCompleteChunk) => void ) { const index = results.findIndex((ret) => ret.id === resp.id) + let result = resp if (index !== -1) { - results[index] = { + const cur = { ...results[index], response: resp.response, status: resp.status } + results[index] = cur + result = cur } else { results.push(resp) } onChunk({ type: resp.status === 'invoking' ? ChunkType.MCP_TOOL_IN_PROGRESS : ChunkType.MCP_TOOL_COMPLETE, - responses: results + responses: [result] }) }