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