deleteTask
Remove a specific task by its ID from the task-orchestrator-mcp server to manage task workflows efficiently.
Instructions
Delete a task by its ID
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | Task ID |
Implementation Reference
- src/task.ts:660-699 (handler)The deleteTask function implements the core logic: validates ID, finds task, checks no children, removes from parent/root, persists changes, returns deleted ID.export function deleteTask(id: string): { id: string } { if (!id || typeof id !== "string") { throw new Error("Task ID is required and must be a string") } const tasks = readTasks() const taskToDelete = findTaskById(tasks, id) if (!taskToDelete) { throw new Error(`Task with id '${id}' not found`) } // Check if task has child tasks if (taskToDelete.tasks.length > 0) { throw new Error( `Cannot delete task '${id}' because it has child tasks. Please delete all child tasks first.`, ) } // Find and remove task from parent's tasks array or root level const parentTask = findParentTask(tasks, id) if (parentTask) { // Remove from parent's tasks array const index = parentTask.tasks.findIndex((t) => t.id === id) if (index !== -1) { parentTask.tasks.splice(index, 1) } } else { // Remove from root level const index = tasks.findIndex((t) => t.id === id) if (index !== -1) { tasks.splice(index, 1) } } writeTasks(tasks) return { id } }
- src/tools.ts:277-318 (registration)Registers the deleteTask tool with the MCP server, providing description, Zod input schema (id: string), and error-handling wrapper that calls the deleteTask function.server.registerTool( "deleteTask", { description: "Delete a task by its ID", inputSchema: { id: z.string().describe("Task ID"), }, }, (args) => { try { const result = deleteTask(args.id) return { content: [ { text: JSON.stringify(result, null, 2), type: "text", }, ], } } catch (error) { return { content: [ { text: JSON.stringify( { error: { code: "TASK_DELETE_ERROR", message: error instanceof Error ? error.message : "Unknown error", }, }, null, 2, ), type: "text", }, ], isError: true, } } }, )
- src/tools.ts:282-283 (schema)Zod input schema for deleteTask tool: requires 'id' as string.id: z.string().describe("Task ID"), },
- src/task.ts:33-44 (helper)Recursive helper to find task by ID in nested structure, used by deleteTask.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 }
- src/task.ts:52-68 (helper)Recursive helper to find parent task of a given task ID, used by deleteTask to locate and remove the task.export function findParentTask( tasks: Task[], targetId: string, ): Task | undefined { for (const task of tasks) { // Check if target is direct child if (task.tasks.some((child) => child.id === targetId)) { return task } // Recursively search in subtasks const parentFound = findParentTask(task.tasks, targetId) if (parentFound) { return parentFound } } return undefined }