/** * A `TaskStore` implementation with post-terminal retention semantics. * * Unlike the SDK's `InMemoryTaskStore` — which arms a deletion timer at task * creation and evicts the record after `ttl` regardless of status — this store * treats `ttl` as a *retention window that starts when the task reaches a * terminal state*. Consequences: * * - A non-terminal task (`working`/`input_required`) is immortal: it has no * `expiresAt` and is never evicted, no matter how much time elapses. * - Once a task reaches a terminal state (`completed`/`failed`/`cancelled`), * its retention window opens (`expiresAt = now + ttl`). It stays retrievable * until the window elapses, then is evicted lazily on read or by the periodic * `sweepExpired()` sweep. * * Method contracts and error-message strings mirror `InMemoryTaskStore` so the * only behavioral difference is timer semantics. * * The store is SDK-free and process-scoped: tasks are keyed by `taskId` alone, * and the task types (`TaskStatus`, `Task`, ...) are defined here rather than * imported from any `@modelcontextprotocol/*` package. */ /** The five SEP-2663 task statuses. */ export type TaskStatus = 'working' | 'input_required' | 'completed' | 'failed' | 'cancelled'; /** A task record as exposed to callers. */ export interface Task { taskId: string; status: TaskStatus; /** Post-terminal retention window (ms); `null` means unlimited. */ ttl: number | null; createdAt: string; lastUpdatedAt: string; pollInterval?: number; statusMessage?: string; } /** JSON-RPC request id of the request that created a task. */ export type RequestId = string | number; /** The originating request a task was created for. */ export interface Request { method: string; params?: Record; } /** A task's stored result payload (e.g. a `CallToolResult`). */ export type Result = { [key: string]: unknown; }; /** Options accepted by `TaskStore.createTask` (local copy of the removed v1 SDK type). */ export interface CreateTaskOptions { ttl?: number | null; pollInterval?: number; context?: Record; } /** Task storage contract (local copy of the removed v1 SDK `TaskStore` interface). */ export interface TaskStore { createTask(taskParams: CreateTaskOptions, requestId: RequestId, request: Request, sessionId?: string): Promise; getTask(taskId: string, sessionId?: string): Promise; storeTaskResult(taskId: string, status: 'completed' | 'failed', result: Result, sessionId?: string): Promise; getTaskResult(taskId: string, sessionId?: string): Promise; updateTaskStatus(taskId: string, status: TaskStatus, statusMessage?: string, sessionId?: string): Promise; listTasks(cursor?: string, sessionId?: string): Promise<{ tasks: Task[]; nextCursor?: string; }>; } /** True when a task status is terminal (`completed`, `failed` or `cancelled`). */ export declare function isTerminal(status: TaskStatus): boolean; export declare class RetentionTaskStore implements TaskStore { private readonly defaultTtl; private tasks; /** * @param defaultTtl Retention window (ms) applied when a task is created * without an explicit `ttl`. `null` means unlimited (no eviction). */ constructor(defaultTtl?: number | null); /** * Generates a unique task ID (16 random bytes as 32 hex chars), matching * `InMemoryTaskStore`. */ private generateTaskId; /** True when a stored task's retention window has elapsed. */ private isExpired; /** * Evict a task and log a distinct eviction message (never a failure). Logged * at `info` so a post-retention `-32602` remains diagnosable under the default * `LOG_LEVEL=info` — this is a benign, expected event, not an error. */ private evict; /** * Look up a live (non-expired) stored task, lazily evicting it if its * retention window has elapsed. */ private getLive; createTask(taskParams: CreateTaskOptions, requestId: RequestId, request: Request, _sessionId?: string): Promise; getTask(taskId: string, _sessionId?: string): Promise; storeTaskResult(taskId: string, status: 'completed' | 'failed', result: Result, _sessionId?: string): Promise; getTaskResult(taskId: string, _sessionId?: string): Promise; updateTaskStatus(taskId: string, status: TaskStatus, statusMessage?: string, _sessionId?: string): Promise; listTasks(cursor?: string, _sessionId?: string): Promise<{ tasks: Task[]; nextCursor?: string; }>; /** * Evict every terminal task whose retention window has elapsed. Non-terminal * (immortal) tasks are always spared. Returns the number of tasks dropped. */ sweepExpired(): number; /** Clear all stored tasks (useful for testing or graceful shutdown). */ cleanup(): void; /** Open a terminal task's retention window from now, if a ttl is configured. */ private openRetentionWindow; } //# sourceMappingURL=retention-task-store.d.ts.map