bug: a request sent before initialize is answered with JSON-RPC error code 0 instead of -32600

Đã đóng Phù hợp với người mới
#1,367 4 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ó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
82/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

Hướng nghiên cứu

Bắt đầu với chương trình tối giản trong issue: chạy một server trên IOTransport, gửi tools/list trước initialize và xác nhận phản hồi có code: 0. Tìm nơi lỗi 'invalid during session initialization' được tạo ra và kiểm tra mã nó đặt. Hoàn thành khi đường đi này trả về -32600 và nội dung thông báo không thay đổi, kèm một test khẳng định mã đó.

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

Mô tả

Summary

A request sent before initialize is answered with a JSON-RPC error whose code is 0. 0 is not a JSON-RPC 2.0 error code; the spec requires -32600 (Invalid Request) for a request that cannot be served.

Version

github.com/modelcontextprotocol/go-sdk v1.8.0 (also observed on main).

Reproduction

Run a server over a raw stdio transport (IOTransport) and, before sending initialize, send:

{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}

Observed response:

{"jsonrpc":"2.0","id":1,"error":{"code":0,"message":"method \"tools/list\" is invalid during session initialization"}}

Expected response (JSON-RPC 2.0):

{"jsonrpc":"2.0","id":1,"error":{"code":-32600,"message":"method \"tools/list\" is invalid during session initialization"}}

The message text is correct; only the code is wrong.

Minimal program

srv := mcp.NewServer(&mcp.Implementation{Name: "t", Version: "0"}, nil)
c2s, serverIn := io.Pipe()
serverOut, cFromS := io.Pipe()
go func() { _ = srv.Run(ctx, &mcp.IOTransport{Reader: c2s, Writer: cFromS}) }()
fmt.Fprintln(serverIn, `{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}`)
// read the first line of serverOut

Notes

  • ping is correctly allowed before initialize.
  • 0 is especially awkward for clients: it is indistinguishable from "no code set" and is not one of the standard codes (-32700, -32600, -32601, -32602, -32603).

Impact

Consumers must wrap the transport to rewrite code: 0 to -32600 before forwarding to clients. We do exactly that in ai-rulez (internal/mcp GuardLifecycle) and would like to delete the workaround once the SDK answers with -32600 itself.

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

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.