modelcontextprotocol / modelcontextprotocol/python-sdk

Invalid JSON-RPC envelope errors are not correlated with the original request id

未关闭
#2,848 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

bug needs confirmation P2
主要语言
Python
星标
24.3k
派生
4k
平均合并
1 天 1 小时
30 天内合并 PR
31

描述

Initial Checks
Description

After a normal initialization flow, several id-bearing JSON-RPC messages that are syntactically valid JSON but invalid JSON-RPC request envelopes are not correlated back to the original request id.

This is not meant to require implementations to recover an id after every low-level parse/deserialization failure. The narrower concern is that these payloads are parsed far enough to produce request-specific validation errors, while the original top-level id is still present in the payload. Preserving that id where feasible would make the error response easier for clients to correlate.

The tested inputs were:

Case Request Validation detail
wrong jsonrpc version {"jsonrpc":"1.0","id":3,"method":"ping","params":{}} JSONRPCRequest.jsonrpc: value should be "2.0"
missing jsonrpc field {"id":4,"method":"ping","params":{}} JSONRPCRequest.jsonrpc: field required
method as number {"jsonrpc":"2.0","id":8,"method":12345,"params":{}} JSONRPCRequest.method: input should be a valid string

For all three envelope-invalid inputs, I would expect -32600 Invalid Request or -32602 error response that can be correlated to the original request where possible.

Observed behavior was consistent by transport:

  • stdio: The server emits a notifications/message log notification with level:"error" and data:"Internal Server Error", but no JSON-RPC error response is sent for the original request id. A follow-up ping succeeds.
  • Streamable HTTP: The server returns HTTP 400 with a JSON-RPC error response using id:"server-error" and code:-32602, rather than the original request id. A follow-up ping succeeds over SSE.
Example Code
"""
With a Python SDK MCP server running over stdio or Streamable HTTP,
complete a normal initialization flow, then send these requests in isolation.
"""

requests = [
    # Wrong JSON-RPC version: valid JSON, invalid JSON-RPC envelope.
    {"jsonrpc": "1.0", "id": 3, "method": "ping", "params": {}},

    # Missing jsonrpc field: valid JSON, invalid JSON-RPC envelope.
    {"id": 4, "method": "ping", "params": {}},

    # method is not a string: valid JSON, invalid JSON-RPC envelope.
    {"jsonrpc": "2.0", "id": 8, "method": 12345, "params": {}},
]
Python & MCP Python SDK
* Python: `3.12.3`
* MCP Python SDK stable release: `v1.27.2` (`62137874ff26dd74d2fea80ff528a7fd9ca7a5e7`)
* Transports: stdio and Streamable HTTP

贡献指南

打开贡献指南

从这里开始

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

调研方向

首先,针对 stdio 和 Streamable HTTP 两种传输复现三个无效的 JSON-RPC envelope payload。跟踪它们的验证和错误响应路径;完成的标准是:envelope 无效的请求返回适当的 JSON-RPC 错误,并在可行时保留原始 id,同时不会导致后续 ping 请求出现回归问题。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
api
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
活跃
描述清晰度
基本清楚
新手友好度
48/100

把新 issue 发到你的邮箱

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