mcp: typed tool handlers lose wrapped JSON-RPC errors
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
- #1528 của @ktsoator — đã đóng, không merge
Đá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
- 85/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
Bắt đầu với toolForErr trong gói MCP và phần xử lý lỗi JSON-RPC mà ClientSession.CallTool sử dụng; so sánh cách xử lý trực tiếp *jsonrpc.Error với các lỗi được bọc. Chạy bản tái hiện client/server trong bộ nhớ đã được cung cấp, sau đó xác minh rằng errors.As giữ nguyên mã, thông điệp và dữ liệu JSON-RPC, và kết quả không bị đánh dấu sai thành lỗi thực thi. Thêm hoặc cập nhật các kiểm thử tập trung cho lỗi giao thức được bọc và không được bọc.
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?
A typed tool handler returning a wrapped *jsonrpc.Error is treated as a tool execution error. ClientSession.CallTool returns a nil Go error and a result with IsError: true, so the JSON-RPC error code and data are lost. Returning the same protocol error directly works.
toolForErr checks err.(*jsonrpc.Error) instead of searching the error chain. The expected result is a JSON-RPC error with the underlying code, message, and data preserved when wrapped with %w.
How to reproduce
Run this program with github.com/modelcontextprotocol/go-sdk v1.8.0:
package main
import (
"context"
"errors"
"fmt"
"github.com/modelcontextprotocol/go-sdk/jsonrpc"
"github.com/modelcontextprotocol/go-sdk/mcp"
)
func main() {
ctx := context.Background()
s := mcp.NewServer(&mcp.Implementation{Name: "server", Version: "1"}, nil)
mcp.AddTool(s, &mcp.Tool{Name: "demo"}, func(context.Context, *mcp.CallToolRequest, map[string]any) (*mcp.CallToolResult, any, error) {
return nil, nil, fmt.Errorf("backend: %w", &jsonrpc.Error{
Code: jsonrpc.CodeInvalidParams,
Message: "bad input",
})
})
st, ct := mcp.NewInMemoryTransports()
ss, err := s.Connect(ctx, st, nil)
if err != nil {
panic(err)
}
defer ss.Close()
c := mcp.NewClient(&mcp.Implementation{Name: "client", Version: "1"}, nil)
cs, err := c.Connect(ctx, ct, nil)
if err != nil {
panic(err)
}
defer cs.Close()
result, err := cs.CallTool(ctx, &mcp.CallToolParams{Name: "demo"})
var rpcErr *jsonrpc.Error
fmt.Printf("protocolError=%v, err=%v\n", errors.As(err, &rpcErr), err)
if result != nil {
fmt.Printf("isError=%v\n", result.IsError)
}
}
Observed:
protocolError=false, err=<nil>
isError=true
Expected: protocolError=true, with JSON-RPC code -32602.
Where did you hit this?
Found during local code inspection and reproduced with an in-memory client and server.
Go MCP SDK version
v1.8.0
Go version
go1.26.10 darwin/arm64, also reproduced on main at 0fa5e8407aa3fda65166e4207156c03d084bfd44.
Proposed fix
Use errors.As and return the underlying protocol error.
- Ngôn ngữ chính
- Go
- Star
- 5.3k
- Fork
- 614
- Merge trung bình
- 23 giờ 55 phút
- Pull request đã merge (30 ngày)
- 62
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
-
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
-
mcp: ClientSession.ReadResource keeps uncacheable and expired results until the session endsCó 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 74/100
modelcontextprotocol/go-sdk#1526 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
mcp: streamable client keeps the session ID from a rejected server/discover, so the fallback initialize failsCó thể đã có người làm @simon0191 đã nhận 1 ngày trước. Đang mở
modelcontextprotocol/go-sdk#1522 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
auth: OAuth client rejects protected resource metadata when the MCP server URL has a query stringCó thể đã có người làm @beiryu đã nhận 2 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 74/100
modelcontextprotocol/go-sdk#1519 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`ping` and `logging/setLevel` still sent for protocol 2026-07-28Có thể đã có người làm @nahapetyan-serob đã nhận 1 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 65/100
modelcontextprotocol/go-sdk#1518 · 1 bình luận · 1 người được giao ·
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 62/100
-
evener-transcript-v2-upgrade tool still scans transcript files through bufio's 4 KiB default bufferĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 78/100
prime-radiant-inc/evener#6370 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
ManageSieve proxy: a backend's NO/BYE greeting is skipped as a capability line and reported as EOFĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Mend: dependency security vulnerability
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
-
Mend: dependency security vulnerability
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
ManageIQ/manageiq-pods#1476 ·
Maintainer thường phản hồi trong vòng 1 ngày