-
Notifications
You must be signed in to change notification settings - Fork 132
mcp: support stateless streamable sessions #277
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
d4960e8
to
4c93089
Compare
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.
I'm confused about why the server is choosing statelessness. I thought there is some mechanism by which the client forces it, for example by sending a tool call without initialization.
mcp/streamable.go
Outdated
@@ -45,6 +45,12 @@ type StreamableHTTPHandler struct { | |||
// StreamableHTTPOptions is a placeholder options struct for future |
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.
no longer just a placeholder
Support stateless streamable sessions by adding a GetSessionID function to StreamableHTTPOptions. If GetSessionID returns "", the session is stateless, and no validation is performed. This is implemented by providing the session a trivial initialization state. To implement this, some parts of modelcontextprotocol#232 (distributed sessions) are copied over, since they add an API for creating an already-initialized session. In total, the following new API is added: - StreamableHTTPOptions.GetSessionID - ServerSessionOptions (a new parameter to Server.Connect) - ServerSessionState - ClientSessionOptions (a new parameter to Client.Connect, for symmetry) For modelcontextprotocol#10 Co-Authored-By: [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.
Minor comment, ca be addressed in a followup.
// GetSessionID provides the next session ID to use for an incoming request. | ||
// | ||
// If GetSessionID returns an empty string, the session is 'stateless', | ||
// meaning it is not persisted and no session validation is performed. |
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.
Describe default.
@findleyr @jba sorry a bit late on this PR, i see that session ID is still getting verified in case header is provided, is it intentional?
Wanted to check with you here before jumping into the issue |
@BC-ACherednichenko but why would the client provide a session ID if the server didn't return one? I guess I'm not understanding the use-case. |
@findleyr it is still related to the #148, since we put on ice the distributed sessions interface we have been wondering if it is possible to solve this problem via stateless mode In particular, if stateless mode could be completely without session validation or etc (sort of you pass the flag, and sdk acts as if sessions did not exist at all), the mcp-session-id emission, management and distributed storage could have been moved to tools middleware layer (upper layer of the server). Currently it reacts right away on the service header |
Support stateless streamable sessions by adding a GetSessionID function to StreamableHTTPOptions. If GetSessionID returns "", the session is stateless, and no validation is performed. This is implemented by providing the session a trivial initialization state.
To implement this, some parts of #232 (distributed sessions) are copied over, since they add an API for creating an already-initialized session.
In total, the following new API is added:
For #10