-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Everything server multiple connection support #1884
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
cliffhall
merged 6 commits into
modelcontextprotocol:main
from
cliffhall:everything-server-multiple-connection-support
May 29, 2025
Merged
Everything server multiple connection support #1884
cliffhall
merged 6 commits into
modelcontextprotocol:main
from
cliffhall:everything-server-multiple-connection-support
May 29, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
For both sse and streamableHttp, a server instance needs to be created for each transport. Otherwise, when a new client connects and its new transport is connected to the single server, the previous transport is overwritten in the server instance and can no longer communicate.
* In sse.ts
- remove global server, cleanup, and transport vars
- add transports map
- in sse GET handler,
- check for sessionId, there shouldn't be one, so comment "Reconnecting?" and do nothing if present
- if sessionId not present
- create new server and transport instance
- connect server to transport
- add transport to transports map
- in server.onclose, delete the transport from the transports map and call cleanup
- in /message POST handler
- get the sessionId from the request
- get the transport from the map by sessionId
- handle the message if the transport was found
* In streamableHttp.ts
- remove the global server and cleanup vars
- change transports var to Map
- in /mcp POST handler
- when creating a new session
- create a server instance
- in server.onclose, delete the transport from the transports map and call cleanup
- remove the calls to cleanup and server.close in the SIGINT handler, because the transport is closed and its onclose handler closes the server.
…ple-connection-support
olaservo
reviewed
May 27, 2025
12 tasks
…ive. In the first case (line 16) we already know that req.query.sessionId is set to something. I n the second (line 40), it doesn't matter because if it doesn't map to a transport no further action is taken.
olaservo
reviewed
May 28, 2025
olaservo
previously approved these changes
May 28, 2025
Member
olaservo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had one more logging question/suggestion but otherwise looks good to me.
…sessionId, output a "No transport found for sessionId" message.
olaservo
approved these changes
May 29, 2025
This was referenced May 29, 2025
PazerOP
referenced
this pull request
in PazerOP/mcp-template
Jul 15, 2025
…nnection-support Everything server multiple connection support
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
In sse.ts
In streamableHttp.ts
Server Details
Motivation and Context
Allow multiple connections to the
everythingserver.For both sse and streamableHttp, a server instance needs to be created for each transport. Otherwise, when a new client connects and its new transport is connected to the single server, the previous transport is overwritten in the server instance and can no longer communicate.
How Has This Been Tested?
Using this Inspector PR which fixes the connection behavior of its proxy server.
Here is a video where I demonstrate the problem with the current version of the server, and then with the fixed versions of the SSE and StreamableHttp servers. Manually tested that STDIO works as well.
Breaking Changes
Nope.
Types of changes
Checklist
Additional context