Skip to content

docs: document best practice for handling argument errors in MCP tools#891

Open
radeshgovind-2005 wants to merge 5 commits intomodelcontextprotocol:mainfrom
radeshgovind-2005:docs/error-handling-best-practices
Open

docs: document best practice for handling argument errors in MCP tools#891
radeshgovind-2005 wants to merge 5 commits intomodelcontextprotocol:mainfrom
radeshgovind-2005:docs/error-handling-best-practices

Conversation

@radeshgovind-2005
Copy link
Copy Markdown

Resolves #356

Clarify the two-tier error model:

  • Recoverable tool errors: use CallToolResult with isError(true)
  • Protocol-level errors: throw McpError / let exceptions propagate as JSON-RPC errors

Motivation and Context

Issue #356 raised uncertainty about whether tool argument errors should throw
exceptions or be returned as CallToolResult. The maintainer clarified the correct
approach in the thread but it was not yet documented. This PR formalizes that guidance.

How Has This Been Tested?

Documentation-only change. The full test suite passes locally (747 tests, 0 failures).

Breaking Changes

None.

Types of changes

  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added or updated documentation as needed

Additional context

The new section was added under the existing ## Error Handling section in
docs/server.md to keep all error-related documentation in one place.

…ations

Resolves modelcontextprotocol#356

Clarify the two-tier error model:
- Recoverable tool errors: use CallToolResult with isError(true)
- Protocol-level errors: throw McpError / let exceptions propagate as JSON-RPC errors
Copy link
Copy Markdown
Contributor

@Kehrlann Kehrlann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. A few comments in the PR.

Comment on lines +809 to +817
```java
// Example: missing required argument
if (lastName == null || lastName.isBlank()) {
return CallToolResult.builder()
.content(List.of(new McpSchema.TextContent("Missing required argument: last_name")))
.isError(true)
.build();
}
```
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example is a bit contrived, because MCP already has semantics for input parameter "required".

Please change it to something more realistic, e.g. validating an address, or an email?

@Kehrlann Kehrlann self-assigned this Apr 1, 2026
@Kehrlann Kehrlann added documentation Improvements or additions to documentation waiting for user Waiting for user feedback or more details labels Apr 1, 2026
radeshgovind-2005 and others added 3 commits April 1, 2026 16:22
Adds "DB timeout" as an explicit example of an infrastructure error to distinguish from input validation.

Co-authored-by: Daniel Garnier-Moiroux <daniel.garnier-moiroux@broadcom.com>
Folds duplicate domain validation rows in the summary table to improve readability.

Co-authored-by: Daniel Garnier-Moiroux <daniel.garnier-moiroux@broadcom.com>
Replaces the contrived missing argument check with a realistic email validation example per maintainer review. This clarifies that CallToolResult(isError=true) should be used for business logic/domain validation, since MCP natively handles missing required arguments via JSON Schema.
@radeshgovind-2005
Copy link
Copy Markdown
Author

@Kehrlann Thanks for the review! I've updated the example to use email format validation. I also committed your suggestion for the DB timeout clarification and folded the two validation rows in the table into one. Let me know if everything looks good to go!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation waiting for user Waiting for user feedback or more details

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Document best Practice for Handling Argument Errors in MCP Tool Rendering

2 participants