modelcontextprotocol / modelcontextprotocol/python-sdk
ExceptionGroup wrapping obscures real errors from task groups
未关闭
还没有人认领这个 Issue。
bug
P1
v2
- 主要语言
- Python
- 星标
- 24.3k
- 派生
- 4k
- 平均合并
- 1 天 1 小时
- 30 天内合并 PR
- 31
描述
Summary
When SDK internal anyio task group tasks fail, the real error is wrapped in a BaseExceptionGroup alongside Cancelled exceptions from cancelled sibling tasks. This makes error classification extremely difficult for callers — they cannot reliably determine the root cause of a failure.
There are 16 create_task_group() usages across the SDK with no except* syntax or ExceptionGroup unwrapping anywhere.
Expected Behavior
- Callers should receive the original exception, not an ExceptionGroup wrapping it alongside cancellation noise
- When a task group has one real failure and N cancelled siblings, only the real failure should propagate
Current Behavior
- A single connection failure produces a
BaseExceptionGroupcontaining the real error plus multipleCancelledexceptions - Callers must manually unwrap exception groups to find the root cause
- This affects ~80+ call sites across the SDK where task groups are used
Affected Code
src/mcp/shared/session.py(session task groups)src/mcp/client/streamable_http.py(transport task groups)- All other
create_task_group()sites
Related
- #1742 — broader typed error classes design
- #1830 — CancelledError indistinguishable from external cancellation (closed but related)
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先阅读 src/mcp/shared/session.py 和 src/mcp/client/streamable_http.py 中的任务组处理逻辑,然后检查 issue 中提到的其他 create_task_group() 位置。复现一个伴随已取消的兄弟任务的连接失败,并验证真实异常会在受影响的调用点之间传播,且不会产生取消噪声。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- backend
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 48/100