Streamable HTTP: a message with an `id` but no `method`, `result` or `error` is answered 202 with no body
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 75/100
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Go
- Star
- 5.3k
- Fork
- 606
- Merge trung bình
- 1 ngày 7 giờ
- Pull request đã merge (30 ngày)
- 77
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của modelcontextprotocol/go-sdk
-
Expose generic `SendNotification` on `ServerSession` for custom protocol extensionsCó thể đã có người làm @ajuijas đã nhận 228 ngày trước. Đang mởneeds investigation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
modelcontextprotocol/go-sdk#745 · 13 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
mcp: a client DELETE waits for a pending keepalive pingCó thể đã có người làm @vshalpnjabi đã nhận hôm nay. Đang mở
modelcontextprotocol/go-sdk#1470 · 2 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
mcp: LoggingHandler drops records logged at custom slog levelsCó thể đã có người làm @kaankucukx đã nhận 5 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 45/100
modelcontextprotocol/go-sdk#1445 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
mcp: Client.Connect falls back to initialize after a 401 on server/discover, running the authorization flow twiceCó thể đã có người làm @kerthans đã nhận 8 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
modelcontextprotocol/go-sdk#1423 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
jsonrpc: decimal and exponent integer IDs still lose precision after #1401Có thể đã có người làm @skosovsky đã nhận 13 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 25/100
modelcontextprotocol/go-sdk#1404 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của modelcontextprotocol/go-sdk
Issue tương tự
-
Type: Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
projectdiscovery/notify#569 ·
-
internal
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Results from sources can contain invalid host namesCó thể đã có người làm @Mzack9999 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
projectdiscovery/subfinder#1983 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug triaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
radius-project/radius#13566 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày