Skip to content

mcp: accept custom methods over the SSE transport - #1292

Open
fadiroot wants to merge 1 commit into
modelcontextprotocol:mainfrom
fadiroot:sse-custom-methods
Open

fadiroot wants to merge 1 commit into
modelcontextprotocol:mainfrom
fadiroot:sse-custom-methods

Conversation

@fadiroot

Copy link
Copy Markdown

Fixes #1291.

SSEServerTransport.ServeHTTP pre-validates each POSTed request against serverMethodInfos, the static set of standard methods, so a method registered with AddReceivingCustomMethod was rejected with HTTP 400 and "acme/search" unsupported. On the client, sseClientConn.Write turned that into failed to write: 400 Bad Request, which jsonrpc2 treats as a transport write failure, so the whole session broke rather than the one call. The same custom method works over the in-memory, stdio and Streamable HTTP transports; the Streamable handler already consults Server.receivingMethodInfos for this check (#956), but the SSE handler was not updated at the same time.

This gives SSEServerTransport an unexported server field, set by SSEHandler before the transport is registered in its session map, and uses the server's receiving method infos in the check when it is known. A transport constructed directly still falls back to the standard methods, as before. getServer is now called before the transport is built so the field can be set in the struct literal; it is still called once per GET.

TestSSECustomMethod connects a client over SSE, calls a custom method, and pings afterwards to check that the session survived. It fails without the change with failed to write: 400 Bad Request.

SSEServerTransport.ServeHTTP pre-validates each POSTed request against
serverMethodInfos, the static set of standard methods, so a method
registered with AddReceivingCustomMethod was rejected with HTTP 400 and
`"acme/search" unsupported`. On the client, sseClientConn.Write turned
that into `failed to write: 400 Bad Request`, which jsonrpc2 treats as
a transport write failure, so the whole session broke rather than the
one call. The same custom method works over the in-memory, stdio and
Streamable HTTP transports; the Streamable handler already consults
Server.receivingMethodInfos for this check (modelcontextprotocol#956), but the SSE handler
was not updated at the same time.

Give SSEServerTransport an unexported server field, set by SSEHandler
before the transport is registered, and use the server's receiving
method infos in the check when it is known. A transport constructed
directly still falls back to the standard methods, as before.

TestSSECustomMethod connects a client over SSE, calls a custom method,
and pings afterwards to check that the session survived. It fails
without the change with `failed to write: 400 Bad Request`.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants