ADR-020: MCP Tasks Integration Strategy
Statusโ
Accepted (Phase 1 Complete)
Dateโ
2025-12-17
Contextโ
The Model Context Protocol (MCP) 2025-11-25 specification introduced Tasks as a new primitive for tracking durable, long-running operations. Tasks are state machines that allow servers to manage expensive computations, batch processing, and operations that may take significant time to complete.
MCP Tasks Overviewโ
From the MCP Specification 2025-11-25:
- Tasks are durable state machines for tracking long-running operations
- Lifecycle states:
working,input_required,completed,failed,cancelled - Task Creation: Tasks are created implicitly by tools returning
CreateTaskResult(not via explicittasks/createendpoint) - Key methods (SDK request schemas):
GetTaskRequestSchema(tasks/get) - Get task status and progressListTasksRequestSchema(tasks/list) - List all tasksGetTaskPayloadRequestSchema(tasks/result) - Get final task result payloadCancelTaskRequestSchema(tasks/cancel) - Cancel an in-progress task
- Use cases: Expensive computations, batch processing, operations requiring progress tracking
Important SDK Behavior: Unlike a REST-style API, MCP Tasks do not have a
tasks/createendpoint. Tasks are created as a side effect when a tool returns aCreateTaskResultcontaining task metadata. This design ties task creation directly to tool execution.
Current Server Architectureโ
The mcp-adr-analysis-server currently has several tools that implement custom long-running operation tracking:
-
Bootstrap Validation Loop Tool (
src/tools/bootstrap-validation-loop-tool.ts)- Self-learning deployment validation system
- Executes multiple phases: generate scripts, execute, capture learnings, update ADRs
- Custom
BootstrapExecutionResultwithexecutionId,timestamp, progress tracking - DAG-based parallel execution via
DAGExecutor
-
Deployment Readiness Tool (
src/tools/deployment-readiness-tool.ts)- Multi-phase deployment validation with test failure tracking
- Custom result interfaces:
TestValidationResult,TestSuiteResult - History analysis and pattern recognition
- Memory integration for deployment assessment tracking
-
Tool Chain Orchestrator (
src/tools/tool-chain-orchestrator.ts)- Already deprecated for CE-MCP migration
- Step dependencies, retry logic, conditional execution
- Custom step tracking with
dependsOn,retryable,conditional
-
DAG Executor (
src/utils/dag-executor.ts)- Directed Acyclic Graph execution engine
- Parallel task execution with dependency resolution
- Custom
TaskNodeinterface withretryCount,retryDelay,canFailSafely
-
Research Tools (
perform-research-tool.ts,research-integration-tool.ts)- Multi-step research workflows
- Custom progress tracking
-
Interactive ADR Planning Tool (
src/tools/interactive-adr-planning-tool.ts)- 7-phase guided ADR creation workflow
- Phases: problem_definition โ research_analysis โ option_exploration โ decision_making โ impact_assessment โ implementation_planning โ adr_generation
- Session-based with persistent state across tool calls
- Uses ResearchOrchestrator for context gathering
- Generates TODOs from architectural decisions
-
Troubleshoot Guided Workflow Tool (
src/tools/troubleshoot-guided-workflow-tool.ts)- Systematic troubleshooting with multiple operations:
analyze_failure,generate_test_plan,full_workflow - Memory integration via
TroubleshootingMemoryManagerfor session persistence - Stores troubleshooting sessions with effectiveness tracking
- Related ADR lookup, follow-up action determination
- Already deprecated for CE-MCP (returns state machine directives)
- Systematic troubleshooting with multiple operations:
SDK Version Considerationโ
- Previous SDK:
@modelcontextprotocol/sdk@^1.19.1 - Updated SDK:
@modelcontextprotocol/sdk@^1.25.1(completed) - Tasks support enabled via SDK upgrade
Decisionโ
We will integrate MCP Tasks into the mcp-adr-analysis-server to provide standardized, protocol-compliant long-running operation tracking. This integration will:
Phase 1: SDK Upgrade and Infrastructureโ
- Upgrade
@modelcontextprotocol/sdkfrom^1.19.1to^1.25.1 - Implement
TaskManagerutility class to abstract MCP Tasks operations - Add task lifecycle handlers in
src/index.ts
Phase 2: Tool Migration (Priority Order)โ
High Priority - Replace Custom Implementationsโ
| Tool | Current Implementation | MCP Tasks Benefit |
|---|---|---|
bootstrap_validation_loop | Custom executionId, phases | Standardized progress, cancellation support |
deployment_readiness | Custom history tracking | Protocol-compliant state persistence |
tool_chain_orchestrator | Already deprecated | Direct replacement with Tasks |
troubleshoot_guided_workflow | Custom memory session tracking | Track full_workflow with session effectiveness |
interactive_adr_planning | Custom 7-phase session state | Track ADR planning workflow with phase progress (14% per phase) |
Medium Priority - Enhance with Tasksโ
| Tool | Enhancement |
|---|---|
perform_research | Track multi-step research workflows |
adr_bootstrap_validation | Track script generation progress |
adr_validation | Track bulk ADR validation with AI analysis progress |
Phase 3: DAG Executor Integrationโ
Integrate DAGExecutor with MCP Tasks:
- Each DAG node becomes a sub-task
- Parent task tracks overall DAG execution
- Preserve parallel execution benefits
Task Schema Designโ
// Internal AdrTask structure (maps to MCP Task types)
interface AdrTask {
taskId: string; // Unique task identifier (UUID)
type: TaskType; // 'bootstrap' | 'deployment' | 'research' | 'orchestration' | 'troubleshooting' | 'validation' | 'planning'
status: TaskStatus; // 'working' | 'input_required' | 'completed' | 'failed' | 'cancelled' (MCP SDK values)
progress: number; // 0-100 percentage
tool: string; // Originating tool name
createdAt: string; // ISO timestamp
lastUpdatedAt: string; // ISO timestamp
phases?: AdrTaskPhase[]; // For multi-phase operations
result?: TaskResult; // Final result when completed
error?: string; // Error message when failed
}
// Phase tracking for multi-step operations
interface AdrTaskPhase {
name: string;
description: string;
status: 'pending' | 'working' | 'completed' | 'failed';
startedAt?: string;
completedAt?: string;
result?: unknown;
}
API Integrationโ
// Import SDK task schemas (experimental)
import {
ListTasksRequestSchema,
GetTaskRequestSchema,
CancelTaskRequestSchema,
GetTaskPayloadRequestSchema,
} from '@modelcontextprotocol/sdk/types.js';
// Server capability declaration
server.setRequestHandler(InitializeRequestSchema, async () => ({
capabilities: {
experimental: {
tasks: {}, // Enable experimental Tasks capability
},
},
}));
// Task handlers using SDK schemas
// NOTE: No tasks/create handler - tasks are created implicitly by tools returning CreateTaskResult
server.setRequestHandler(ListTasksRequestSchema, async () => {
const taskManager = getTaskManager();
const tasks = await taskManager.listTasks();
return { tasks };
});
server.setRequestHandler(GetTaskRequestSchema, async request => {
const { taskId } = request.params;
const taskManager = getTaskManager();
const task = await taskManager.getTask(taskId);
if (!task) throw new McpAdrError(`Task not found: ${taskId}`, 'TASK_NOT_FOUND');
return { task };
});
server.setRequestHandler(CancelTaskRequestSchema, async request => {
const { taskId } = request.params;
const taskManager = getTaskManager();
const cancelled = await taskManager.cancelTask(taskId);
if (!cancelled) throw new McpAdrError(`Task not found: ${taskId}`, 'TASK_NOT_FOUND');
return { success: true };
});
server.setRequestHandler(GetTaskPayloadRequestSchema, async request => {
const { taskId } = request.params;
const taskManager = getTaskManager();
const result = await taskManager.getTaskResult(taskId);
return result ?? {};
});
Consequencesโ
Positiveโ
- Protocol Compliance: Aligns with MCP 2025-11-25 specification
- Standardized Progress Tracking: Clients can uniformly track all long-running operations
- Cancellation Support: Native support for cancelling in-progress operations
- Reduced Custom Code: Replace bespoke tracking implementations
- Better Client Integration: AI assistants can better manage and monitor operations
- Memory Integration: Tasks can persist to memory entities for historical analysis
- Interoperability: Other MCP clients can interact with our tasks
Negativeโ
- SDK Upgrade Required: May introduce breaking changes
- Migration Effort: Existing tools need refactoring
- Learning Curve: Team needs to understand Tasks API
- Potential Overhead: Tasks add protocol overhead for simple operations