Align error handling documentation with SEP-1303 (#967)

* Initial plan

* Update documentation to clarify error handling per SEP-1303

- 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>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
This commit is contained in:
Copilot 2025-11-17 10:01:30 -05:00 • committed by GitHub
commit 4b241e7ddc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -591,6 +591,41 @@ public class McpServerTests : LoggedTest
});
}
[Fact]
public async Task Can_Handle_Call_Tool_Requests_With_InputValidationException()
{
// Test that input validation errors (like ArgumentException from JSON deserialization)
// are returned as tool execution errors (IsError=true) rather than protocol errors, per SEP-1303.
const string errorMessage = "Input validation failed: invalid date format";
await Can_Handle_Requests(
new ServerCapabilities
{
Tools = new()
},
method: RequestMethods.ToolsCall,
configureOptions: options =>
{
options.Handlers.CallToolHandler = async (request, ct) =>
{
// Simulate an input validation error (like what would happen with wrong argument types)
throw new ArgumentException(errorMessage);
};
options.Handlers.ListToolsHandler = (request, ct) => throw new NotImplementedException();
},
assertResult: (_, response) =>
{
var result = JsonSerializer.Deserialize<CallToolResult>(response, McpJsonUtilities.DefaultOptions);
Assert.NotNull(result);
Assert.True(result.IsError, "Input validation errors should be returned as tool execution errors (IsError=true), not protocol errors");
Assert.NotEmpty(result.Content);
var textContent = Assert.IsType<TextContentBlock>(result.Content[0]);
// ArgumentException should result in a generic error message that doesn't expose the exception details
Assert.DoesNotContain(errorMessage, textContent.Text);
Assert.Contains("An error occurred", textContent.Text);
});
}
[Fact]
public async Task Can_Handle_Call_Tool_Requests_With_McpProtocolException()
{