Skip to content

fix(happy-cli): use stateful StreamableHTTPServerTransport to prevent 500 errors#874

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

fix(happy-cli): use stateful StreamableHTTPServerTransport to prevent 500 errors#874
Wshid wants to merge 1 commit intoslopus:mainfrom
Wshid:fix/mcp-server-stateless-transport-reuse

Conversation

@Wshid
Copy link

@Wshid Wshid commented Mar 17, 2026

Summary

The MCP server in startHappyServer.ts uses StreamableHTTPServerTransport with sessionIdGenerator: undefined (stateless mode). Since MCP SDK @modelcontextprotocol/sdk >= 1.27.x, stateless transports throw "Stateless transport cannot be reused across requests" after the first request.

Because startHappyServer creates a single transport and reuses it for all incoming HTTP requests, every request after the initial initialize silently returns HTTP 500. This breaks the change_title MCP tool — Claude Code cannot rename chat sessions.

Fix

Switch from stateless to stateful mode:

```diff

  • sessionIdGenerator: undefined
  • sessionIdGenerator: () => randomUUID()
    ```

randomUUID is already imported from node:crypto in the same file.

How to reproduce

  1. Start a happy session (happy)
  2. Claude Code launches with --mcp-config {"mcpServers":{"happy":{"type":"http","url":"http://127.0.0.1:{port}/"}}}
  3. Try to call mcp__happy__change_title → fails with 500
  4. Directly test: curl -X POST http://127.0.0.1:{port}/ -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"initialize","params":{"protocolVersion":"2025-03-26","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}},"id":1}' → HTTP 500

Tested

  • yarn build
  • yarn typecheck
  • yarn test — 1 pre-existing failure in runAcp.test.ts (unrelated log format mismatch)
  • Manual verification: after patch, new happy sessions can successfully call change_title

… on MCP tool calls

The MCP SDK (>= 1.27.x) enforces that stateless transports
(`sessionIdGenerator: undefined`) cannot be reused across requests,
throwing "Stateless transport cannot be reused across requests".

Since `startHappyServer` creates a single transport and reuses it for
all incoming HTTP requests, every request after the first `initialize`
silently returns HTTP 500, making `change_title` tool calls fail.

Switching to stateful mode (`sessionIdGenerator: () => randomUUID()`)
allows the transport to be safely reused across multiple requests.
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