Fix Not Connected Error in Everything Streamable HTTP Server #1844
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 src/everything/streamableHttp.ts
createServer()to inside the "New initialization request" blockserverCleanupHooksglobal variable so that servers are still cleaned up and closed like beforeServer Details
Motivation and Context
There's a bug with the streamable HTTP version of the "Everything" reference server where the server tries to notify the client before any transport is connected.
This change moves the
createServer()call to when a new session is created so that a transport is immediately connected to the server like in the MCP TypeScript SDK readme.How Has This Been Tested?
The bug can be reproduced by doing this
cd src/everything npm install npm run start:streamableHttpAfter waiting a few seconds
With these changes, I verified that I could initialize multiple sessions and use tools as expected with the TypeScript Client.
Breaking Changes
None.
Types of changes
Checklist
Additional context
It's a bit unexpected how this change cleans up servers via the array
serverCleanupHookswhile transports are cleaned up via thetransportsrecord, but I wasn't sure if there was a good way to map session ID to server + cleanup since the session ID gets created after the transport is is initialized.Some alternatives I thought of
cleanupandserver.closefrom inside of thetransport.oncloselistenersessionIdGeneratorto return a constant so that the server can be aware of the session ID it's handlingI didn't go with those alternatives since the only time transports are closed are on process interrupt and I'm not really sure how all these callbacks are supposed to interact with each other, but it would be nice to know if there's a "right" way to do this.