listTasks
Retrieve tasks from a hierarchical structure, showing root tasks by default or filtering to display direct children of a specified parent task.
Instructions
List tasks from hierarchical structure, optionally filtered by parentId. Returns root tasks if no parentId specified, or direct children of specified parent task.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| parentId | No | Filter tasks by parent ID to get direct children (optional, returns root tasks if not specified) |
Implementation Reference
- src/task.ts:575-591 (handler)Core implementation of listTasks: reads all tasks from storage and returns either root tasks (if no parentId) or direct children of the specified parent task.export function listTasks(params?: { parentId?: string }): Task[] { const tasks = readTasks() if (!params?.parentId) { // Return root level tasks return tasks } // Find the parent task and return its direct children const parentTask = findTaskById(tasks, params.parentId) if (!parentTask) { // Return empty array for non-existent parent (graceful handling) return [] } return parentTask.tasks }
- src/tools.ts:161-209 (registration)Registers the 'listTasks' tool with the MCP server, defining its input schema (optional parentId) and a thin wrapper handler that calls the core listTasks function and formats the response.// Register listTasks tool server.registerTool( "listTasks", { description: "List tasks from hierarchical structure, optionally filtered by parentId. Returns root tasks if no parentId specified, or direct children of specified parent task.", inputSchema: { parentId: z .string() .describe( "Filter tasks by parent ID to get direct children (optional, returns root tasks if not specified)", ) .optional(), }, }, (args) => { try { const tasks = listTasks(args) return { content: [ { text: JSON.stringify({ tasks }, null, 2), type: "text", }, ], } } catch (error) { return { content: [ { text: JSON.stringify( { error: { code: "TASK_LIST_ERROR", message: error instanceof Error ? error.message : "Unknown error", }, }, null, 2, ), type: "text", }, ], isError: true, } } }, )
- src/tools.ts:168-174 (schema)Zod input schema for listTasks tool: optional parentId string to filter children.parentId: z .string() .describe( "Filter tasks by parent ID to get direct children (optional, returns root tasks if not specified)", ) .optional(), },
- src/task.ts:33-44 (helper)Helper function used by listTasks to find parent task by ID in the nested task hierarchy.export function findTaskById(tasks: Task[], id: string): Task | undefined { for (const task of tasks) { if (task.id === id) { return task } const found = findTaskById(task.tasks, id) if (found) { return found } } return undefined }