Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Streamable HTTP: a message with an `id` but no `method`, `result` or `error` is answered 202 with no body

Đang mở
#1,476 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

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
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
go
Lĩnh vực
api, backend

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

Mở trong Codespaces

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.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của modelcontextprotocol/go-sdk

Tất cả issue của modelcontextprotocol/go-sdk

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.