Skip to content

Conversation

@jonathan-fulton
Copy link
Contributor

Summary

Fixes error propagation in the /mcp endpoint tool invocation handler.

Problem

When using server/<server-id>/mcp endpoint for tool invocations, exceptions (e.g., 401 unauthorized errors) resulted in empty responses instead of actual error messages.

The previous code caught all exceptions and returned an empty list:

except Exception as e:
    logger.exception(f"Error calling tool '{name}': {e}")
    return []

Solution

Re-raise exceptions after logging so the MCP SDK can properly convert them to JSON-RPC error responses:

except Exception as e:
    logger.exception(f"Error calling tool '{name}': {e}")
    raise

This ensures clients receive proper error messages instead of empty results.

Testing

Verified that errors are now properly returned in the response body instead of empty results.

Fixes #2570

@jonathan-fulton jonathan-fulton force-pushed the fix/mcp-endpoint-error-propagation branch from 43371db to def9c13 Compare January 31, 2026 18:38
@crivetimihai crivetimihai self-assigned this Jan 31, 2026
@crivetimihai crivetimihai added this to the Release 1.0.0-RC1 milestone Jan 31, 2026
@crivetimihai
Copy link
Member

Thanks @jonathan-fulton! Important fix - swallowing exceptions and returning empty results was definitely masking real errors from clients. Re-raising to let the MCP SDK convert them to proper JSON-RPC error responses is the right approach. I'll start merging and rebasing.

@crivetimihai crivetimihai force-pushed the fix/mcp-endpoint-error-propagation branch from def9c13 to 65d62be Compare January 31, 2026 20:19
Previously, exceptions in tool invocation were caught and an empty list was
returned, hiding error details from clients. Now errors are re-raised to let
the MCP SDK properly convert them to JSON-RPC error responses.

This ensures clients see actual error messages (e.g., '401 Unauthorized')
instead of empty responses.

Fixes IBM#2570

Signed-off-by: Jonathan Fulton <[email protected]>
@crivetimihai crivetimihai force-pushed the fix/mcp-endpoint-error-propagation branch from 65d62be to 9e0a4ae Compare January 31, 2026 20:34
@crivetimihai crivetimihai merged commit 8c61345 into IBM:main Jan 31, 2026
51 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.

[BUG]: Error message not propogated in /mcp endpoint responses

2 participants