-
Notifications
You must be signed in to change notification settings - Fork 772
StreamableHTTPServerTransport should only check init status when sessionId existing #335
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
Conversation
…e is an sessionId When using stateless mode, the backend will create a new transport for each request. For new transport, the initialized filed is always false. So we should only check the initialized filed if there is session existing
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.
A more understandable alternative would be:
- Remove this change
- Move the subsequent conditional at lines 478..482 up before this condition.
This would handle the stateless condition out of the gate, and the reader would automatically understand that the rest of the method is dealing with stateful sessions.
Co-authored-by: Cliff Hall <[email protected]>
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.
Yes, I agree with the change. Thank you for point it out!
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.
@qikaigao You still need to remove lines 483...487.

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.
remove the undefined check at line 478 to 483
Sorry, I am new to PR. I just made the update |
Hey @ihrpr. Have a look at this implementation. The PR you pointed to does make the change that @qikaigao was initially making, but in the end, it was refactored to a more understandable reordering of the conditionals. It moves the check for stateless to the top of the function as an early return. The reader can then assume the rest of the logic is for a stateful connection. I would lobby for keeping @qikaigao's implementation. |
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.
Looks good, thank you! Would be good to add tests for this, but we can merge as is.
@qikaigao please can you update |
yeah, the current implementation actually solves a different problem. In multi-node deployment, not all servers will be initialized. A client can send an initialization request and verify capabilities on one node, but then start sending requests to a node that was not initialized. PR that I mentioned solves the problem when multiple clients connect to a node. |
@ihrpr I wasn't suggesting this as an alternate to the other PR; this part was only a slice of that other one's work. I only meant that this section, the reordering of these two conditionals vs making one more complex and leaving the early return needlessly further down in the method, might be a good way for those particular lines to end up. For readability. |
@@ -463,6 +463,11 @@ export class StreamableHTTPServerTransport implements Transport { | |||
* Returns true if the session is valid, false otherwise | |||
*/ | |||
private validateSession(req: IncomingMessage, res: ServerResponse): boolean { | |||
if (this.sessionId === undefined) { |
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.
realised it should sessionIdGenerator
not session id. Merged this commit and applied the change in #377
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.
Nice one. If the generator is there, then definitely this is intended to be stateful, whereas lack of sessionId only infers such.
Closing. Fixed in #377 |
Motivation and Context
When using stateless mode, the backend will create a new transport for each request. For new transport, the initialized filed is always false. So we should only check the initialized filed if there is session existing
How Has This Been Tested?
Tested in local MCP Server. At backend, I create a new transport object and meet the issue. the PR fixed it.
Breaking Changes
No
Types of changes
Checklist
Additional context