fix: create new MCP transport per request for stateless mode#739
Open
pemagic wants to merge 1 commit intoslopus:mainfrom
Open
fix: create new MCP transport per request for stateless mode#739pemagic wants to merge 1 commit intoslopus:mainfrom
pemagic wants to merge 1 commit intoslopus:mainfrom
Conversation
MCP SDK >=1.26 added a guard that stateless transports (sessionIdGenerator: undefined) cannot be reused across requests. The previous code created a single transport at startup and reused it for all HTTP requests, causing every request after the initial `initialize` handshake to throw with HTTP 500. Move transport creation inside the HTTP request handler so each request gets a fresh transport, which is the SDK's recommended pattern for stateless mode. Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
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
StreamableHTTPServerTransportcreation inside the HTTP request handler (one transport per request)Problem
MCP SDK 1.26.0 added a check that prevents stateless transports (
sessionIdGenerator: undefined) from being reused across requests. The previous code created one transport at startup and shared it across all requests, so after the firstinitializehandshake, every subsequent request threw → HTTP 500 → "Failed to reconnect to happy" in Claude Code.Changes
packages/happy-cli/src/claude/utils/startHappyServer.ts: Move transport +mcp.connect()insidecreateServer()handler so each request gets a fresh stateless transport.Test plan
initializechange_titletool calls succeed (no more HTTP 500)Generated with Claude Code
via Happy