Skip to content

Proposal: expose ErrSessionMissing #715

@findleyr

Description

@findleyr

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.

CC @dpasiukevich @jba @markus-kusano

Metadata

Metadata

Assignees

Labels

proposalA proposal for an a new API or behavior. See CONTRIBUTING.md.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions