Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 15, 2025

Updates documentation to reflect SEP-1303, which clarifies that input validation errors should be returned as tool execution errors (IsError=true) rather than protocol errors, enabling language models to see error details and self-correct.

Changes

  • McpErrorCode.InvalidParams: Clarified usage is limited to malformed requests (schema violations) and unknown primitives (tool/prompt/resource names). Explicitly excludes input validation errors.

  • CallToolResult.IsError: Enhanced remarks to specify tool execution errors include input validation (wrong format, out of range), API failures, and business logic errors. Added examples of model self-correction scenarios.

  • McpProtocolException: Strengthened language to emphasize protocol-level scope only, not tool execution failures.

  • Test coverage: Added Can_Handle_Call_Tool_Requests_With_InputValidationException to verify ArgumentException (representing input validation) converts to tool execution error.

Implementation Note

The SDK already implements SEP-1303 correctly. The error handler in McpServerImpl.cs (lines 585-598) catches all exceptions except OperationCanceledException and McpProtocolException, converting them to CallToolResult with IsError=true. This ensures JSON deserialization failures and parameter validation errors reach the model as actionable feedback.

catch (Exception e) when (e is not OperationCanceledException and not McpProtocolException)
{
    return new() { IsError = true, Content = [new TextContentBlock { Text = errorMessage }] };
}
Original prompt

Review modelcontextprotocol/modelcontextprotocol#1611 and ensure it's appropriately implemented by the ModelContextProtocol.Core project, making the minimal changes necessary to src and tests to fully comply with the tweaks.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

- Updated McpErrorCode.InvalidParams documentation to clarify it's for protocol-level errors (malformed requests, unknown primitives)
- Updated CallToolResult documentation to distinguish between tool execution errors and protocol errors
- Updated McpProtocolException documentation to emphasize it's only for protocol-level errors
- Added test to verify input validation errors are returned as tool execution errors (IsError=true)
- Implementation already correctly handles input validation as tool execution errors per SEP-1303

Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Copilot AI changed the title [WIP] Review and implement ModelContextProtocol changes Align error handling documentation with SEP-1303 Nov 15, 2025
Copilot finished work on behalf of stephentoub November 15, 2025 17:38
Copilot AI requested a review from stephentoub November 15, 2025 17:38
@stephentoub stephentoub marked this pull request as ready for review November 15, 2025 23:56
Copy link
Contributor

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

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

@halter73 / @mikekistler, should we expose an option or switch somewhere to allow propagating details of arbitrary exceptions out of tools?

@mikekistler
Copy link
Contributor

should we expose an option or switch somewhere to allow propagating details of arbitrary exceptions out of tools?

I think we can defer that until there is clear signal from users that it is needed.

@stephentoub stephentoub merged commit 4b241e7 into main Nov 17, 2025
10 checks passed
@stephentoub stephentoub deleted the copilot/review-implement-modelcontextprotocol-changes branch November 17, 2025 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants