Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Streamable HTTP: malformed requests return raw pydantic errors to the client

未关闭 适合新手
#3,698 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
api, security

调研方向

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 内容生成。

描述

bug v1 v2
Initial Checks
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

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

modelcontextprotocol/python-sdk 的其他 Issue

查看 modelcontextprotocol/python-sdk 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。