/** * Task lifecycle manager for the hand-built `io.modelcontextprotocol/tasks` * extension (SEP-2663): background execution, cancellation and retention. * * SDK-free apart from the `CallToolResult` type; the task store contract is * local (see `retention-task-store.ts`). */ import type { CallToolResult } from '@modelcontextprotocol/server'; import type { TaskStore } from './retention-task-store.js'; export interface TaskManagerConfig { /** Time-to-live for completed task results (milliseconds). */ defaultTtl: number; /** Suggested interval between client polls (milliseconds). */ pollInterval: number; /** Interval for cleanup/monitoring sweep (milliseconds). */ cleanupInterval: number; } /** * Manages MCP task lifecycle: creation, background execution, cancellation, and cleanup. * * - Owns the process-scoped `RetentionTaskStore` read by the server's * `tasks/*` handlers. * - Tracks active background work via `AbortController` per task for cancellation. * - Handles graceful shutdown (cancels active tasks, clears timers). */ export declare class TaskManager { readonly taskStore: TaskStore; readonly config: TaskManagerConfig; /** * Concrete handle to the same instance exposed as `taskStore`. Retained so the * periodic sweep and shutdown can call `RetentionTaskStore`-specific methods * (`sweepExpired`, `cleanup`) without repeatedly downcasting the `TaskStore`. */ private readonly retentionStore; /** Maps taskId → AbortController for active background work. */ private activeControllers; private cleanupTimer?; constructor(config?: Partial); /** * Start background work for a task. * * This is fire-and-forget: the returned promise resolves immediately. * The `work` function runs asynchronously; its result is stored in the * task store on completion. On error the task is marked `failed`. * On abort (cancellation) the task is marked `cancelled`. * * @param taskId ID of the task (from `taskStore.createTask`) * @param work Async function receiving an `AbortSignal` and returning a `CallToolResult` */ startBackground(taskId: string, work: (signal: AbortSignal) => Promise): void; /** Cancel a running task by aborting its AbortController. */ cancel(taskId: string): boolean; /** Number of currently active background tasks. */ get activeCount(): number; private startCleanup; /** Graceful shutdown: cancel all active tasks and clear timers. */ shutdown(): void; } //# sourceMappingURL=task-manager.d.ts.map