list_tasks
Retrieve tasks from the Task Manager MCP Server with filters for status, priority, and category to organize and track workflow.
Instructions
List tasks with optional filters
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| status | No | Filter by status | all |
| priority | No | Filter by priority | all |
| category | No | Filter by category |
Implementation Reference
- src/tools.ts:53-124 (handler)The handler function that executes the list_tasks tool logic: validates input, loads and filters tasks, sorts them, formats output with summary, and returns MCP content.
export async function listTasks(args: unknown) { // Validate input const validated = ListTasksSchema.parse(args || {}); // Load tasks const storage = await loadTasks(); let tasks = [...storage.tasks]; // Apply filters if (validated.status !== "all") { tasks = tasks.filter((t) => t.status === validated.status); } if (validated.priority !== "all") { tasks = tasks.filter((t) => t.priority === validated.priority); } if (validated.category) { tasks = tasks.filter( (t) => t.category?.toLowerCase() === validated.category?.toLowerCase() ); } if (tasks.length === 0) { return { content: [ { type: "text", text: "No tasks found matching the criteria.", }, ], }; } // Sort by priority and due date const priorityOrder: Record<Priority, number> = { high: 0, medium: 1, low: 2, }; tasks.sort((a, b) => { const priorityDiff = priorityOrder[a.priority] - priorityOrder[b.priority]; if (priorityDiff !== 0) return priorityDiff; const aDate = a.dueDate || "9999-99-99"; const bDate = b.dueDate || "9999-99-99"; return aDate.localeCompare(bDate); }); // Format output let result = `š Found ${tasks.length} task(s):\n\n`; tasks.forEach((task) => { result += formatTask(task) + "\n"; }); // Add summary const pending = storage.tasks.filter((t) => t.status === "pending").length; const inProgress = storage.tasks.filter( (t) => t.status === "in_progress" ).length; const completed = storage.tasks.filter((t) => t.status === "completed").length; result += `\nš Summary: ${pending} pending | ${inProgress} in progress | ${completed} completed`; return { content: [ { type: "text", text: result, }, ], }; } - src/types.ts:40-46 (schema)Zod schema used for input validation in the listTasks handler.
export const ListTasksSchema = z.object({ status: z .enum(["pending", "in_progress", "completed", "all"]) .default("all"), priority: z.enum(["low", "medium", "high", "all"]).default("all"), category: z.string().optional(), }); - src/index.ts:59-83 (registration)Tool registration in the TOOLS array returned by listTools, including name, description, and inputSchema.
{ name: "list_tasks", description: "List tasks with optional filters", inputSchema: { type: "object", properties: { status: { type: "string", enum: ["pending", "in_progress", "completed", "all"], default: "all", description: "Filter by status", }, priority: { type: "string", enum: ["low", "medium", "high", "all"], default: "all", description: "Filter by priority", }, category: { type: "string", description: "Filter by category", }, }, }, }, - src/index.ts:218-219 (registration)Dispatch to the listTasks handler in the CallToolRequest switch statement.
case "list_tasks": return await listTasks(args);