Proposal: Provide better error handling for HTTP errors when using a Streamable Client
Maintainer thường phản hồi trong vòng 1 ngày
@chenwei791129 đang làm issue này rồi.
Từ ngày 2/8/2026.
Đá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
- 45/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Ít trao đổi
- Công nghệ
- go
- Lĩnh vực
- api, networking
Hướng nghiên cứu
Bắt đầu từ client.Connect() và StreamableClientTransport, sau đó theo dõi cách lỗi HTTP trong initialize trở thành lỗi phiên hiện đang bị hỏng. Công việc được xem là hoàn tất khi các bên gọi có thể truy cập trạng thái HTTP, các header của phản hồi, nội dung phản hồi và lỗi ban đầu thông qua một lỗi kết nối có cấu trúc, bao gồm cả header WWW-Authenticate được hiển thị trong ví dụ.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Is your feature request related to a problem? Please describe.
When an MCP server responds to an initialize request with an error status (e.g., 401 Unauthorized), the current error handling in client.Connect() only provides the HTTP status code as part of the error message itself.
Important context like response headers (e.g., WWW-Authenticate), response body, and other HTTP metadata are not accessible to the caller.
This makes it difficult to implement proper authentication flows or provide detailed error messages to users, as critical information needed to handle the error appropriately is lost.
Describe the solution you'd like
Expose HTTP response details in connection errors, potentially through:
-
A structured error type that includes:
- HTTP status code
- Response headers
- Response body
- Original error
-
Example API:
type HTTPError struct {
StatusCode int
Headers http.Header
Body []byte
Err error
}
func (e *HTTPError) Error() string { ... }
func (e *HTTPError) Unwrap() error { return e.Err }
This would allow clients to handle authentication challenges and other HTTP-level errors appropriately:
session, err := client.Connect(ctx, transport, nil)
if err != nil {
var httpErr *mcp.HTTPError
if errors.As(err, &httpErr) {
if httpErr.StatusCode == 401 {
// Access WWW-Authenticate header
authHeader := httpErr.Headers.Get("WWW-Authenticate")
// Handle authentication flow
}
}
}
Describe alternatives you've considered
Wrapping the HTTP client in Transport options:
While this works, it adds significant complexity:
- Requires manual synchronization (mutexes) to safely capture response data when the session is used concurrently
- Couples transport-level concerns with business logic
- Makes the code harder to maintain and test
Additional context
Minimal reproduction example:
package main
import (
"context"
"log"
"net/http"
"github.com/modelcontextprotocol/go-sdk/mcp"
)
func main() {
go runServer("localhost:8000")
runClient("http://localhost:8000")
}
func runServer(url string) {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`)
w.WriteHeader(http.StatusUnauthorized)
})
log.Printf("[Server] MCP server listening on %s", url)
if err := http.ListenAndServe(url, handler); err != nil {
log.Fatalf("[Server] Server failed: %v", err)
}
}
func runClient(url string) {
ctx := context.Background()
log.Printf("[Client] Connecting to MCP server at %s", url)
client := mcp.NewClient(&mcp.Implementation{}, nil)
session, err := client.Connect(ctx, &mcp.StreamableClientTransport{Endpoint: url}, nil)
if err != nil {
// Currently: no access to WWW-Authenticate header or response body
log.Fatalf("[Client] Failed to connect: %v (type: %T)", err, err)
}
defer session.Close()
log.Println("[Client] Session acquired successfully")
}
Output:
2025/10/14 16:41:25 [Client] Connecting to MCP server at http://localhost:8000
2025/10/14 16:41:25 [Server] MCP server listening on localhost:8000
2025/10/14 16:41:25 [Client] Failed to connect: calling "initialize": broken session: 401 Unauthorized (type: *fmt.wrapError)
exit status 1
- 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