modelcontextprotocol / modelcontextprotocol/python-sdk
Fix Streamable HTTP Accept header quality-factor handling
未关闭
还没有人认领这个 Issue。
bug
needs confirmation
P3
v1
v2
- 主要语言
- Python
- 星标
- 24.3k
- 派生
- 4k
- 平均合并
- 1 天 1 小时
- 30 天内合并 PR
- 31
描述
Initial Checks
- I confirm that I'm using the latest version of MCP Python SDK
- I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue
Description
Streamable HTTP currently ignores q=0 values in the Accept header, so requests that explicitly mark a media type as unacceptable can still be accepted. This violates RFC 7231 semantics for content negotiation and can cause clients and servers to disagree about which response format is actually allowed.
Example Code
from starlette.requests import Request
def check_accept_headers(request: Request) -> tuple[bool, bool]:
accept_header = request.headers.get("accept", "")
accept_types = [media_type.strip().split(";")[0].strip().lower() for media_type in accept_header.split(",")]
has_wildcard = "*/*" in accept_types
has_json = has_wildcard or any(t in ("application/json", "application/*") for t in accept_types)
has_sse = has_wildcard or any(t in ("text/event-stream", "text/*") for t in accept_types)
return has_json, has_sse
# Example: client explicitly rejects JSON
request = Request({"type": "http", "method": "GET", "headers": [(b"accept", b"application/json;q=0, text/event-stream;q=1.0")]})
print(check_accept_headers(request))
# -> (True, True)
Python & MCP Python SDK
Python 3.12.10
MCP Python SDK: 1.28.1
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先跟踪 Streamable HTTP 请求处理流程以及 issue 中的 check_accept_headers 示例,重点关注 Accept 参数的解析方式。使用提供的 application/json;q=0 和 text/event-stream;q=1.0 请求验证行为,并考虑其他 quality factor 情况;完成的标准是,在 RFC 7231 语义下,明确不可接受的媒体类型不会被当作已接受。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- api, backend
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 68/100