Keeping MCP server sessions alive after restarts

The MCP Python SDK includes a basic event store for reconnecting after a dropped connection, but it keeps data only in memory. That is fine for development, but a restart, redeploy, or switch to another worker can quietly erase session state. The client may not see a clear error, so work that should continue from the last point can start over.

mcp-persist is built to reduce that problem. It adds SQLite, Redis, and PostgreSQL storage so session information survives outside the running server process and can work across multi-worker deployments. When a client reconnects with Last-Event-ID, it can continue from the point where it stopped.

A proxy mode can also add this behavior in front of MCP servers that cannot be changed directly. In about two weeks since launch, it has passed 8,000 downloads, has one confirmed production use, and has received feedback about TTL edge cases.

Key points

  • The MCP Python SDK’s default event store keeps session data only in memory.
  • mcp-persist stores session state in SQLite, Redis, or PostgreSQL so it can survive restarts.
  • Clients can reconnect with Last-Event-ID and continue from where they stopped.
  • Proxy mode can add resumability without changing the original MCP server.
  • The tool has over 8,000 downloads in about two weeks and one confirmed production deployment.

Quick term guide

PostgreSQL
A database used to store and retrieve app data.
Last-Event-ID
A value that tells the server the last event the client received before reconnecting.
MCP servers
Servers that help an AI tool connect to outside services or company data.
MCP server
A server that helps AI tools connect to outside services in a standard way.
production
The live version of a service that real users use.
reliability
How consistently a tool works without failing or behaving unexpectedly.
tool calls
Times when an AI system uses another function, such as search or file access.
long sessions
Extended AI work sessions where many messages or steps happen over time.
Read original