deleteTask
Remove a task from the task orchestrator by specifying its unique ID to manage task lists and maintain organization.
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)Core handler function that implements the deleteTask logic: validates the task ID, locates the task in the hierarchy, ensures no child tasks exist, removes the task from its parent or root array, persists the change to storage, and returns the deleted task 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)Registration of the 'deleteTask' MCP tool, including input schema validation (task ID), description, and a thin wrapper handler that invokes the core deleteTask function, formats the response, and handles errors with standardized error format.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:281-283 (schema)Zod input schema for deleteTask tool: requires a string 'id' parameter representing the Task ID.inputSchema: { id: z.string().describe("Task ID"), },