import { Server } from '@modelcontextprotocol/sdk/server/index.js'; /** * Represents a single HTTP session with its own MCP server instance. */ export interface ISession { id: string; server: Server; createdAt: Date; lastActivityAt: Date; metadata?: Record; } /** * Configuration for the session manager. */ export interface ISessionManagerConfig { /** * Session timeout in milliseconds. * Default: 30 minutes (1800000 ms) */ sessionTimeout?: number; /** * Interval for cleaning up inactive sessions in milliseconds. * Default: 5 minutes (300000 ms) */ cleanupInterval?: number; /** * Maximum number of concurrent sessions. * Default: 100 */ maxSessions?: number; } /** * Manages HTTP transport sessions with lifecycle management. */ export declare class SessionManager { private readonly sessions; private cleanupTimer?; private readonly config; constructor(config?: ISessionManagerConfig); /** * Create a new session with a unique ID. * * @param server The MCP server instance for this session * @param metadata Optional metadata to associate with the session * @returns The created session * @throws Error if maximum sessions limit is reached */ createSession(server: Server, metadata?: Record): ISession; /** * Get a session by its ID. * * @param sessionId The session ID * @returns The session if found, undefined otherwise */ getSession(sessionId: string): ISession | undefined; /** * Remove a session by its ID. * * @param sessionId The session ID * @returns True if the session was removed, false if not found */ removeSession(sessionId: string): boolean; /** * Check if a session exists and is still valid. * * @param sessionId The session ID * @returns True if the session exists and is valid, false otherwise */ hasSession(sessionId: string): boolean; /** * Get all active sessions. * * @returns Array of active sessions */ getAllSessions(): ISession[]; /** * Get the number of active sessions. * * @returns Number of active sessions */ getSessionCount(): number; /** * Clean up inactive sessions based on timeout. */ private cleanupInactiveSessions; /** * Start the cleanup timer for inactive sessions. */ private startCleanupTimer; /** * Stop the cleanup timer and clear all sessions. * Should be called when shutting down the HTTP transport. */ shutdown(): void; /** * Get session statistics for monitoring. * * @returns Session statistics */ getStatistics(): { activeSessions: number; maxSessions: number; sessionTimeout: number; oldestSession?: Date; newestSession?: Date; }; }