fix(private-server): run the MCP endpoint statelessly#275
Merged
Conversation
Claude Code (and any client) connected, then got 'Not Found: Session not found' on the request after initialize. rmcp's default stateful mode keeps sessions in process memory; behind the multi-replica deployment a follow-up request routed to a different pod than the one that ran initialize, so the session was unknown and rmcp 404'd. Clients surface that as a dropped connection / 'tools fetch failed'. This is a read-only request/response API with no server-initiated push, so disable sessions (stateful_mode=false) and return plain application/json (json_response=true). Each POST is then self-contained and any replica can serve it; there's also no long-lived SSE stream for the ingress to drop. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
🤖 Follow-up to #273 and #274. With Host and OAuth-discovery sorted, clients connect but then fail with
Not Found: Session not foundimmediately afterinitialize— surfaced as "connected · tools fetch failed" / "Connection closed".Cause
rmcp's default stateful mode keeps each MCP session in the handling process's memory and returns 404 for any later request whose
Mcp-Session-Idit doesn't recognise. Behind the multi-replica deployment, the request afterinitializeis load-balanced to a different pod, which never saw that session → 404. Confirmed from Claude Code's MCP log:(A single
curlreusing one HTTP/2 connection lands on one pod, so it worked — which is why this only showed up with a real client opening multiple connections.)Fix
This is a read-only request/response API with no server-initiated push, so disable sessions:
stateful_mode = false— each POST is self-contained; any replica can serve any request, no session affinity needed.json_response = true— return plainapplication/jsonper request, so there's no long-lived SSE stream for the ingress to buffer or drop either.Tests updated for the stateless transport, plus a regression test that a
tools/callsucceeds with no priorinitializeand no session id.