@mcp-ts/sdk keeps track of active MCP sessions across requests. Every session — its OAuth tokens, transport type, server URL, and connection state — lives in the storage layer. Because your server process may restart or scale horizontally at any time, storage must live outside the process. Pick the backend that fits your environment; the SDK handles the rest transparently through a single storage export.
How auto-detection works
The SDK selects a backend at startup using a fixed priority order. You can either setMCP_TS_STORAGE_TYPE to force a specific backend, or let the SDK infer one from whichever environment variables are present.
Detection priority:
MCP_TS_STORAGE_TYPE— explicit override always winsREDIS_URLpresent → RedisMCP_TS_STORAGE_FILEpresent → FileMCP_TS_STORAGE_SQLITE_PATHpresent → SQLiteSUPABASE_URL(+ key) present → Supabase- Nothing set → Memory (default)
When Redis auto-detection fails (unreachable host, bad URL, etc.), the SDK logs a warning and falls back to in-memory storage. Your app continues to run, but sessions will not survive a restart. The same fallback applies when
MCP_TS_STORAGE_TYPE=redis is set explicitly but the connection fails.Backend comparison
| Backend | Persistence | Distributed | Auto-expiry | Extra install | Production-ready |
|---|---|---|---|---|---|
| Memory | No | No | No | None | No |
| File | Yes | No | No | None | No |
| SQLite | Yes | No | Yes (manual) | better-sqlite3 | Single-instance only |
| Redis | Yes | Yes | Yes (TTL) | ioredis | Yes |
| Supabase | Yes | Yes | Yes (manual) | @supabase/supabase-js | Yes |
Quick configuration
- Redis
- Supabase
- SQLite
- File
- Memory
Using a backend directly
The auto-detection path covers most use cases, but you can also instantiate any backend directly — useful when you want to pass an existing client or a custom configuration.Session data structure
Every backend stores the sameSessionData shape:
active flag controls TTL transitions: false means the session is short-lived (auth pending or failed); true means the session is fully established and uses the long-lived TTL.
Choose your backend
Redis
Distributed, TTL-managed storage. Recommended for all production and serverless deployments.
Supabase
PostgreSQL-backed storage with RLS policies and AES-256-GCM encryption at rest.
SQLite
Zero-config persistent database. Good for single-instance apps and local development.
File and Memory
Built-in backends requiring no extra packages. File for local dev, Memory for testing.