Skip to content

Commit fd79481

Browse files
authored
fix: properly type tool error content in getAITools (#781)
* fix: properly type tool error content in getAITools * fix: cast result.content to fix TS18046 error - Cast result.content to Array<{ type: string; text?: string }> | undefined - Add additional null check for textContent.text - Add changeset for patch release
1 parent 99cbca0 commit fd79481

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

.changeset/fix-mcp-error-type.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"agents": patch
3+
---
4+
5+
fix: properly type tool error content in getAITools

packages/agents/src/mcp/client.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -941,8 +941,15 @@ export class MCPClientManager {
941941
serverId: tool.serverId
942942
});
943943
if (result.isError) {
944-
// @ts-expect-error TODO we should fix this
945-
throw new Error(result.content[0].text);
944+
const content = result.content as
945+
| Array<{ type: string; text?: string }>
946+
| undefined;
947+
const textContent = content?.[0];
948+
const message =
949+
textContent?.type === "text" && textContent.text
950+
? textContent.text
951+
: "Tool call failed";
952+
throw new Error(message);
946953
}
947954
return result;
948955
},

0 commit comments

Comments
 (0)