StorageBackend interface, all built-in backends (Redis, SQLite, File, Memory, Supabase), and environment variables for auto-detection.
The storage layer persists MCP session data — OAuth tokens, server URLs, connection state — across requests and server restarts. Every server-side operation (connecting, disconnecting, OAuth flows) reads and writes through this layer. You can use the auto-detected global storage proxy, or instantiate a specific backend directly for full control.
All storage backends implement this interface. Import individual backends from @mcp-ts/sdk/server or use the global storage proxy, which selects the backend automatically.
import type { StorageBackend } from '@mcp-ts/sdk/server';
Returns every session ID across all users. Admin operation — use with care.
const all = await storage.getAllSessionIds();
clearAll(): Promise<void>
Deletes all sessions across all users. Admin operation.
await storage.clearAll();
cleanupExpiredSessions(): Promise<void>
Removes expired sessions. This is a no-op on backends that handle TTL natively (Redis, Supabase). Useful as a scheduled job on File and SQLite backends.
await storage.cleanupExpiredSessions();
disconnect(): Promise<void>
Closes the connection to the storage backend. Call this during graceful shutdown.
await storage.disconnect();
init(): Promise<void>
Optional. When present, validates connectivity to the backend at startup (table existence, network reachability, etc.). Called automatically when the global storage proxy initializes.
import { Redis } from 'ioredis';import { RedisStorageBackend } from '@mcp-ts/sdk/server';const redis = new Redis(process.env.REDIS_URL);const store = new RedisStorageBackend(redis);await store.init();
MemoryStorageBackend()
In-memory store — no constructor arguments. Data is lost when the process exits. Use for local development and testing.
import { MemoryStorageBackend } from '@mcp-ts/sdk/server';const store = new MemoryStorageBackend();
FileStorageBackend(options?)
Persists sessions as JSON to a local file. Suitable for single-process development environments.
Path to the SQLite database file. Defaults to a file in the working directory.
import { SqliteStorage } from '@mcp-ts/sdk/server';const store = new SqliteStorage({ path: './sessions.db' });await store.init();
SupabaseStorageBackend(client)
Backed by a Supabase (PostgreSQL) database. Supports row-level security policies and scales across multiple server instances.Requires the @supabase/supabase-js peer dependency. Run npx mcp-ts supabase-init to eject the required database migrations before using this backend.