Streamable HTTP: malformed requests return raw pydantic errors to the client
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
pydantic 和 JSON 解析的原始文本来自 src/mcp/server/streamable_http.py 中 POST 处理器,大约第 580-596 行。_streamable_http_modern.py 中的 2026-07-28 路径(大约第 415 行)已经返回固定消息,因此照着这个模式来做。运行示例脚本查看当前的响应体,然后检查格式错误的输入是否返回固定的 Parse error 或 Invalid JSON-RPC message 文本,而详细信息只写入服务器日志。为缺少 jsonrpc 和非 JSON 的情况添加测试,并在 v1.x 上检查同样的修改。
由索引模型根据 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)
Also applies to latest 1.x
Description
When the Streamable HTTP POST handler rejects a malformed body, it returns the raw exception text to the client (streamable_http.py L580-L596):
- No
"jsonrpc"field →"Validation error: 6 validation errors for union[JSONRPCRequest,...] ... input_value={...} ... https://errors.pydantic.dev/2.14/v/missing" - Not JSON →
"Parse error: EOF while parsing a value at line 1 column 27"
A security audit of our MCP server flagged this: the errors reveal that the backend is Python, using pydantic (down to the exact version) and the MCP Python SDK, which helps an attacker enumerate the environment.
Expected: fixed messages (Parse error, Invalid JSON-RPC message), with detail in the server log only. The 2026-07-28 path already does this (_streamable_http_modern.py L415).
The same code is on v1.x, which we run. I’d like to fix both if assigned: a few lines plus tests, with no new API.
Related: #3557 (error code on these lines), #3572 (same pydantic text in tool-argument errors).
Disclosure: this issue was drafte by Claude Code and reviewed/iterated by myself and another senior developer. I ran the reproduction and verified the output myself.
Example Code
import json
from mcp.server import MCPServer
from mcp.server.transport_security import TransportSecuritySettings
from starlette.testclient import TestClient
server = MCPServer("repro")
@server.tool()
def echo(text: str) -> str:
return text
app = server.streamable_http_app(
stateless_http=True,
transport_security=TransportSecuritySettings(enable_dns_rebinding_protection=False),
)
headers = {
"Accept": "application/json, text/event-stream",
"Content-Type": "application/json",
"mcp-protocol-version": "2025-06-18",
}
with TestClient(app) as client:
for body in (
json.dumps({"id": 1, "method": "tools/call", "params": {"name": "echo", "arguments": {"text": "hi"}}}),
json.dumps([{"jsonrpc": "2.0", "id": 1, "method": "tools/list"}]),
'{"jsonrpc": "2.0", "id": 1,',
):
response = client.post("/mcp", content=body, headers=headers)
print(response.status_code, json.dumps(response.json(), indent=2))
Python & MCP Python SDK
Python 3.12.9
mcp 2.3.0
pydantic 2.14.0
- 主要语言
- Python
- 星标
- 24.5k
- 派生
- 4k
- 平均合并
- 18 小时 28 分钟
- 30 天内合并 PR
- 38
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
modelcontextprotocol/python-sdk 的其他 Issue
-
bug v1 v2
难度 2/5 1-3 小时 新手友好度 72/100
modelcontextprotocol/python-sdk#3725 ·
维护者通常 1 天内回复
-
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 天内回复
-
Streamable HTTP: Content-Type handling is order dependent and accepts invalid values可能已有人在做 @jayzuccarelli 于 5 天前认领。 未关闭bug v1 v2
难度 2/5 1-3 小时 新手友好度 76/100
modelcontextprotocol/python-sdk#3691 · 1 条评论 ·
维护者通常 1 天内回复
-
Skills: URI traversal validation skips percent-encoded dot-segments可能已有人在做 @Varshith-Kali 于 3 天前认领。 未关闭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 天内回复
查看 modelcontextprotocol/python-sdk 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
ok-oldking/ok-wuthering-waves#1785 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
healthchecks/healthchecks#1349 ·
-
deployment release-lag
难度 1/5 1 小时以内 新手友好度 68/100
nolte/kamerplanter#2374 ·
维护者通常 1 天内回复
-
batchterms() drops queries without a similar() clause, misaligning results with inputs可能已有人在做 @MohammadHijjawi97 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 86/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 77/100
lidofinance/diffyscan#239 ·
维护者通常 1 天内回复