Repository navigation
Fix self-referential connection error causes - #4720
Merged
Merged
Conversation
🤖 Generated with OpenAI Codex
jakekaplan
marked this pull request as ready for review
July 30, 2026 18:46
mitchnielsen
approved these changes
Jul 30, 2026
jlowin
approved these changes
Jul 30, 2026
jlowin
pushed a commit
that referenced
this pull request
Oct 5, 2026
…or unchanged (#5344) `ErrorHandlingMiddleware.on_message` always re-raised with `raise transformed_error from error`. `_transform_error` returns the same exception for every `MCPError`, and for every error when `transform_errors=False`. In those cases the error became its own `__cause__`, and the original cause was lost to everything further out. A `RetryMiddleware` added before it could no longer see the `ConnectionError` behind a `ToolError`, so it stopped retrying. Anything walking the exception chain found a loop instead of the real exception. An untransformed error is now re-raised as-is and keeps its original cause. Transformed errors still chain from the error they replace. #4720 fixed the same pattern for the client's connection errors. ```python mcp.add_middleware(RetryMiddleware(retry_exceptions=(ConnectionError,))) mcp.add_middleware(ErrorHandlingMiddleware(transform_errors=False)) @mcp.tool def fetch() -> str: raise ConnectionError("upstream unreachable") # before: the ToolError's __cause__ is the ToolError itself, so the call is never retried # after: its __cause__ is the ConnectionError, and RetryMiddleware retries the call ``` Fixes #5329. Co-authored-by: asemabdallah <asasem547@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Client._connect()unconditionally chained normalized connection failures, causing pass-throughMCPErrorandHTTPStatusErrorinstances to become their own__cause__. Cause-chain traversal could therefore loop indefinitely after an upstream HTTP failure.Preserved exceptions are now raised directly, while newly created
RuntimeErrorwrappers retain the original failure as their cause:🤖 Generated with OpenAI Codex