Title: fix: collapse single-exception ExceptionGroups from task groups by Varun6578 · Pull Request #2245 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: fix: collapse single-exception ExceptionGroups from task groups by Varun6578 · Pull Request #2245 · modelcontextprotocol/python-sdk
X Title: fix: collapse single-exception ExceptionGroups from task groups by Varun6578 · Pull Request #2245 · modelcontextprotocol/python-sdk
Description: Summary Fixes #2114 — ExceptionGroup wrapping obscures real errors from task groups. When an anyio task group contains tasks and one fails, the exception is always wrapped in an ExceptionGroup — even if there is only a single real exception. This makes it impossible for callers to catch specific error types with except ConnectionError:. Changes New module src/mcp/shared/_task_group.py: collapse_exception_group() — recursively unwraps single-exception BaseExceptionGroups _CollapsingTaskGroup — drop-in wrapper around anyio's TaskGroup that collapses on __aexit__ create_mcp_task_group() — factory function replacing anyio.create_task_group() All 16 anyio.create_task_group() call sites updated across: Client transports: sse.py, stdio.py, websocket.py, streamable_http.py, _memory.py Server transports: sse.py, stdio.py, websocket.py, streamable_http.py Shared: session.py, session_group.py Server internals: lowlevel/server.py, streamable_http_manager.py, task_support.py, task_result_handler.py 12 new tests covering collapse logic, integration with task groups, edge cases Ruff config: added builtins for BaseExceptionGroup/ExceptionGroup (Python 3.10 compat) Behavior Scenario Before After Single task fails ExceptionGroup([ConnectionError]) ConnectionError raised directly Single task fails + siblings cancelled ExceptionGroup([ConnectionError]) ConnectionError raised directly Multiple tasks fail ExceptionGroup([A, B]) ExceptionGroup([A, B]) (unchanged) No failures Clean exit Clean exit (unchanged) The collapsed exception preserves the ExceptionGroup as __cause__ for debugging.
Open Graph Description: Summary Fixes #2114 — ExceptionGroup wrapping obscures real errors from task groups. When an anyio task group contains tasks and one fails, the exception is always wrapped in an ExceptionGroup — ev...
X Description: Summary Fixes #2114 — ExceptionGroup wrapping obscures real errors from task groups. When an anyio task group contains tasks and one fails, the exception is always wrapped in an ExceptionGroup — ev...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/pull/2245
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:a7618cae-1609-da2c-4ed5-9e4755c9de33 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 97A8:3D312F:7F36B1:A591B6:6A6000AC |
| html-safe-nonce | 39fdc0bedcc740ea67a9635e9f48dffc76f26d14083accf578b4d30faee79a8e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5N0E4OjNEMzEyRjo3RjM2QjE6QTU5MUI2OjZBNjAwMEFDIiwidmlzaXRvcl9pZCI6IjM3NDUxNDU0ODMxMzQyMzg4OTMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 6cec89cdcfcdd632c361addca38ed4eedd7eb1d68887ffef7ca525c987f9d8e1 |
| hovercard-subject-tag | pull_request:3367246229 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/modelcontextprotocol/python-sdk/pull/2245/files |
| twitter:image | https://avatars.githubusercontent.com/u/34965159?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/34965159?s=400&v=4 |
| og:image:alt | Summary Fixes #2114 — ExceptionGroup wrapping obscures real errors from task groups. When an anyio task group contains tasks and one fails, the exception is always wrapped in an ExceptionGroup — ev... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5789899e92b20db289de946d86eb20bf5c9626276695d68f58a8c47cdda699b7 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git |
| octolytics-dimension-user_id | 182288589 |
| octolytics-dimension-user_login | modelcontextprotocol |
| octolytics-dimension-repository_id | 862584018 |
| octolytics-dimension-repository_nwo | modelcontextprotocol/python-sdk |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 862584018 |
| octolytics-dimension-repository_network_root_nwo | modelcontextprotocol/python-sdk |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 6ddc048ddf80664b9b33547b619db10313c482f1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width