/** * Task lifecycle adapter wrapping the MCP SDK's experimental Tasks API. * * This module isolates all direct usage of `@modelcontextprotocol/sdk/experimental` * behind a single adapter class so that future breaking changes in the experimental * API only require updates here. */ import type { TaskStore, TaskMessageQueue } from '@modelcontextprotocol/sdk/experimental'; import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js'; export interface TaskManagerConfig { /** Time-to-live for completed task results (milliseconds). */ defaultTtl: number; /** Suggested interval between client polls (milliseconds). */ pollInterval: number; /** Maximum messages per task queue (prevents unbounded growth). */ maxQueueSize: number; /** Interval for cleanup/monitoring sweep (milliseconds). */ cleanupInterval: number; } /** * Manages MCP task lifecycle: creation, background execution, cancellation, and cleanup. * * - Provides `RetentionTaskStore` and `InMemoryTaskMessageQueue` instances for * `McpServer`'s `ProtocolOptions`. * - 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 taskMessageQueue: TaskMessageQueue; 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