Skip to content

mcp: custom methods registered with AddReceivingCustomMethod are rejected over the SSE transport #1291

Closed

Description

@fadiroot

Describe the bug

A method registered with AddReceivingCustomMethod works over the in-memory, stdio and Streamable HTTP transports, but over the (deprecated) HTTP+SSE transport the POST is rejected with HTTP 400 and the whole client session breaks.

SSEServerTransport.ServeHTTP pre-validates each POSTed request with checkRequest(req, serverMethodInfos) (mcp/sse.go). serverMethodInfos is the static set of standard methods, so a custom method name fails with "acme/search" unsupported and the handler answers 400. The Streamable HTTP handler does the same pre-check but was updated in #956 to use Server.receivingMethodInfos(), which includes custom methods; the SSE handler was not.

On the client side, sseClientConn.Write returns failed to write: 400 Bad Request for the POST. jsonrpc2 treats that as a transport write failure, so not only the custom call fails: later calls on the same session fail too.

To Reproduce

Take the existing TestCustomMethods setup (server with AddReceivingCustomMethod(s, "acme/search", ...), client with AddSendingCustomMethod) and connect through SSE instead of NewInMemoryTransports:

sseHandler := NewSSEHandler(func(*http.Request) *Server { return s }, nil)
httpServer := httptest.NewServer(sseHandler)
cs, _ := c.Connect(ctx, &SSEClientTransport{Endpoint: httpServer.URL}, nil)
_, err := CallCustomMethod[*searchParams, *searchResult](ctx, cs, "acme/search", &searchParams{Query: "x"})
// err: calling "acme/search": failed to write: 400 Bad Request

Expected behavior

The custom method is dispatched to the registered handler over SSE, the same as over the other transports, and the session stays usable.

Fix

Give SSEServerTransport access to the server it is connected to (set by SSEHandler before the transport is registered) and use server.receivingMethodInfos() in the pre-check when it is known, falling back to serverMethodInfos for a transport constructed directly. I have a PR with this change and a regression test (TestSSECustomMethod).

Activity

  1. added a commit that references this issue on Sep 29, 2026
    591c5fd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Nice to haves, rare edge cases

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions