UNPKG

mcp-adr-analysis-server

Version:

MCP server for analyzing Architectural Decision Records and project architecture

239 lines 6.5 kB
/** * Task Manager for MCP Tasks Integration * * This module provides a unified interface for managing MCP Tasks across * long-running operations in the mcp-adr-analysis-server. * * Implements ADR-018: MCP Tasks Integration Strategy * * @experimental MCP Tasks is an experimental feature in the MCP specification */ import { type TaskPersistenceConfig } from './task-persistence.js'; /** * Task status values from MCP spec */ export type McpTaskStatus = 'working' | 'input_required' | 'completed' | 'failed' | 'cancelled'; /** * Task types supported by this server * From ADR-020: bootstrap, deployment, research, orchestration, troubleshooting, validation, planning, adr_planning */ export type TaskType = 'bootstrap' | 'deployment' | 'research' | 'orchestration' | 'troubleshooting' | 'validation' | 'planning' | 'adr_planning'; /** * Phase information for multi-phase operations */ export interface PhaseInfo { name: string; description: string; progress: number; status: 'pending' | 'running' | 'completed' | 'failed' | 'skipped'; startTime?: string; endTime?: string; error?: string; } /** * Extended metadata for ADR-specific tasks */ export interface AdrTaskMetadata { type: TaskType; tool: string; phases?: PhaseInfo[]; dependencies?: string[]; projectPath?: string; adrDirectory?: string; customData?: Record<string, unknown>; } /** * MCP Task structure (matches SDK spec) */ export interface McpTask { taskId: string; status: McpTaskStatus; ttl: number | null; createdAt: string; lastUpdatedAt: string; pollInterval?: number; statusMessage?: string; } /** * Task with ADR-specific metadata */ export interface AdrTask extends McpTask { metadata?: AdrTaskMetadata; result?: unknown; } /** * Options for creating a new task */ export interface CreateAdrTaskOptions { type: TaskType; tool: string; phases?: string[]; dependencies?: string[]; projectPath?: string; adrDirectory?: string; ttl?: number | null; pollInterval?: number; } /** * Progress update for a task */ export interface TaskProgressUpdate { taskId: string; progress: number; phase?: string; phaseProgress?: number; message?: string; } /** * Result type for task completion */ export interface TaskResult { success: boolean; data?: unknown; error?: { code: string; message: string; recoverable?: boolean; }; } /** * Check if a task status represents a terminal state */ export declare function isTerminalStatus(status: McpTaskStatus): boolean; /** * Options for TaskManager configuration */ export interface TaskManagerOptions { /** Persistence configuration */ persistence?: Partial<TaskPersistenceConfig>; /** Whether to enable persistence (default: true) */ enablePersistence?: boolean; } /** * Task Manager for coordinating long-running operations * * Features: * - Creates and tracks tasks for tool operations * - Updates task progress and status * - Supports multi-phase operations with individual phase tracking * - Provides cancellation support * - File-based persistence for durability across restarts * - Designed to work with MCP SDK experimental tasks API */ export declare class TaskManager { private tasks; private taskProgress; private cleanupTimers; private persistence; private initialized; constructor(options?: TaskManagerOptions); /** * Initialize the TaskManager - loads persisted tasks */ initialize(): Promise<void>; /** * Persist current state to disk */ private persistState; /** * Create a new task for a tool operation */ createTask(options: CreateAdrTaskOptions): Promise<AdrTask>; /** * Get a task by ID */ getTask(taskId: string): Promise<AdrTask | null>; /** * Get task result */ getTaskResult(taskId: string): Promise<TaskResult | null>; /** * List all tasks */ listTasks(cursor?: string): Promise<{ tasks: AdrTask[]; nextCursor?: string; }>; /** * Update task progress */ updateProgress(update: TaskProgressUpdate): Promise<void>; /** * Start a phase */ startPhase(taskId: string, phaseName: string): Promise<void>; /** * Complete a phase */ completePhase(taskId: string, phaseName: string): Promise<void>; /** * Fail a phase */ failPhase(taskId: string, phaseName: string, error: string): Promise<void>; /** * Complete a task successfully */ completeTask(taskId: string, result: TaskResult): Promise<void>; /** * Fail a task */ failTask(taskId: string, error: string): Promise<void>; /** * Cancel a task */ cancelTask(taskId: string, reason?: string): Promise<void>; /** * Check if a task is still running */ isTaskRunning(taskId: string): Promise<boolean>; /** * Request input from the user (sets task to input_required state) * Used for interactive tools that need user input during execution */ requestInput(taskId: string, prompt: string): Promise<void>; /** * Resume a task after receiving input (sets task back to working state) */ resumeTask(taskId: string): Promise<void>; /** * Get task progress (0-100) */ getProgress(taskId: string): number; /** * Get task metadata */ getMetadata(taskId: string): AdrTaskMetadata | undefined; /** * Get all tasks for a specific tool */ getTasksByTool(tool: string): Promise<AdrTask[]>; /** * Get all tasks of a specific type */ getTasksByType(type: TaskType): Promise<AdrTask[]>; /** * Clean up a specific task */ private cleanupTask; /** * Cleanup completed/failed tasks older than specified duration */ cleanup(maxAgeMs?: number): Promise<number>; /** * Cleanup all tasks and timers (for graceful shutdown) */ shutdown(): Promise<void>; } /** * Get the global TaskManager instance */ export declare function getTaskManager(): TaskManager; /** * Set the global TaskManager instance (for testing or custom stores) */ export declare function setTaskManager(manager: TaskManager): void; /** * Reset the global TaskManager (for testing) */ export declare function resetTaskManager(): Promise<void>; //# sourceMappingURL=task-manager.d.ts.map