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

Client returns a call's result before handling notifications that preceded it

Đang mở
#1,337 1 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ó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
48/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
go
Lĩnh vực
backend-api-design

Hướng nghiên cứu

Start in internal/jsonrpc2/conn.go, tracing readIncoming, acceptRequest, handlerQueue, and handleAsync to compare response retirement with queued notification handling. Run go test -count=1 -v ./... in the reproduction repository and inspect order_test.go and wire_test.go. Done means notifications received before a response are handled before CallTool returns, or a documented wait mechanism is covered by passing tests.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

P3

Describe the bug

When a server sends notifications during a request and then its response, the go-sdk client can return from CallTool before it has run the handlers for those notifications. Over in-memory transports the wire order is correct and the client reorders delivery; over Streamable HTTP the symptom is the same, but the wire order was not measured.

In internal/jsonrpc2/conn.go, readIncoming retires a *Response immediately, which wakes the Call waiting on it, while an incoming *Request (a notification included) goes through acceptRequest onto handlerQueue and is handled later by handleAsync on another goroutine. Notifications read before a response can therefore be handled after CallTool has returned.

For a plain client this means a ProgressNotificationHandler may still be running for a call that has already returned. LoggingMessageHandler should be affected the same way, since log messages take the same path through jsonrpc2.Connection, but the tests measure progress only.

For anything built on both halves of the SDK -- a gateway or proxy that forwards an upstream's progress to its own caller (the client calling the proxy) -- there is no correct way to forward. The proxy has to stop forwarding a call's progress at some point, and the only moment the SDK gives it is the upstream CallTool returning, when progress the upstream sent before its response may not have been handled yet. If it stops there, that progress is lost. If it keeps forwarding, the progress reaches its caller after the proxy has answered, which 2025-11-25 basic/utilities/progress forbids: "Progress notifications MUST only reference tokens that ... were provided in an active request", and "Progress notifications MUST stop after completion."

Nothing in the API says how many notifications preceded a response, or when they have been handled, so neither a client nor a proxy can wait for them.

To Reproduce

Four tests, each asserting the property that should hold, so a failing run is the reproduction: https://github.com/serverplumber/go-sdk-notify-order/tree/6230dcf2db9d0588ac9252a04d420f4c5f83db3a (order_test.go, wire_test.go; RESULTS.md has the per-run counts). Run go test -count=1 -v ./....

A tool reports progress three times and returns at once. No handler sleeps. The test clients' handlers only count, under a mutex; the proxy's forwards each notification, which is what a proxy is for. Three runs of 1000 calls each, at v1.8.0 and at main (25a53e3), Go 1.26.7 on linux/amd64:

Test v1.8.0 main
In-memory transports: calls whose CallTool returned before all 3 progress handlers ran 69–80 43–58
Streamable HTTP: the same 342–373 374–399
Proxy that stops forwarding when the upstream call returns: progress lost, of 3000 472–488 460–472
Proxy that keeps forwarding: progress its caller read after the response, of 3000 579–591 575–608

The in-memory test also records the order the client's transport delivers messages in: every call's progress arrives before its response, in every run, so the reordering happens after Read, in jsonrpc2.Connection. The last proxy figure is counted at the transport of the proxy's caller for the same reason -- it is what the proxy sent, not the caller's own reordering.

Expected behavior

Handlers for notifications received before a response have run by the time the call that response settles returns -- or, failing that, the client offers a way to wait for them. Either lets a proxy forward progress before its own response.

Possible directions (for discussion, not a patch)

  • Deliver a response through the same ordered path as incoming notifications, so retiring it waits for the handlers queued ahead of it.
  • Or expose a barrier: something the code that called CallTool can wait on that completes when everything read before the response has been handled.

Additional context

Found building an MCP gateway on go-sdk for fault-injection testing. The gateway works around it by counting notifications/progress for a call's token on the HTTP event stream ahead of the response, and waiting until that many are forwarded -- which needs an http.RoundTripper that parses SSE, because the SDK gives no other handle on it. Before the workaround, the gateway's own test saw 1 of 3 progress notifications downstream: the other two were handled after the upstream call returned, by which time the gateway had answered and stopped forwarding for that call.

Ngôn ngữ chính
Go
Star
5.2k
Fork
568
Merge trung bình
1 ngày 15 giờ
Pull request đã merge (30 ngày)
39

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.