modelcontextprotocol / modelcontextprotocol/python-sdk
Introduce typed error classes with metadata
未关闭
还没有人认领这个 Issue。
breaking change
enhancement
P2
v2
- 主要语言
- Python
- 星标
- 24.3k
- 派生
- 4k
- 平均合并
- 1 天 1 小时
- 30 天内合并 PR
- 31
描述
Summary
Replace generic exceptions with SDK-native error classes that include useful metadata like fault attribution, retryability, and HTTP details.
Problem
The SDK currently raises generic exceptions from various layers (httpx, anyio, task groups) with no context about:
- Whether the error is retryable
- Who is at fault (client, server, network, protocol violation)
- HTTP status codes and response bodies (often discarded)
This makes it hard for users to build robust error handling.
Goal
A hierarchy of typed errors like:
McpError(base) withfault,is_retryable,http_status_code,response_bodyMcpTransportErrorfor connection/network issuesMcpProtocolErrorfor invalid JSON-RPC responsesMcpAuthErrorfor 401/403 responses
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先追踪 SDK 当前在哪些位置暴露来自 httpx、anyio 和任务组的通用异常。定义拟议 McpError 层次结构的范围和元数据要求,包括故障归因、可重试性、HTTP 状态码和响应正文。设计确定且受影响的错误路径始终暴露带类型的 SDK 原生错误,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- api, backend
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 冷清
- 描述清晰度
- 需要澄清
- 新手友好度
- 35/100