Error Handling
This is a member-only chapter. Log in with your Signal Over Noise membership email to continue.
Log in to readModule 4 · Section 7 of 9
Error Handling
Don’t let errors crash your server silently. Claude will see a generic failure and have no idea why. Be explicit:
server.setRequestHandler(CallToolRequestSchema, async (request) => {
const toolName = request.params.name;
if (toolName === "get_events") {
const { start_date, end_date } = request.params.arguments as {
start_date: string;
end_date: string;
};
if (!start_date || !end_date) {
return {
content: [{ type: "text", text: "Error: start_date and end_date are required" }],
isError: true,
};
}
try {
const events = await fetchEvents(start_date, end_date);
return { content: [{ type: "text", text: events }] };
} catch (error) {
return {
content: [{ type: "text", text: `Failed to fetch events: ${error}` }],
isError: true,
};
}
}
throw new Error(`Unknown tool: ${toolName}`);
});
The isError: true flag tells Claude the call failed so it can respond appropriately — retry with different parameters, tell the user something went wrong, or try an alternative approach.