Skip to content

fix(mcp): create an MCP server per HTTP request - #104

Open
asasemahmed wants to merge 1 commit into
CopilotKit:mainfrom
asasemahmed:fix/mcp-http-per-request-server
Open

asasemahmed wants to merge 1 commit into
CopilotKit:mainfrom
asasemahmed:fix/mcp-http-per-request-server

Conversation

@asasemahmed

Copy link
Copy Markdown

The HTTP entry point creates one McpServer at module load and calls server.connect() with a new transport on every request. connect() replaces the server's current transport. So when two requests overlap, a response can be written to the other request's transport, and the first caller never gets an answer.

Repro: send a tools/call whose body arrives slowly. While it is still arriving, send a second request. The second request gets 200, and the first one hangs.

The transport is created without a sessionIdGenerator, so the server already runs in stateless mode: no mcp-session-id is ever returned, and the sessions map is never filled. This change follows the SDK's stateless pattern of a new server and transport per request, and removes the unused map.

To make the route testable, the Hono app moved into src/app.ts (createApp()). src/index.ts now only reads the env vars and starts the server.

Tests: tests/app.test.ts stalls request 1's body, completes request 2, then releases request 1 and asserts that each gets its own result. On main, request 1 never answers.

This branch has not been deployed

No deployments
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