Reject standalone GET in stateless streamable HTTP mode#1884
Open
vrv wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
Reject standalone GET in stateless streamable HTTP mode#1884vrv wants to merge 1 commit intomodelcontextprotocol:mainfrom
vrv wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
|
@modelcontextprotocol/client
@modelcontextprotocol/server
@modelcontextprotocol/express
@modelcontextprotocol/fastify
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Reject standalone
GET /mcpin statelessWebStandardStreamableHTTPServerTransportmode by returning405 Method Not AllowedwithAllow: POST.Motivation and Context
In stateless mode (
sessionIdGenerator === undefined), the transport requires a fresh transport instance per HTTP request. However,handleGetRequest()still permits creation of a standalone SSE stream (_GET_stream), which is transport-local state with no durable owner across requests.This change aligns the implementation with the SDK’s own examples:
simpleStatelessStreamableHttp.tsrejectsGET /mcpwith405jsonResponseStreamableHttp.tsalso rejectsGET /mcpwith405How Has This Been Tested?
Tested in a real application using
@modelcontextprotocol/sdk1.29.0in stateless mode.Scenarios tested:
sessionIdGenerator: undefinedGET /mcpstreams accumulatedGET /mcpis rejected with405Breaking Changes
Potentially, yes for stateless servers that currently rely on standalone
GET /mcpfor out-of-band server-to-client notifications while a request is in flight.This change makes stateless mode effectively POST-only for Streamable HTTP. Stateful servers are unchanged.
I'm not entirely sure whether this aligns with the stateless transport goals going forward, but offering this change in case this is actually a bug; can add tests for this if someone thinks this is the right fix.
Types of changes
Checklist