mcp: stateless subscriptions/listen stream can start with an unrequested tools/list_changed
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
- #1553 của @luiacuaniello — đã đóng, không merge
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 25/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- go
- Lĩnh vực
- backend-api-design
Hướng nghiên cứu
Start with the stateless StreamableHTTPHandler and ServerSession.handle paths described in the report, then trace how negotiatedLegacyProtocol affects Server.notifySessions and stateless Write during subscriptions/listen setup. Reproduce the race using the supplied Go program against the reported SDK versions. Done means the first event is always the requested listen acknowledgment and unrequested list-changed notifications do not reach that stream; a test should cover the setup race.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Checklist
- I searched the existing issues, and this has not been reported before.
- This is a real problem that I ran into myself, using the latest release of the SDK.
- I ran into it in a production system, not in a toy example, a benchmark, or an automated or AI-driven scan of the code.
- I (a human) examined the relevant SDK code, and wrote or reviewed every line of this report. It is not unreviewed AI output.
- This report is brief and concise, and sticks to the facts needed to understand the problem.
What happened?
Using a stateless StreamableHTTPHandler on 2026-07-28, a subscriptions/listen stream occasionally starts with notifications/tools/list_changed instead of notifications/subscriptions/acknowledged. The listen only asked for resourcesListChanged, and the notification has no subscriptionId in _meta. The spec says the server MUST NOT send notification types the client didn't request, and the ack has to come first.
It happens when the tool list changes while the listen is being set up. The ephemeral session for a 2026-07-28 request has no protocol version until ServerSession.handle reads it from _meta, and in that window negotiatedLegacyProtocol treats it as legacy. So Server.notifySessions includes it in the legacy broadcast, and the stateless Write puts the notification on the only stream it has, the listen.
I'd expect list-changed notifications to reach a 2026-07-28 session only through a listen that asked for them. I have a fix and a test ready if you want a PR.
Found and written with help from Claude Code.
How to reproduce
The program opens listens that ask only for resource list changes while the tool list keeps changing, and counts the streams that don't start with the ack.
package main
import (
"bufio"
"bytes"
"context"
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
"strings"
"sync"
"sync/atomic"
"time"
"github.com/modelcontextprotocol/go-sdk/mcp"
)
func main() {
server := mcp.NewServer(&mcp.Implementation{Name: "server", Version: "v1"}, nil)
server.AddResource(&mcp.Resource{Name: "r1", URI: "file:///r1"}, nil)
ts := httptest.NewServer(mcp.NewStreamableHTTPHandler(func(*http.Request) *mcp.Server { return server },
&mcp.StreamableHTTPOptions{Stateless: true}))
defer ts.Close()
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()
// Keep the tool list changing.
go func() {
for i := 0; ctx.Err() == nil; i++ {
name := fmt.Sprintf("t%d", i)
server.AddTool(&mcp.Tool{Name: name, InputSchema: map[string]any{"type": "object"}},
func(context.Context, *mcp.CallToolRequest) (*mcp.CallToolResult, error) { return &mcp.CallToolResult{}, nil })
time.Sleep(11 * time.Millisecond)
server.RemoveTools(name)
}
}()
// A listen that asks only for resource list changes.
body, _ := json.Marshal(map[string]any{
"jsonrpc": "2.0",
"id": 1,
"method": "subscriptions/listen",
"params": map[string]any{
"_meta": map[string]any{
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientCapabilities": map[string]any{},
},
"notifications": map[string]any{"resourcesListChanged": true},
},
})
var total, bad atomic.Int64
var example sync.Once
var wg sync.WaitGroup
for range 8 {
wg.Add(1)
go func() {
defer wg.Done()
for ctx.Err() == nil {
reqCtx, reqCancel := context.WithCancel(ctx)
req, _ := http.NewRequestWithContext(reqCtx, http.MethodPost, ts.URL, bytes.NewReader(body))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json, text/event-stream")
req.Header.Set("Mcp-Protocol-Version", "2026-07-28")
req.Header.Set("Mcp-Method", "subscriptions/listen")
resp, err := http.DefaultClient.Do(req)
if err == nil {
total.Add(1)
// Look at the first event of the stream only.
sc := bufio.NewScanner(resp.Body)
for sc.Scan() {
if data, ok := strings.CutPrefix(sc.Text(), "data: "); ok {
if !strings.Contains(data, "notifications/subscriptions/acknowledged") {
bad.Add(1)
example.Do(func() { fmt.Println("first event:", data) })
}
break
}
}
resp.Body.Close()
}
reqCancel()
}
}()
}
wg.Wait()
fmt.Printf("%d of %d listen streams did not start with the acknowledgment\n", bad.Load(), total.Load())
}
Output with v1.9.0-pre.1 (v1.8.0 gives 137 of 9834):
first event: {"jsonrpc":"2.0","method":"notifications/tools/list_changed","params":{}}
86 of 24444 listen streams did not start with the acknowledgment
Where did you hit this?
Found while reading the code; I then reproduced it on a production service that uses the SDK.
Go MCP SDK version
v1.8.0, also v1.9.0-pre.1 and main at 4b1a524
Go version
go1.26.0 darwin/arm64
Logs
No response
- Ngôn ngữ chính
- Go
- Star
- 5.4k
- Fork
- 623
- Merge trung bình
- 22 giờ 10 phút
- Pull request đã merge (30 ngày)
- 30
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
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
modelcontextprotocol/go-sdk#1557 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Streamable HTTP (2026-07-28): tools/call with an out-of-range number in arguments fails because extractName decodes Arguments into anyCó thể làm lại được @beiryu đã nhận 10 ngày trước và không có pull request nào đang mở. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
modelcontextprotocol/go-sdk#1534 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Expose generic `SendNotification` on `ServerSession` for custom protocol extensionsCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đ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
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 18/100
modelcontextprotocol/go-sdk#1555 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
mcp: 2026-07-28 client runs elicitation and sampling handlers for standalone server requestsCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đ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#1552 ·
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ự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
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 76/100
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 86/100
apache/dubbo-admin#1659 ·
Maintainer thường phản hồi trong vòng 8 ngày
-
taskmanager: a failed v1alpha1 backup leaves the partial backup behindCó thể đã có người làm @arshil42 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Packaging: support mise-en-placeĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100