delete_task
Remove obsolete or completed tasks safely with built-in confirmation protection, maintaining a clean task environment and preventing accidental data loss.
Instructions
Streamline your workflow by safely removing obsolete or completed tasks with built-in confirmation protection. Maintain a clean, focused task environment while preventing accidental data loss through required confirmation safeguards.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| confirm | Yes | Must be set to true to confirm deletion (safety measure) | |
| id | Yes | The unique identifier of the task to delete | |
| workingDirectory | Yes | The full absolute path to the working directory where data is stored. MUST be an absolute path, never relative. Windows: "C:\Users\username\project" or "D:\projects\my-app". Unix/Linux/macOS: "/home/username/project" or "/Users/username/project". Do NOT use: ".", "..", "~", "./folder", "../folder" or any relative paths. Ensure the path exists and is accessible before calling this tool. NOTE: When server is started with --claude flag, this parameter is ignored and a global user directory is used instead. |
Implementation Reference
- The factory function that creates the 'delete_task' MCP tool handler. Defines the tool name, description, input schema (id: string, confirm: boolean), and the async handler logic including validation, task lookup, deletion via storage, and formatted responses.export function createDeleteTaskTool(storage: Storage) { return { name: 'delete_task', description: 'Delete a task and all its associated subtasks. This action cannot be undone.', inputSchema: { id: z.string(), confirm: z.boolean() }, handler: async ({ id, confirm }: { id: string; confirm: boolean }) => { try { // Validate inputs if (!id || id.trim().length === 0) { return { content: [{ type: 'text' as const, text: 'Error: Task ID is required.' }], isError: true }; } if (confirm !== true) { return { content: [{ type: 'text' as const, text: 'Error: You must set confirm to true to delete a task.' }], isError: true }; } const task = await storage.getTask(id.trim()); if (!task) { return { content: [{ type: 'text' as const, text: `Error: Task with ID "${id}" not found. Use list_tasks to see all available tasks.` }], isError: true }; } // Get project information for display const project = await storage.getProject(task.projectId); const projectName = project ? project.name : 'Unknown Project'; // Get count of subtasks for confirmation message const subtasks = await storage.getSubtasks(task.id); const deleted = await storage.deleteTask(id); if (!deleted) { return { content: [{ type: 'text' as const, text: `Error: Failed to delete task with ID "${id}".` }], isError: true }; } return { content: [{ type: 'text' as const, text: `✅ Task deleted successfully! **Deleted:** "${task.name}" (ID: ${task.id}) **Project:** ${projectName} **Also deleted:** ${subtasks.length} subtask(s) This action cannot be undone. All data associated with this task has been permanently removed.` }] }; } catch (error) { return { content: [{ type: 'text' as const, text: `Error deleting task: ${error instanceof Error ? error.message : 'Unknown error'}` }], isError: true }; } } }; }
- src/features/task-management/tools/tasks/index.ts:235-245 (registration)The function that creates and registers the 'delete_task' tool as part of the task management tools suite by calling createDeleteTaskTool and including it in the returned tools object.export function createTaskTools(storage: Storage) { return { create_task: createCreateTaskTool(storage), delete_task: createDeleteTaskTool(storage), get_task: createGetTaskTool(storage), list_tasks: createListTasksTool(storage), update_task: createUpdateTaskTool(storage), migrate_subtasks: createMigrateSubtasksTool(storage), move_task: createMoveTaskTool(storage) }; }
- Zod schema definition for the delete_task tool inputs: task ID (string) and confirmation boolean.inputSchema: { id: z.string(), confirm: z.boolean() },
- Storage interface defining the deleteTask method used by the tool handler.deleteTask(id: string): Promise<boolean>; deleteTasksByProject(projectId: string): Promise<number>; deleteTasksByParent(parentId: string): Promise<number>; // Task hierarchy operations getTaskHierarchy(projectId?: string, parentId?: string): Promise<TaskHierarchy[]>; getTaskChildren(taskId: string): Promise<Task[]>; getTaskAncestors(taskId: string): Promise<Task[]>;
- Concrete implementation of deleteTask in FileStorage, which recursively deletes child tasks and removes the task from storage.async deleteTask(id: string): Promise<boolean> { const index = this.data.tasks.findIndex(t => t.id === id); if (index === -1) return false; // Delete all child tasks recursively await this.deleteTasksByParent(id); this.data.tasks.splice(index, 1); await this.save(); return true; }