Production-grade persistence backends for the MCP Python SDK
Project description
mcp-persist
Production-grade persistence backends for the MCP Python SDK.
The MCP SDK ships an EventStore interface but only an in-memory reference implementation. mcp-persist provides backends for real deployments where you need durability across process restarts and multi-worker environments.
Backends
| Backend | Extra | Use case |
|---|---|---|
RedisEventStore |
redis |
Multi-process / multi-worker SSE resumability |
Installation
pip install "mcp-persist[redis]"
Quickstart
import redis.asyncio as aioredis
from mcp_persist import RedisEventStore
from mcp.server.streamable_http_manager import StreamableHTTPSessionManager
redis_client = aioredis.from_url("redis://localhost:6379")
store = RedisEventStore(redis_client, ttl=3600) # 1 hour TTL
session_manager = StreamableHTTPSessionManager(
app=mcp_server,
event_store=store,
)
RedisEventStore
Stores MCP SSE events in Redis so clients can resume interrupted streams — even across worker restarts or load-balanced deployments.
How it works
Redis data layout:
{prefix}counter — atomic INCR source for monotonic event IDs
{prefix}event:{event_id} — HASH: stream_id + serialized payload
{prefix}stream:{stream_id} — ZSET: event IDs sorted by score for O(log N) range queries
- Atomic monotonic IDs via Redis
INCR— collision-free across concurrent workers - O(log N) replay via sorted set
ZRANGEBYSCORE - TTL support — automatic key expiry to prevent unbounded memory growth
- Multi-tenant isolation via configurable
key_prefix - Priming event handling — sentinel empty-string payloads are stored but never replayed to clients
Configuration
RedisEventStore(
redis, # redis.asyncio.Redis instance
key_prefix="mcp:", # isolate multiple servers on one Redis instance
ttl=3600, # seconds; None = never expire (not recommended)
)
TTL guidance: Set ttl to at least 2× your session idle timeout. If you leave it as None, a warning is logged and events accumulate indefinitely.
Multi-tenant deployments
If multiple MCP servers share a Redis instance, use different prefixes:
store_a = RedisEventStore(redis_client, key_prefix="server-a:")
store_b = RedisEventStore(redis_client, key_prefix="server-b:")
Development
git clone https://github.com/Ar-maan05/mcp-persist
cd mcp-persist
pip install -e ".[redis,dev]"
pytest tests/
Tests use fakeredis — no external Redis server required.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mcp_persist-0.1.1.tar.gz.
File metadata
- Download URL: mcp_persist-0.1.1.tar.gz
- Upload date:
- Size: 61.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1976bcfb2d11614dbab3ca1f06adcdb3bbf5759c557a15c03406a875fd8383ac
|
|
| MD5 |
85e3b3ffee39e44f229c7f975c0bc4ce
|
|
| BLAKE2b-256 |
2487e4884fc95f9926f62d61c37a802fad72b00bbfdd4596b5e4b1cd5708c8fd
|
File details
Details for the file mcp_persist-0.1.1-py3-none-any.whl.
File metadata
- Download URL: mcp_persist-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
85d96a1cf17b7c47784e199fb129f71b5394ebd854bf289b1963da867874d92a
|
|
| MD5 |
bfaa83b1c8861de102b5d09efaae7d77
|
|
| BLAKE2b-256 |
d3172b410ca8dd6c33cd88a55657acd824dd3c8a2b5d57b01441caa229b17860
|