Repository navigation
mcp: reuse server selection for new streamable requests - #1414
Merged
guglielmo-san merged 3 commits intoOct 20, 2026
Merged
guglielmo-san merged 3 commits into
guglielmo-san merged 3 commits into
Conversation
Reuse the server selected for protocol-version validation when creating a new stateful or stateless session. This prevents duplicate getServer callback invocations for a single POST. Fixes modelcontextprotocol#1413 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment on lines
414
to
422
| @@ -419,12 +421,11 @@ func (h *StreamableHTTPHandler) ServeHTTP(w http.ResponseWriter, req *http.Reque | |||
| http.Error(w, fmt.Sprintf("Bad Request: Unsupported protocol version (supported versions: %s)", strings.Join(supportedVersions, ",")), http.StatusBadRequest) | |||
| return | |||
Contributor
There was a problem hiding this comment.
this check can be moved to a helper function, and avoid passing server to serveStateless and serveStateful
Instead we could call h.getServer directly from serveStatefulPOST and serveStateless, in case of stateful request, the server can be retrieved from sessInfo in
sessInfo, ok := h.lookupSession(w, req, sessionID)
What do you thihk?
Contributor
Author
There was a problem hiding this comment.
Thanks, this is a good suggestion. I moved protocol-version validation into a helper, resolve the server in the stateless/new-stateful POST paths, and use the server on the existing session for subsequent stateful requests.
Validate protocol versions using the server selected for new POSTs, or the server associated with an existing session. Avoid invoking getServer for requests routed to established sessions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
guglielmo-san
approved these changes
Oct 20, 2026
Contributor
|
@Adebayo120 thank you for the contribution! |
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.
Reuse the server selected for protocol-version validation when creating a new stateful or stateless session. This prevents duplicate
getServercallback invocations for a single POST.Regression coverage verifies one callback invocation in both modes, while preserving request-body handling.
Fixes #1413
Validation:
go test ./...— passed.git diff --check— passed.