Skip to content

Fix "Missing session ID" by making the MCP transport stateless - #161

Merged
brianglass merged 1 commit into
mainfrom
fix-mcp-stateless-session
Aug 4, 2026
Merged

Fix "Missing session ID" by making the MCP transport stateless#161
brianglass merged 1 commit into
mainfrom
fix-mcp-stateless-session

Conversation

@brianglass

Copy link
Copy Markdown
Owner

Summary

  • After the 421 fix (Fix production 421 "Invalid Host header" on /mcp #160) deployed, /mcp started returning "Bad Request: Missing session ID."
  • Cloud Run logs showed several separate container instances each starting their own independent StreamableHTTP session manager in short succession -- confirms the SDK's default session manager tracks each session's transport in that process's own memory, but this service scales to multiple instances (maxScale=15, no session affinity configured), with no guarantee a session's follow-up request lands back on the instance that created it.
  • Both tools (get_day, search_saints) are stateless reads with no need for server-side session state in the first place, so stateless_http=True is the correct fix rather than trying to force session affinity: it makes every request self-contained instead.

Test plan

  • docker compose run --rm tests — 135/135 passing
  • Verified locally: tools/call with no prior initialize on the connection and no session ID at all now succeeds (200 OK, correct data) -- confirms statelessness, not just that the old flow still happens to work

🤖 Generated with Claude Code

https://claude.ai/code/session_01Hf6j2xXQXywHVh3HAVRxB3

Cloud Run logs (after the 421 fix deployed) showed several container
instances each starting their own independent StreamableHTTP session
manager -- confirms the default session manager's in-memory,
per-instance session tracking doesn't survive a follow-up request
landing on a different instance than the one that created the
session (maxScale=15, no session affinity configured).

Both tools (get_day, search_saints) are stateless reads with no need
for server-side session state in the first place, so
stateless_http=True is the correct fix rather than trying to force
session affinity: it makes every request self-contained instead.

Verified locally: a tools/call with no prior initialize on the
connection and no session ID at all now succeeds.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hf6j2xXQXywHVh3HAVRxB3
@brianglass
brianglass merged commit 6992a1d into main Aug 4, 2026
4 checks passed
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.

1 participant