You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support serializable session state for distributed deployments #2111
BaseSession holds all session state in-memory (_response_streams, _in_flight, _request_id counter, _server_capabilities). This state cannot be serialized or shared across process boundaries, making it difficult to run MCP services behind a load balancer or in horizontally-scaled deployments.
Motivation
Horizontally-scaled MCP services need to share session state across instances
When a response arrives at a different instance than the one that sent the request, there is no way to route it correctly without reimplementing session internals
As the protocol transitions from stateful (current spec) to stateless-by-default (upcoming spec), servers will need to support both old and new clients simultaneously. Serializable session state would help bridge this transition period, allowing stateful sessions to be managed across a distributed backend while also serving stateless clients.
Proposed Approach
Provide a lightweight SessionState snapshot with the minimal serializable fields needed to reconstruct session context:
session_id
protocol_version
next_request_id
server_capabilities
server_info
initialized_sent
Expose get_session_state() and from_session_state() methods on ClientSession, allowing consumers to store and restore state using whatever backing store they choose (Redis, database, etc.).
Activity
feat: add SessionState model for serializable session state
feat: add get_session_state() method to ClientSession
feat: add from_session_state() classmethod to ClientSession
test: add integration test for session state round-trip
feat: export SessionState from public API
test: add coverage for None branches in from_session_state
maxisbey commentedon Aug 10, 2026
v2 went a different direction here, so this no longer applies as written — closing. Feel free to reopen if there's something still outstanding.