Skip to content

Commit 9fd0bb4

Browse files
fix: return isError instead of throwing InternalError on chart failures (#292)
1 parent 7563a99 commit 9fd0bb4

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

src/utils/callTool.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,23 @@ export async function callTool(tool: string, args: object = {}) {
108108
};
109109
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
110110
} catch (error: any) {
111-
logger.error(
112-
`Failed to generate chart: ${error.message || "Unknown error"}.`,
113-
);
111+
const message = error?.message || "Unknown error";
112+
logger.error(`Failed to generate chart: ${message}.`);
114113
if (error instanceof McpError) throw error;
115114
if (error instanceof ValidateError)
116115
throw new McpError(ErrorCode.InvalidParams, error.message);
117-
throw new McpError(
118-
ErrorCode.InternalError,
119-
`Failed to generate chart: ${error?.message || "Unknown error."}`,
120-
);
116+
// Return isError content instead of throwing InternalError (-32603).
117+
// InternalError is treated as a server crash by MCP clients; agents
118+
// cannot recover from it. Returning isError: true with a descriptive
119+
// message lets agents self-correct (e.g., fix their input and retry).
120+
return {
121+
content: [
122+
{
123+
type: "text",
124+
text: `Failed to generate chart: ${message}. Please check that the data matches the expected format for this chart type.`,
125+
},
126+
],
127+
isError: true,
128+
};
121129
}
122130
}

0 commit comments

Comments
 (0)