modelcontextprotocol / modelcontextprotocol/python-sdk
Invalid JSON-RPC envelope errors are not correlated with the original request id
還沒有人認領這個 Issue。
- 主要語言
- 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
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/messagelog notification withlevel:"error"anddata:"Internal Server Error", but no JSON-RPC error response is sent for the original requestid. A follow-uppingsucceeds. - Streamable HTTP: The server returns HTTP 400 with a JSON-RPC error response using
id:"server-error"andcode:-32602, rather than the original requestid. A follow-uppingsucceeds 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
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 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