fix(mcp): handle tool result errors (#32244)
This commit is contained in:
parent
1338d7b47a
commit
dfb616f067
2 changed files with 33 additions and 0 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue