fix(mcp): handle tool result errors (#32244)

This commit is contained in:
Aiden Cline 2026-06-14 21:16:39 -05:00 committed by GitHub
commit dfb616f067
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 33 additions and 0 deletions

View file

@ -63,6 +63,13 @@ export function convertTool(mcpTool: MCPToolDef, client: Client, timeout?: numbe
timeout,
},
)
if (result.isError)
throw new Error(
result.content
.flatMap((item) => (item.type === "text" ? [item.text] : []))
.filter((text) => text.trim())
.join("\n\n") || "MCP tool returned an error",
)
if (result.structuredContent === undefined || result.structuredContent === null) return result
return {
...result,