Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-mcp-error-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"agents": patch
---

fix: properly type tool error content in getAITools
11 changes: 9 additions & 2 deletions packages/agents/src/mcp/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -941,8 +941,15 @@ export class MCPClientManager {
serverId: tool.serverId
});
if (result.isError) {
// @ts-expect-error TODO we should fix this
throw new Error(result.content[0].text);
const content = result.content as
| Array<{ type: string; text?: string }>
| undefined;
const textContent = content?.[0];
const message =
textContent?.type === "text" && textContent.text
? textContent.text
: "Tool call failed";
throw new Error(message);
}
return result;
},
Expand Down
Loading