-
Notifications
You must be signed in to change notification settings - Fork 851
Open
Copy link
Labels
P3Nice to haves, rare edge casesNice to haves, rare edge casesdocumentationImprovements or additions to documentationImprovements or additions to documentationhelp wantedExtra attention is neededExtra attention is neededquestionThe issue is a question and not a reportThe issue is a question and not a report
Description
I'm uncertain about the recommended approach for handling errors in MCP, especially when it comes to missing or invalid arguments.
Specifically:
Should we throw an exception, or should we catch the error and return it as part of the McpSchema.CallToolResult so the LLM can understand what went wrong and possibly correct the request in a future interaction?
Example Scenario:
I have a tool that expects two parameters: first_name and last_name. It returns a simple greeting message.
If the request includes only first_name and last_name is null, how should the error be handled?
Option 1 — Throw an exception:
catch (Exception e) {
throw new McpError(e);
}Option 2 — Catch and return the error message:
catch (Exception e) {
contents.add(
new McpSchema.TextContent("Error: " + e.getMessage())
);
}Which approach aligns better with MCP's error-handling philosophy and the intended LLM experience?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P3Nice to haves, rare edge casesNice to haves, rare edge casesdocumentationImprovements or additions to documentationImprovements or additions to documentationhelp wantedExtra attention is neededExtra attention is neededquestionThe issue is a question and not a reportThe issue is a question and not a report