mcp: support stateless streamable sessions#277
Conversation
d4960e8 to
4c93089
Compare
jba
left a comment
There was a problem hiding this comment.
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 | |||
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]
jba
left a comment
There was a problem hiding this comment.
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. |
|
@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