mcp: a handler error without a code reaches the peer as JSON-RPC error code 0
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
- 35/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
- backend-api-design
Hướng nghiên cứu
Start with internal/jsonrpc2/messages.go and toWireError, then read #1367 and #1393 for the related behavior. Compare the proposed default in toWireError with handling errors at MCP call sites, including the duplicate initialize case. Done means uncoded handler errors reach peers as -32603, duplicate initialize as -32600, existing coded errors retain their codes, and the agreed MCPGODEBUG option and 1.9.0 documentation are addressed.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
What happens
When a handler returns an ordinary Go error, the peer receives it with "code": 0. Measured on main at b5d319b:
| side | where the plain error comes from | response |
|---|---|---|
| server | prompts/get handler |
{"code":0,"message":"prompt boom"} |
| server | resources/read handler (resource) |
{"code":0,"message":"resource boom"} |
| server | resources/read handler (template) |
{"code":0,"message":"template boom"} |
| server | tools/call, raw ToolHandler from Server.AddTool |
{"code":0,"message":"raw boom"} |
| server | CompletionHandler |
{"code":0,"message":"complete boom"} |
| server | SubscribeHandler / UnsubscribeHandler |
{"code":0,"message":"subscribe boom"} |
| server | receiving middleware | {"code":0,"message":"middleware boom"} |
| server | handler added with AddReceivingCustomMethod |
{"code":0,"message":"custom boom"} |
| server | second initialize on a legacy session (SDK's own error) |
{"code":0,"message":"duplicate \"initialize\" received"} |
| client | CreateMessageHandler |
{"code":0,"message":"sampling boom"} |
| client | ElicitationHandler |
{"code":0,"message":"elicit boom"} |
| client | receiving middleware | {"code":0,"message":"client middleware boom"} |
The server rows give the same answer over IOTransport on 2025-11-25, over IOTransport on 2026-07-28, and over stateless Streamable HTTP on 2026-07-28 (subscribe/unsubscribe and the second initialize on 2025-11-25 only). The client rows were run on 2025-11-25 over IOTransport. context.DeadlineExceeded returned from a handler is answered the same way.
Not affected:
- A handler that returns a
*jsonrpc.Error, or an error wrapping one, keeps its code. ResourceNotFoundErroris answered with-32602.- A typed
ToolHandlerFor: its error becomes anisErrorresult.
Why
Same cause as #1367. toWireError in internal/jsonrpc2/messages.go copies a code only from an error that is or wraps a WireError, so a plain error keeps the zero value. #1393 fixed the one site that issue was about.
What the specification says
- Prompts, Error Handling (2025-11-25 and 2026-07-28): "Internal errors:
-32603(Internal error)". - Resources, 2026-07-28: "Servers SHOULD return
-32603for internal errors." 2025-11-25 lists "Internal errors:-32603". - Tools, Error Handling: protocol errors are "standard JSON-RPC errors for issues like … Server errors".
For comparison, the TypeScript SDK (1.32.1, shared/protocol.js) answers with -32603 when a handler throws an error that has no integer code.
Proposal
Answer with -32603 (jsonrpc.CodeInternalError) when an error that carries no code is about to be sent, keeping the message as it is. For the duplicate initialize, -32600, matching #1393.
Two ways to do it, and I would like your preference before writing the patch:
- In
toWireError: default to-32603whenever no code is set. One change, covers every row above and future sites, but changes every such answer at once. - At the call sites in
mcponly. Leaves the jsonrpc2 default alone, but it is a dozen sites today and each new handler type needs the same care.
Given how many sites there are, I lean towards 1. Either way gated behind an MCPGODEBUG option and documented under 1.9.0, as in #1393. I can send the PR for whichever you choose.
The only test I found that expects 0 is internal/jsonrpc2/wire_test.go, which builds the error with code 0 explicitly, so it would not change.
AI disclosure: investigated and drafted with Claude Code; I reproduced and reviewed it.
- Ngôn ngữ chính
- Go
- Star
- 5.2k
- Fork
- 583
- Merge trung bình
- 1 ngày 13 giờ
- Pull request đã merge (30 ngày)
- 53
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 76/100
modelcontextprotocol/go-sdk#1372 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Session-lifecycle bookkeeping logs at info, spamming multiple log lines per request on stateless streamable HTTPCó thể đã có người làm @anneheartrecord đã nhận 48 ngày trước. Đang mởP3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
modelcontextprotocol/go-sdk#1204 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Expose generic `SendNotification` on `ServerSession` for custom protocol extensionsCó thể đã có người làm @ajuijas đã nhận 214 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: rejected request IDs receive no JSON-RPC error envelopeCó thể đã có người làm @skosovsky đã nhận 2 ngày trước. Đang mở
Độ khó 4/5 1-2 ngày Mức phù hợp với người mới 68/100
modelcontextprotocol/go-sdk#1391 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
jsonrpc: numeric request IDs above 2^53 lose precisionCó thể đã có người làm @skosovsky đã nhận 3 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
modelcontextprotocol/go-sdk#1376 ·
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ự
-
docs: clarify gh api -f vs -F and @-file expansion in the gh skillCó thể đã có người làm @MatiasOlivera đã nhận hôm nay. Đang mởenhancement
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
aws/aws-advanced-go-wrapper#612 ·
-
Say in the changelog that the text-index update cannot be rolled backCó thể đã có người làm @praetorianer777 đã nhận hôm nay. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
praetorianer777/GoTome#275 ·
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 62/100
SAP/crossplane-provider-btp#1118 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
benchmark: `make setup` fails because audit-exporter builds with Go 1.25.0 while go.mod requires 1.26.0Có thể đã có người làm @xsvm đã nhận hôm nay. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 84/100
volcano-sh/volcano#6097 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày