docs: document best practice for handling argument errors in MCP tools#891
Open
radeshgovind-2005 wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
Conversation
…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
Kehrlann
reviewed
Apr 1, 2026
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(); | ||
| } | ||
| ``` |
Contributor
There was a problem hiding this comment.
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?
|
|
||
| **2. Protocol-Level Errors (Unrecoverable)** | ||
|
|
||
| Uncaught exceptions from a tool handler are mapped to a JSON-RPC error response. Use this only for truly unexpected failures (e.g., infrastructure errors), not for input validation. |
Contributor
There was a problem hiding this comment.
Suggested change
| Uncaught exceptions from a tool handler are mapped to a JSON-RPC error response. Use this only for truly unexpected failures (e.g., infrastructure errors), not for input validation. | |
| Uncaught exceptions from a tool handler are mapped to a JSON-RPC error response. Use this only for truly unexpected failures (e.g., infrastructure errors such as DB timeout), not for input validation. |
Comment on lines
+834
to
+835
| | Missing / invalid argument | `CallToolResult` with `isError=true` | | ||
| | Domain validation failure | `CallToolResult` with `isError=true` | |
Contributor
There was a problem hiding this comment.
Both cases are the same, let's fold them together.
Suggested change
| | Missing / invalid argument | `CallToolResult` with `isError=true` | | |
| | Domain validation failure | `CallToolResult` with `isError=true` | | |
| | Domain validation failure | `CallToolResult` with `isError=true` | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #356
Clarify the two-tier error model:
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
Checklist
Additional context
The new section was added under the existing
## Error Handlingsection indocs/server.mdto keep all error-related documentation in one place.