Skip to content

fix(http): create a server instance per request in stateless HTTP mode - #121

Merged
rbuchmayer-pplx merged 1 commit into
perplexityai:mainfrom
rbuchmayer-pplx:fix-http-stateless-transport
Jul 27, 2026
Merged

fix(http): create a server instance per request in stateless HTTP mode#121
rbuchmayer-pplx merged 1 commit into
perplexityai:mainfrom
rbuchmayer-pplx:fix-http-stateless-transport

Conversation

@rbuchmayer-pplx

@rbuchmayer-pplx rbuchmayer-pplx commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Stateless HTTP mode reuses one McpServer across requests, but a Protocol instance only supports one transport, so the second POST in any session 500s with "Already connected to a transport". MCP init is itself a POST, so every HTTP client breaks on its first real request (npm run start:http and Docker HTTP mode).

  • Build a fresh server + transport pair per request (the SDK's stateless pattern) and close both when the response closes
  • Reproduced on main with the lockfile SDK (1.27.1) using the official streamable HTTP client
  • Adds a regression test (two sequential POSTs against one app instance) and a /health test

Fixes #117.

@rbuchmayer-pplx
rbuchmayer-pplx force-pushed the fix-http-stateless-transport branch 2 times, most recently from cae26b3 to 81557ad Compare July 23, 2026 04:32
@rbuchmayer-pplx
rbuchmayer-pplx marked this pull request as ready for review July 23, 2026 19:31
The stateless streamable HTTP path reused a single McpServer across
requests, but a Protocol instance only supports one transport. The second
POST in any session failed with "Already connected to a transport"
(HTTP 500), which breaks initialize -> tools/list for every client.

Follow the SDK's stateless pattern: build a fresh server + transport pair
per request and close both when the response closes.
@rbuchmayer-pplx
rbuchmayer-pplx force-pushed the fix-http-stateless-transport branch from 81557ad to 9ca242e Compare July 27, 2026 16:12
@rbuchmayer-pplx
rbuchmayer-pplx merged commit 29e6ab5 into perplexityai:main Jul 27, 2026
1 check 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.

Stateless HTTP mode reuses one MCP server across requests -> "Already connected to a transport" (breaks multi-request clients)

2 participants