Skip to content

Document best Practice for Handling Argument Errors in MCP Tool Rendering #356

@Eraoui909

Description

@Eraoui909

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Nice to haves, rare edge casesdocumentationImprovements or additions to documentationhelp wantedExtra attention is neededquestionThe issue is a question and not a report

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions