Fix Not Connected Error in Everything Streamable HTTP Server#1844
Conversation
|
Thanks for the PR! I was just looking at @cliffhall 's everything server PR here: #1884 I think there might be some overlap with the types of issues we are dealing with here, especially if we want to use the cleanup approach here which I don't think is covered in the other PR. I tagged Cliff on this one to take a look at it. |
Thanks for tagging this, @olaservo and for noticing the problem @charlotte-zhuang. All of this is covered by #1884
|
|
Just a note that we should close this one if/when #1884 is merged. |
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.