mcp: custom methods rejected on a StreamableServerTransport connected with Server.Connect

Đang mở
#1,506 2 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ó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
62/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 the POST pre-check in mcp/streamable.go:1695 and compare how connectStreamable sets c.server and toolLookup with the path used by Server.Connect. The report says custom methods fail on directly connected StreamableServerTransport sessions while standard methods succeed; trace that setup and add a regression test based on the supplied reproduction. Done means the custom method reaches its handler and the request returns HTTP 200.

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 method registered with AddReceivingCustomMethod fails with HTTP 400 (JSON RPC not handled: "acme/search" unsupported) on a StreamableServerTransport connected with Server.Connect and served through its ServeHTTP. Standard methods on the same session succeed, and the custom method works through StreamableHTTPHandler.

The POST pre-check falls back to the standard-only serverMethodInfos when c.server is nil (mcp/streamable.go:1695). c.server is set only in connectStreamable (streamable.go:603), which Server.Connect does not call. This is the Streamable HTTP counterpart of #1291 (fixed for SSE in #1292).

Expected: the custom method reaches its handler. A possible fix is for Server.Connect to set the connection's server (and toolLookup, which has the same gap) as connectStreamable does.

We hit this serving the Skills extension (SEP-2640): skills/list, skills/get and resources/directory/read are custom methods, so they fail this way on a resumed session.

How to reproduce
package repro

import (
        "context"
        "io"
        "net/http"
        "net/http/httptest"
        "strings"
        "testing"

        "github.com/modelcontextprotocol/go-sdk/mcp"
)

type searchParams struct {
        mcp.ParamsBase
        Query string `json:"query"`
}

type searchResult struct {
        mcp.ResultBase
        Hits []string `json:"hits"`
}

func TestCustomMethodOnDirectlyConnectedSession(t *testing.T) {
        s := mcp.NewServer(&mcp.Implementation{Name: "s", Version: "1"}, nil)
        if err := mcp.AddReceivingCustomMethod(s, "acme/search",
                func(context.Context, *mcp.ServerSession, *searchParams) (*searchResult, error) {
                        return &searchResult{Hits: []string{"hit"}}, nil
                }); err != nil {
                t.Fatal(err)
        }

        // Connect a session directly, e.g. to resume one from a shared store.
        tr := &mcp.StreamableServerTransport{SessionID: "s1"}
        state := &mcp.ServerSessionState{
                InitializeParams:  &mcp.InitializeParams{ProtocolVersion: "2025-11-25"},
                InitializedParams: &mcp.InitializedParams{},
        }
        ss, err := s.Connect(context.Background(), tr, &mcp.ServerSessionOptions{State: state})
        if err != nil {
                t.Fatal(err)
        }
        defer ss.Close()
        ts := httptest.NewServer(tr)
        defer ts.Close()

        req, _ := http.NewRequest(http.MethodPost, ts.URL,
                strings.NewReader(`{"jsonrpc":"2.0","id":1,"method":"acme/search","params":{"query":"x"}}`))
        req.Header.Set("Content-Type", "application/json")
        req.Header.Set("Accept", "application/json, text/event-stream")
        req.Header.Set("Mcp-Session-Id", "s1")
        req.Header.Set("Mcp-Protocol-Version", "2025-11-25")
        resp, err := http.DefaultClient.Do(req)
        if err != nil {
                t.Fatal(err)
        }
        defer resp.Body.Close()
        body, _ := io.ReadAll(resp.Body)
        if resp.StatusCode != http.StatusOK {
                t.Fatalf("got HTTP %d: %s", resp.StatusCode, body)
        }
}


Output: `got HTTP 400: JSON RPC not handled: "acme/search" unsupported`. The same request with method `tools/list` returns 200, and calling `acme/search` through `NewStreamableHTTPHandler` with `CallCustomMethod` succeeds.
Paste everything between the outer four-backtick fence, including the inner  fence, so GitHub renders it as code.
Where did you hit this?

ToolHive's multi-replica Virtual MCP Server, which serves MCP through go-sdk and resumes a session on another replica by connecting a StreamableServerTransport with Server.Connect.

Go MCP SDK version

v1.8.0; also reproduced on main at caa354d.

Go version

go version go1.27.1 darwin/arm64

Logs
acme/search: 400 JSON RPC not handled: "acme/search" unsupported
Ngôn ngữ chính
Go
Star
5.3k
Fork
607
Merge trung bình
1 ngày 11 giờ
Pull request đã merge (30 ngày)
82

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.