mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-25 03:10:08 +08:00
fix(mcp-tools): improve error message formatting and response handlin… (#5565)
fix(mcp-tools): improve error message formatting and response handling in upsertMCPToolResponse function
This commit is contained in:
parent
e0e1edebbe
commit
d78d8373d7
@ -228,7 +228,7 @@ export async function callMCPTool(tool: MCPTool): Promise<MCPCallToolResponse> {
|
||||
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]
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user