list_tasks
View and filter all tasks by status, batch ID, or recency to monitor and manage complex AI workflows on the MCP Task server.
Instructions
List all tasks with their current status.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| batch_id | No | Optional: Filter tasks by batch ID to only show tasks from a specific batch | |
| recent_only | No | Optional: Only show tasks from the last 2 hours (default: false) | |
| status_filter | No | Optional: Filter tasks by status |
Implementation Reference
- src/serve.ts:1076-1147 (handler)Handler for 'list_tasks' tool call. Retrieves all tasks from TaskManager, applies optional filters (status_filter, batch_id, recent_only), creates summaries and stats, returns formatted JSON response.case 'list_tasks': { let allTasks = taskManager.getAllTasks(); // Apply recent_only filter (last 2 hours) if (args.recent_only) { const twoHoursAgo = Date.now() - 2 * 60 * 60 * 1000; allTasks = allTasks.filter( t => t.createdAt.getTime() > twoHoursAgo ); } // Apply batch_id filter if (args.batch_id) { allTasks = allTasks.filter( t => t.batchId === args.batch_id ); } // Apply status filter const filteredTasks = args.status_filter ? allTasks.filter(t => t.status === args.status_filter) : allTasks; const taskSummaries = filteredTasks.map(t => ({ id: t.id, status: t.status, task: t.task.substring(0, 100), model: t.model || t.modelClass, batchId: t.batchId, readOnly: t.readOnly, createdAt: t.createdAt, completedAt: t.completedAt, })); // Calculate stats for filtered tasks const stats = { total: filteredTasks.length, pending: filteredTasks.filter(t => t.status === 'pending') .length, running: filteredTasks.filter(t => t.status === 'running') .length, completed: filteredTasks.filter( t => t.status === 'completed' ).length, failed: filteredTasks.filter(t => t.status === 'failed') .length, cancelled: filteredTasks.filter( t => t.status === 'cancelled' ).length, }; return { content: [ { type: 'text', text: JSON.stringify( { stats, tasks: taskSummaries, filters_applied: { batch_id: args.batch_id || null, status: args.status_filter || null, recent_only: args.recent_only || false, }, }, null, 2 ), }, ], }; }
- src/serve.ts:286-324 (schema)Tool schema definition for 'list_tasks', including name, description, annotations (read-only, etc.), and input schema with optional filters: status_filter (enum), batch_id, recent_only.const LIST_TASKS_TOOL: Tool = { name: 'list_tasks', description: 'List all tasks with their current status.', annotations: { title: 'List All Tasks', readOnlyHint: true, // Only reads task list destructiveHint: false, // Doesn't modify or destroy data idempotentHint: false, // Task list may change between calls openWorldHint: false, // Only queries local task state }, inputSchema: { type: 'object', properties: { status_filter: { type: 'string', description: 'Optional: Filter tasks by status', enum: [ 'pending', 'running', 'completed', 'failed', 'cancelled', ], }, batch_id: { type: 'string', description: 'Optional: Filter tasks by batch ID to only show tasks from a specific batch', }, recent_only: { type: 'boolean', description: 'Optional: Only show tasks from the last 2 hours (default: false)', default: false, }, }, required: [], // All parameters are optional }, };
- src/serve.ts:558-579 (registration)Registration of 'list_tasks' tool via the ListToolsRequestSchema handler, which returns the list of available tools including LIST_TASKS_TOOL.server.setRequestHandler(ListToolsRequestSchema, async () => { if (process.env.MCP_MODE !== 'true') { logger.debug('Received ListTools request'); } const response = { tools: [ RUN_TASK_TOOL, CHECK_TASK_STATUS_TOOL, GET_TASK_RESULT_TOOL, CANCEL_TASK_TOOL, WAIT_FOR_TASK_TOOL, LIST_TASKS_TOOL, ], }; if (process.env.MCP_MODE !== 'true') { logger.debug( 'Returning tools:', response.tools.map(t => t.name) ); } return response; });
- src/utils/task-manager.ts:316-318 (helper)Core helper method TaskManager.getAllTasks() that provides the raw list of all TaskInfo objects used by the list_tasks handler.public getAllTasks(): TaskInfo[] { return Array.from(this.tasks.values()); }