summaryrefslogtreecommitdiff
path: root/packages/core/src/tools/mcp-tool.ts
diff options
context:
space:
mode:
authorLee James <[email protected]>2025-08-14 18:30:05 -0400
committerGitHub <[email protected]>2025-08-14 22:30:05 +0000
commitf47af1607a11314461960abb2cb523aec66a8fa2 (patch)
treee0a9b4a44ea46b5466abae203f78df9559b04adc /packages/core/src/tools/mcp-tool.ts
parenta01db2cfd503cd744a859e84adbf2d17774ba75c (diff)
bug(mcp): catch errors reported by GitHub MCP (#6194)
Diffstat (limited to 'packages/core/src/tools/mcp-tool.ts')
-rw-r--r--packages/core/src/tools/mcp-tool.ts30
1 files changed, 30 insertions, 0 deletions
diff --git a/packages/core/src/tools/mcp-tool.ts b/packages/core/src/tools/mcp-tool.ts
index fbb104fd..88e89c85 100644
--- a/packages/core/src/tools/mcp-tool.ts
+++ b/packages/core/src/tools/mcp-tool.ts
@@ -104,6 +104,28 @@ class DiscoveredMCPToolInvocation extends BaseToolInvocation<
return confirmationDetails;
}
+ // Determine if the response contains tool errors
+ // This is needed because CallToolResults should return errors inside the response.
+ // ref: https://modelcontextprotocol.io/specification/2025-06-18/schema#calltoolresult
+ isMCPToolError(rawResponseParts: Part[]): boolean {
+ const functionResponse = rawResponseParts?.[0]?.functionResponse;
+ const response = functionResponse?.response;
+
+ interface McpError {
+ isError?: boolean | string;
+ }
+
+ if (response) {
+ const error = (response as { error?: McpError })?.error;
+ const isError = error?.isError;
+
+ if (error && (isError === true || isError === 'true')) {
+ return true;
+ }
+ }
+ return false;
+ }
+
async execute(): Promise<ToolResult> {
const functionCalls: FunctionCall[] = [
{
@@ -113,6 +135,14 @@ class DiscoveredMCPToolInvocation extends BaseToolInvocation<
];
const rawResponseParts = await this.mcpTool.callTool(functionCalls);
+
+ // Ensure the response is not an error
+ if (this.isMCPToolError(rawResponseParts)) {
+ throw new Error(
+ `MCP tool '${this.serverToolName}' reported tool error with response: ${JSON.stringify(rawResponseParts)}`,
+ );
+ }
+
const transformedParts = transformMcpContentToParts(rawResponseParts);
return {