Skip to content

fix(http-stream): give each session its own SDK server - #199

Open
maksimgm wants to merge 2 commits into
QuantGeekDev:mainfrom
maksimgm:fix/http-stream-session-isolation
Open

maksimgm wants to merge 2 commits into
QuantGeekDev:mainfrom
maksimgm:fix/http-stream-session-isolation

Conversation

@maksimgm

Copy link
Copy Markdown

@QuantGeekDev all http-stream sessions share one SDK server, so request ids from different clients collide. Clients number requests from 0, so when two clients have a request with the same id in flight, one client's response can be delivered to the other.

This gives each session its own SDK server, same as the SSE transport already does. It also makes MCPServer.listRoots() return right away for http-stream instead of waiting out the 60s request timeout, since clients now answer on their own session's server.

Tested with two clients calling a tool at the same time in both stream and batch modes. On main the second client gets the first client's result; with this change each gets its own. Tests are in tests/transports/http/server-session-isolation.test.ts and tests/core/http-stream-session-isolation.test.ts, and the full suite passes.

Follow-ups I'd like to do separately: tool instances are shared, so injectServer() and the progress token can be swapped between overlapping calls (SSE has this too), and sessionTimeout / maxConcurrentSessions aren't enforced yet.

All http-stream sessions shared one SDK Server, so JSON-RPC ids from
different clients collided. When two clients had a request with the same
id in flight, the first response was delivered to both of them.

Use a per-session SDK Server, the same way the SSE transport already does.
…s client

With per-session servers, clients initialize and answer on their own
session's server, so a roots/list sent through the shared server waits for
the full request timeout. Add an MCPServer-level test for both cases.
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