/** * @name session/redis-session-store * @description Redis-backed persistent session store for production SAP MCP deployments. * * Features: * - Persistent sessions across server restarts * - Multi-instance support (distributed deployments) * - Automatic TTL-based expiration * - Memory-safe (no local storage) * * @flow * 1. `createSessionStore` checks `SAP_MCP_USE_REDIS` env var and creates a `RedisSessionStore` * or returns `null` for in-memory development mode. * 2. `RedisSessionStore` manages session CRUD with automatic TTL based on session expiry. * 3. A background cleanup interval removes expired sessions periodically. * * @env `SAP_MCP_USE_REDIS` — Set to `true` to enable Redis session storage. * @env `SAP_MCP_REDIS_URL` — Redis connection URL (default `redis://localhost:6379`). * * @module session/redis-session-store */ import { Redis } from 'ioredis'; import type { SapAgentSession } from '../../core/src/types.js'; /** * @name RedisSessionStoreConfig * @description Configuration for the Redis-backed session store. * * @property redisUrl — Redis connection URL. * @property keyPrefix — Optional prefix for session keys in Redis (default `sap-mcp:session:`). * @property cleanupIntervalMs — Optional cleanup interval in milliseconds (default 3600000 / 1 hour). * * @usedBy `RedisSessionStore`, `createSessionStore` */ export interface RedisSessionStoreConfig { redisUrl: string; keyPrefix?: string; cleanupIntervalMs?: number; } /** * @name RedisSessionStore * @description Persistent session store backed by Redis with TTL-based expiration and periodic cleanup. * * @method connect — Establish the Redis connection. * @method set — Store a session with TTL derived from its expiry. * @method get — Retrieve a session by id. * @method delete — Remove a session by id. * @method getAll — Retrieve all active sessions (for debugging/admin). * @method getCount — Get the total number of stored sessions. * @method cleanup — Manually remove expired sessions. * @method getStats — Get session statistics (total, active, expired). * @method shutdown — Gracefully close the Redis connection and cleanup interval. * @method getClient — Get the raw Redis client for advanced operations. * * @usedBy `createSessionStore`, distributed SAP MCP deployments. */ export declare class RedisSessionStore { private redis; private keyPrefix; private cleanupInterval?; private isShuttingDown; /** * @name RedisSessionStore.constructor * @description Creates a new Redis session store with merged config and starts the cleanup interval. * * @param config — Optional configuration overriding defaults. */ constructor(config?: RedisSessionStoreConfig); /** * @name RedisSessionStore.connect * @description Connects to the Redis server. * * @usedBy `createSessionStore`. */ connect(): Promise; /** * @name RedisSessionStore.set * @description Stores a session in Redis with a TTL derived from its expiry timestamp. * * @param sessionId — Unique session identifier. * @param session — The agent session to store. */ set(sessionId: string, session: SapAgentSession): Promise; /** * @name RedisSessionStore.get * @description Retrieves a session by id from Redis. * * @param sessionId — Unique session identifier. * @returns The session if found and parseable, `null` otherwise. */ get(sessionId: string): Promise; /** * @name RedisSessionStore.delete * @description Deletes a session from Redis by id. * * @param sessionId — Unique session identifier. * @returns `true` if the session was deleted, `false` if it did not exist. */ delete(sessionId: string): Promise; /** * @name RedisSessionStore.getAll * @description Retrieves all active sessions from Redis (for debugging/admin). * * @returns Array of all stored agent sessions. */ /** * @name RedisSessionStore.scanKeys * @description Iterates session keys with `SCAN` instead of `KEYS` to avoid * blocking Redis on large key spaces. `KEYS` is O(N) and can stall a * production instance; `SCAN` is incremental and safe under load. * * @returns The full list of session keys matching the store prefix. */ private scanKeys; getAll(): Promise; /** * @name RedisSessionStore.getCount * @description Returns the total number of stored sessions. * * @returns Count of session keys in Redis. */ getCount(): Promise; /** * @name RedisSessionStore.cleanup * @description Manually removes expired sessions from Redis. */ cleanup(): Promise; /** * @name RedisSessionStore.getStats * @description Returns session statistics (total, active, expired). * * @returns Object with `totalSessions`, `activeSessions`, and `expiredSessions` counts. */ getStats(): Promise<{ totalSessions: number; activeSessions: number; expiredSessions: number; }>; /** * @name RedisSessionStore.shutdown * @description Gracefully shuts down the Redis connection and clears the cleanup interval. */ shutdown(): Promise; /** * @name RedisSessionStore.getClient * @description Returns the raw Redis client instance for advanced operations. * * @returns The underlying `ioredis` Redis instance. */ getClient(): InstanceType; /** @description Builds the full Redis key from the prefix and session id. */ private getKey; /** @description Starts the periodic cleanup interval for expired sessions. */ private startCleanup; } /** * @name createSessionStore * @description Creates a session store based on environment configuration. * * Uses Redis in production (when `SAP_MCP_USE_REDIS=true`) and in-memory * storage in development (returns `null`). * * @returns A connected `RedisSessionStore` if Redis is enabled, `null` otherwise. * @throws If Redis connection fails after retries. * * @env `SAP_MCP_USE_REDIS` — Set to `true` to enable Redis. * @env `SAP_MCP_REDIS_URL` — Redis connection URL (default `redis://localhost:6379`). * * @usedBy Server initialization in the SAP MCP runtime. */ export declare function createSessionStore(): Promise; //# sourceMappingURL=redis-session-store.d.ts.map