Streamable HTTP: Content-Type handling is order dependent and accepts invalid values
維護者通常 1 天內回覆
@jayzuccarelli 已經在處理了。
開始於 2026年10月12日。
評估
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 新手友好度
- 76/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- python
研究方向
先閱讀 src/mcp/server/transport_security.py 和 src/mcp/server/streamable_http.py 中的 Content-Type 檢查,接著追蹤對應的 modern transport 檢查。為列出的 Content-Type 值新增或更新測試,包括帶參數的值和以逗號分隔的值。完成標準是所有 transport 都一致地只接受 application/json,參數可選。
由索引模型根據 Issue 內容生成。
描述
Initial Checks
- I confirm that I'm using the newest release of my line (the latest 2.x, or the latest 1.x if I'm still on v1)
- I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue
Release line
2.x (current stable)
Description
The Content-Type header:
- accepts values that are not JSON media types.
application/json, text/plainis accepted and the request is executed, although a comma cannot appear inside a media type. On the modern transportapplication/jsonxis accepted as well - The answer depends on order.
application/json, text/plainis accepted whiletext/plain, application/jsonis rejected, so the same invalid value gets opposite answers.
The first check is a prefix test in the middleware:
# src/mcp/server/transport_security.py
return content_type is not None and content_type.lower().startswith("application/json")
The second splits the value on ; and , and compares the result:
# src/mcp/server/streamable_http.py
content_type_parts = [part.strip() for part in content_type.split(";")[0].split(",")]
return any(part == CONTENT_TYPE_JSON for part in content_type_parts)
The second check rejects application/jsonx. The 2.x modern transport has no equivalent, so it accepts that value.
For reference, the TypeScript SDK answers 415 for application/json, text/plain and for application/jsonx, and mcp-go answers 400 for both.
Reproduction
Against a server started with stateless_http=True, so no session handshake is needed:
curl -s http://127.0.0.1:8901/mcp \
-H 'Content-Type: application/json, text/plain' \
-H 'Accept: application/json, text/event-stream' \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"ping","arguments":{}}}'
Observed: 200 with a normal JSON-RPC result, and the tool's handler runs.
Content-Type sent |
Expected | handshake transport (1.x and 2.x) | modern transport (2.x only) |
|---|---|---|---|
application/json |
accepted | 200 |
200 |
application/json; charset=utf-8 |
accepted | 200 |
200 |
application/json, text/plain |
rejected | 200, body executed |
200, body executed |
application/jsonx |
rejected | 415 |
200, body executed |
text/plain, application/json |
rejected | 400 |
400 |
text/plain |
rejected | 400 |
400 |
For modern transport calls were sent with MCP-Protocol-Version: 2026-07-28 plus the Mcp-Method and Mcp-Name headers.
Fix
Parse the media type, the segment before the first ;, and compare it exactly to application/json. Parameters keep working, so application/json; charset=utf-8 is unaffected, while the values above are rejected.
Python & MCP Python SDK
Reproduced on the 2.x line (`2.2.0`, `2.3.0`) and the 1.x line (`1.30.0`)
- 主要語言
- Python
- 星號
- 24.5k
- 分支
- 4k
- 平均合併
- 18 小時 31 分鐘
- 30 天內合併 PR
- 38
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
modelcontextprotocol/python-sdk 的其他 Issue
-
2026-07-28 SSE responses share one header list, so in-place middleware appends leak across responses可能重新可做 關聯的 PR 已關閉且未合併。 未關閉bug spec-2026-07-28 v2
難度 2/5 1-3 小時 新手友好度 68/100
modelcontextprotocol/python-sdk#3701 · 1 則留言 ·
維護者通常 1 天內回覆
-
bug v1 v2
難度 2/5 1-3 小時 新手友好度 78/100
modelcontextprotocol/python-sdk#3698 ·
維護者通常 1 天內回覆
-
Skills: URI traversal validation skips percent-encoded dot-segments可能已有人在做 @Varshith-Kali 於 1 天前認領。 未關閉bug v2
難度 2/5 1-3 小時 新手友好度 78/100
modelcontextprotocol/python-sdk#3685 · 2 則留言 ·
維護者通常 1 天內回覆
-
Type annotation gaps and unhandled FileNotFoundError in src/mcp/cli/cli.py可能重新可做 關聯的 PR 已關閉且未合併。 未關閉enhancement
難度 2/5 1-3 小時 新手友好度 84/100
modelcontextprotocol/python-sdk#3673 · 4 則留言 ·
維護者通常 1 天內回覆
-
Streamable HTTP server rejects a mixed-case Content-Type with 415可能已有人在做 @CRYPTONIKAV 於 4 天前認領。 未關閉bug v1 v2
難度 2/5 1-3 小時 新手友好度 75/100
modelcontextprotocol/python-sdk#3670 · 4 則留言 ·
維護者通常 1 天內回覆
查看 modelcontextprotocol/python-sdk 的全部 Issue
相似的 Issue
-
good first issue
難度 2/5 1-3 小時 新手友好度 85/100
btclib-org/btclib-node#1955 ·
維護者通常 1 天內回覆
-
documentation v0.9.2
難度 2/5 半天 新手友好度 72/100
khuisman/mcp-gee-sweet#1033 ·
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 76/100
ossf/cve-bin-tool#5966 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 62/100
維護者通常 2 天內回覆
-
write_iceberg ignores the table's write.parquet.compression-codec property可能已有人在做 @YuangGao 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 82/100
Eventual-Inc/Daft#7606 ·
維護者通常 1 天內回覆