Skip to content

Conversation

@aminsaedi
Copy link
Contributor

Per the MCP specification, tool execution errors should be returned as tool results with isError=true, not as JSON-RPC protocol errors (-32603). This allows LLMs to see the error message and self-correct by retrying with different parameters.

Previously, all handler errors were returned as Go errors which mcp-go converted into JSON-RPC -32603 responses. MCP clients either crash or silently discard these, so the LLM never sees what went wrong.

This adds a middleware that catches handler errors and converts them to mcp.NewToolResultError() responses. The middleware is registered before the logger and auth middlewares, so it catches all tool handler errors regardless of which tool triggered them.

Per the MCP specification, tool execution errors should be returned as
tool results with isError=true, not as JSON-RPC protocol errors (-32603).
This allows LLMs to see the error message and self-correct by retrying
with different parameters.

Previously, all handler errors were returned as Go errors which mcp-go
converted into JSON-RPC -32603 responses. MCP clients either crash or
silently discard these, so the LLM never sees what went wrong.

This adds a middleware that catches handler errors and converts them to
mcp.NewToolResultError() responses. The middleware is registered before
the logger and auth middlewares, so it catches all tool handler errors
regardless of which tool triggered them.
@korotovsky
Copy link
Owner

Could you please add integration test for this?

Verifies that the error recovery middleware correctly converts handler
errors into isError tool results instead of JSON-RPC protocol errors.
Uses mcp-go client/server wired via stdio pipes to test the full
middleware chain without external dependencies.
@aminsaedi aminsaedi force-pushed the fix/tool-errors-as-isError-results branch from 5c02ce8 to 25aea2b Compare February 9, 2026 19:20
@aminsaedi
Copy link
Contributor Author

@korotovsky pushed

@korotovsky korotovsky merged commit 6c4e8fb into korotovsky:master Feb 11, 2026
2 checks passed
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.

2 participants