Skip to content

fix(cli): close stateless Happy MCP server on response close#830

Open
liunice wants to merge 1 commit intoslopus:mainfrom
liunice:fix/nas-happy-mcp
Open

fix(cli): close stateless Happy MCP server on response close#830
liunice wants to merge 1 commit intoslopus:mainfrom
liunice:fix/nas-happy-mcp

Conversation

@liunice
Copy link

@liunice liunice commented Mar 8, 2026

Summary

Fix the built-in Happy MCP bridge for stateless HTTP mode by aligning its lifecycle with the MCP SDK example:

  • create a fresh StreamableHTTPServerTransport per request
  • create a fresh McpServer per request
  • close both on res.close instead of reusing them across requests

Problem

On Linux/NAS environments, Happy's built-in mcp__happy__change_title tool could fail with errors like:

  • No matching deferred tools found
  • No such tool available: mcp__happy__change_title

The root cause is that the stateless HTTP MCP implementation in startHappyServer was reusing a single StreamableHTTPServerTransport (and connected MCP server state) across multiple HTTP requests.

Why this fix

The MCP SDK's stateless Streamable HTTP example creates a new server/transport for each request and performs cleanup on response close. This PR makes Happy follow the same lifecycle pattern.

Validation

Tested on a Synology NAS / Linux environment where the bug was reproducible:

  • before: mcp__happy__change_title failed reliably
  • after: title updates succeed again
  • takeover UI still works as expected after remote control is attached

Also discussed in #564.

@liunice liunice force-pushed the fix/nas-happy-mcp branch from 9795582 to 2d7329f Compare March 8, 2026 15:20
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