Streamable HTTP: a message with an `id` but no `method`, `result` or `error` is answered 202 with no body
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
Start in internal/jsonrpc2/messages.go at DecodeMessage, then trace how StreamableHTTPHandler handles decoded responses with no matching request. Add or locate tests for messages with an id but no method, result or error; check that a present result: null still counts as a response. Done means malformed input returns HTTP 400 with a JSON-RPC -32600 error carrying the id, while valid responses and notifications retain their behavior.
由索引模型根据 Issue 内容生成。
描述
What happened?
A JSON-RPC message that has an id but none of method, result or error is answered with HTTP 202 and an empty body by StreamableHTTPHandler. The sender gets no sign that the message was invalid, and nothing is processed.
The same malformed message without an id is already refused: HTTP 400, malformed payload: invalid request. So the SDK treats the missing method as invalid in one case and accepts it silently in the other.
Cause, as far as I can tell: DecodeMessage (internal/jsonrpc2/messages.go) treats any message without a method key as a response ("no method key, should be a response") and only rejects it when the id is invalid. It never checks that result or error is present. The message is then routed as a response to a request that does not exist, the transport takes the branch for "no calls in this POST", and writes http.StatusAccepted.
Expected: the message is neither a request, a notification nor a response, so it should be refused like the no-id case, with HTTP 400 and a JSON-RPC -32600 Invalid Request error that carries the id.
The MCP Streamable HTTP page (2026-07-28) says the POST body must be a single JSON-RPC request or notification, that an accepted notification gets 202 Accepted with no body, and that when the server cannot accept the input it returns an HTTP error status such as 400. A 202 for a message that is not a valid notification or response does not fit that.
How to reproduce
package main
import (
"fmt"
"io"
"net/http"
"net/http/httptest"
"strings"
"github.com/modelcontextprotocol/go-sdk/mcp"
)
func main() {
srv := mcp.NewServer(&mcp.Implementation{Name: "repro", Version: "0"}, nil)
h := mcp.NewStreamableHTTPHandler(func(*http.Request) *mcp.Server { return srv },
&mcp.StreamableHTTPOptions{Stateless: true})
ts := httptest.NewServer(h)
defer ts.Close()
post := func(label, body string) {
req, _ := http.NewRequest(http.MethodPost, ts.URL, strings.NewReader(body))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json, text/event-stream")
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
b, _ := io.ReadAll(resp.Body)
resp.Body.Close()
fmt.Printf("%-24s -> HTTP %d, body %q\n", label, resp.StatusCode, string(b))
}
post("id, no method", `{"jsonrpc":"2.0","id":5,"params":{"name":"x","arguments":{}}}`)
post("no id, no method", `{"jsonrpc":"2.0","params":{}}`)
}
Output on v1.7.0 and v1.8.0 (the code in main is the same):
id, no method -> HTTP 202, body ""
no id, no method -> HTTP 400, body "malformed payload: invalid request\n"
A possible fix: in DecodeMessage, when there is no method key, also require that a result or an error key is present (check the key, not the value, since "result": null is a valid response); otherwise return ErrInvalidRequest.
Where did you hit this?
An MCP server using StreamableHTTPHandler in stateless mode. QA found it by deleting "method": "tools/call" from a request by hand and getting a 202 with no body.
Go MCP SDK version
v1.7.0 and v1.8.0 (and main, by reading the code)
Go version
go1.27.1 darwin/arm64
Logs
None; the response is the log.
- 主要语言
- Go
- 星标
- 5.3k
- 派生
- 606
- 平均合并
- 1 天 7 小时
- 30 天内合并 PR
- 77
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
modelcontextprotocol/go-sdk 的其他 Issue
-
Expose generic `SendNotification` on `ServerSession` for custom protocol extensions可能已有人在做 @ajuijas 于 228 天前认领。 未关闭needs investigation
难度 2/5 1-3 小时 新手友好度 72/100
modelcontextprotocol/go-sdk#745 · 13 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
-
mcp: a client DELETE waits for a pending keepalive ping可能已有人在做 @vshalpnjabi 今天认领。 未关闭
modelcontextprotocol/go-sdk#1470 · 2 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
mcp: LoggingHandler drops records logged at custom slog levels可能已有人在做 @kaankucukx 于 5 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 45/100
modelcontextprotocol/go-sdk#1445 ·
维护者通常 1 天内回复
-
mcp: Client.Connect falls back to initialize after a 401 on server/discover, running the authorization flow twice可能已有人在做 @kerthans 于 9 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 35/100
modelcontextprotocol/go-sdk#1423 · 1 条评论 ·
维护者通常 1 天内回复
-
jsonrpc: decimal and exponent integer IDs still lose precision after #1401可能已有人在做 @skosovsky 于 14 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 25/100
modelcontextprotocol/go-sdk#1404 · 2 条评论 ·
维护者通常 1 天内回复
查看 modelcontextprotocol/go-sdk 的全部 Issue
相似的 Issue
-
[Bug]: Anthropic Responses converter forwards empty text blocks, upstream rejects with 400可能已有人在做 @david-choi-querypie 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
area:web p3
难度 2/5 1-3 小时 新手友好度 72/100
Lets-Parley/Parley#912 ·
维护者通常 1 天内回复
-
bug observability
难度 2/5 1-3 小时 新手友好度 86/100
sagar2395/snowopslabs#164 ·
维护者通常 1 天内回复
-
enhancement help wanted
难度 2/5 1-3 小时 新手友好度 76/100
Git-Hospital/githealthcheck#61 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
afreidah/s3-orchestrator#1824 ·
维护者通常 1 天内回复