-
Notifications
You must be signed in to change notification settings - Fork 302
Description
The MCP spec states that the streamable server may terminate the session at any time, and when the client encounters a 404 it should initialize a new session:
https://modelcontextprotocol.io/specification/2025-11-25/basic/transports#session-management
The SDK doesn't currently expose an easy way to achieve this: for consistency with other transports, we do not transparently reinitialize the session for the user: a ClientSession corresponds to a logical session on the server, and if it is broken a new ClientSession must be created.
However, there's no easy way to detect if the session is broken, because our internal sentinel error value for this is not exported.
I propose that we export ErrSessionMissing, a sentinel error value that is wrapped by Write errors from the streamableClientConn when an HTTP request returns NotFound.
An alternative would be to expose the HTTP errors directly (see also #579), but that is a rather large API surface, and tightly couples the client logic to the transport. I would prefer to just expose this one error value. We can add more as needed.