/** * @name task-manager * @description MCP experimental task support for long-running operations. * Wraps the SDK's experimental/tasks API to provide async task tracking * for operations like transaction submission, on-chain confirmation, and * premium stream processing. * * Tasks allow the client to poll status instead of blocking the tool call. * The client receives a task ID and can query progress until completion. * * @module tools/task-manager */ import { InMemoryTaskStore } from '@modelcontextprotocol/sdk/experimental/tasks/stores/in-memory.js'; import type { TaskStatus } from '@modelcontextprotocol/sdk/types.js'; /** * @name TaskState * @description Internal state tracked for each async task. */ interface TaskState { id: string; toolName: string; status: TaskStatus; progress: number; total: number; message: string; result?: unknown; error?: string; createdAt: number; updatedAt: number; } /** * @name TaskManager * @description Manages async MCP tasks for long-running tool operations. * Uses an in-memory store for task state. In production with multiple * server instances, this should be replaced with a Redis-backed store. */ export declare class TaskManager { private static instance; private readonly tasks; private readonly store; private constructor(); /** * @name getInstance * @description Singleton accessor for the global task manager. */ static getInstance(): TaskManager; /** * @name getStore * @description Returns the SDK task store for integration with the MCP server. */ getStore(): InMemoryTaskStore; /** * @name createTask * @description Create a new async task for a long-running tool operation. * Returns the task ID that the client can use to poll status. */ createTask(toolName: string, message: string, total?: number): string; /** * @name updateProgress * @description Update task progress. Called by long-running operations * to report incremental progress to the client. */ updateProgress(id: string, progress: number, message?: string): void; /** * @name completeTask * @description Mark a task as completed with the final result. */ completeTask(id: string, result: unknown): void; /** * @name failTask * @description Mark a task as failed with an error message. */ failTask(id: string, error: string): void; /** * @name getTask * @description Get the current state of a task for client polling. */ getTask(id: string): TaskState | undefined; /** * @name getTaskStatus * @description Get a lightweight status snapshot suitable for MCP task status notifications. */ getTaskStatus(id: string): { status: TaskStatus; progress: number; message: string; } | undefined; /** * @name cleanup * @description Remove completed/failed tasks older than the specified TTL (ms). */ cleanup(ttlMs?: number): void; /** * @name isLongRunningTool * @description Check if a tool is a candidate for async task execution. * Tools that involve on-chain confirmation or premium streaming are * good candidates for task-based execution. */ static isLongRunningTool(toolName: string): boolean; } export {}; //# sourceMappingURL=task-manager.d.ts.map