ioredis under the hood and stores each session as a JSON-serialised hash with a configurable TTL.
Install the peer dependency
Configure environment variables
Connection URL formats
- Local Redis
- Local with password
- Upstash (TLS)
- Redis Cloud
How auto-detection works
WhenMCP_TS_STORAGE_TYPE is not set, the SDK scans for known environment variables in priority order. REDIS_URL is checked first — before MCP_TS_STORAGE_FILE, MCP_TS_STORAGE_SQLITE_PATH, and SUPABASE_URL. If REDIS_URL is present and the connection succeeds, Redis is used without any further configuration.
Fallback behavior
If the Redis connection fails at startup — whether due to a bad URL, a timeout, or an unreachable host — the SDK logs an error and falls back to in-memory storage:Key schema
The SDK stores sessions under two types of Redis keys:| Key pattern | Type | Purpose |
|---|---|---|
mcp:session:<identity>:<sessionId> | String (JSON) | Full session data |
mcp:identity:<identity>:sessions | Set | Index of session IDs per identity |
getIdentitySessionsData.
Example: use the auto-detected storage export
Example: instantiate directly with a custom client
Use this pattern when you need fine-grained control over theioredis configuration — for example, to set a custom connectTimeout, use a Redis Cluster, or inject a client in tests.
Deploying to Upstash
Upstash is a serverless Redis provider that works well with Vercel, Cloudflare Workers, and other edge environments. Create a database in the Upstash console, then copy the REST URL from the Details tab.Create an Upstash Redis database
Go to console.upstash.com, create a new database, and select your preferred region.
Copy the connection URL
In the database details, find the Redis URL (starts with
rediss://). Copy it.Set the environment variable
Add On Vercel, add this in Project Settings → Environment Variables.
REDIS_URL to your deployment environment:Troubleshooting
connect ECONNREFUSED — Redis is not running locally. Start it with redis-server or check your Docker setup.
WRONGPASS invalid username-password pair — The password in REDIS_URL is incorrect.
ERR unknown command 'SCAN' — You are using a Redis-compatible store that does not support SCAN. The SDK falls back to KEYS automatically in this case, which is safe but slower on large keysets.