Skip to content

fix: create new MCP transport per request for stateless mode#739

Open
pemagic wants to merge 1 commit intoslopus:mainfrom
pemagic:fix/mcp-stateless-transport-reuse
Open

fix: create new MCP transport per request for stateless mode#739
pemagic wants to merge 1 commit intoslopus:mainfrom
pemagic:fix/mcp-stateless-transport-reuse

Conversation

@pemagic
Copy link

@pemagic pemagic commented Feb 24, 2026

Summary

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 first initialize handshake, 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() inside createServer() handler so each request gets a fresh stateless transport.

Test plan

  • Start Happy CLI, verify MCP server responds to initialize
  • Verify subsequent change_title tool calls succeed (no more HTTP 500)
  • Verify Claude Code no longer shows "Failed to reconnect to happy"

Generated with Claude Code
via Happy

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>
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.

Happy MCP server returns HTTP 500 after initial handshake (MCP SDK >=1.26 compat)

1 participant