Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

renvins
Copy link
Contributor

@renvins renvins commented Sep 26, 2025

Pull Request Description

Changes

This PR enhance errors' explanations that were opaque when encountering http errors during connection. That was happening because SSE runs behind a TaskGroup, and the MCP doesn't handle the exceptions as in the streamable and doesn't convert them to McpError, so exceptions are propagated to our code through ExceptionGroup (due to async TaskGroup). Now we're retrieving the last exception (in theory in our case is always one) and making it explicit.

It were also removed all the checks for fallback, because when Streamable HTTP transport fails, it always raise an McpError that doesn't contain further information about why the error happened and the status code (only custom status codes of MCP) and then the fallback is always tried (it was always tried also before). That's because in the MCP, streamable error handling is different: if something is wrong a JSONRPCError is generated and in the ClientSession after some checks, an McpError is raised.

Someone could ask why SSE doesn't raise McpError and directly http or connections errors. That's because of the nature of SSE and how it's implemented on MCP. Errors are not handled in try blocks so when for example httpx raises an HTTPStatusError, it is propagated to our code.

Errors now

image image

Testing

  • Unit Tests: No new unit tests were added. The change corrects behavior that was not previously covered.
  • Manual Testing: I verified by running manual tests on the streamable transport with auth problems and connection problems.

Backwards Compatibility

These changes are fully backwards compatible.

Related Issues

Fixes #278

@renvins
Copy link
Contributor Author

renvins commented Sep 26, 2025

@pietrozullo Please review this fix and let me know. I had to put a lot of effort in it to fully understand the process behind!

@renvins renvins requested a review from pietrozullo September 26, 2025 15:15
@renvins renvins merged commit 07f088b into main Sep 27, 2025
16 checks passed
@renvins renvins deleted the fix/opaque-errors branch September 27, 2025 10:22
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.

Errors explanations are opaque and not clear when connecting or authenticating
2 participants