delete_task
Remove unfinished tasks from the mcp-chain-of-thought server by specifying their unique task ID, ensuring completed tasks remain intact for record integrity.
Instructions
Delete unfinished tasks, but does not allow deleting completed tasks, ensuring the integrity of system records
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| taskId | Yes | Unique identifier of the task to delete, must be an existing unfinished task ID in the system |
Implementation Reference
- src/tools/taskTools.ts:786-829 (handler)Main handler function for the delete_task tool. Validates input, checks task existence and status, calls the model delete function, and returns a formatted response with prompts.export async function deleteTask({ taskId }: z.infer<typeof deleteTaskSchema>) { const task = await getTaskById(taskId); if (!task) { return { content: [ { type: "text" as const, text: getDeleteTaskPrompt({ taskId }), }, ], isError: true, }; } if (task.status === TaskStatus.COMPLETED) { return { content: [ { type: "text" as const, text: getDeleteTaskPrompt({ taskId, task, isTaskCompleted: true }), }, ], isError: true, }; } const result = await modelDeleteTask(taskId); return { content: [ { type: "text" as const, text: getDeleteTaskPrompt({ taskId, task, success: result.success, message: result.message, }), }, ], isError: !result.success, }; }
- src/tools/taskTools.ts:779-784 (schema)Zod schema for validating the input to the delete_task tool, requiring a valid UUID taskId.export const deleteTaskSchema = z.object({ taskId: z .string() .uuid({ message: "Invalid task ID format, please provide a valid UUID format" }) .describe("Unique identifier of the task to delete, must be an existing unfinished task ID in the system"), });
- src/index.ts:284-289 (registration)Registration of the delete_task tool in the MCP server's list of tools, including name, description from MD file, and input schema.name: "delete_task", description: loadPromptFromTemplate( "toolsDescription/deleteTask.md" ), inputSchema: zodToJsonSchema(deleteTaskSchema), },
- src/models/taskModel.ts:538-574 (helper)Underlying model function (deleteTask, aliased as modelDeleteTask) that performs the actual task deletion from the JSON file, with checks for dependencies and status.export async function deleteTask( taskId: string ): Promise<{ success: boolean; message: string }> { const tasks = await readTasks(); const taskIndex = tasks.findIndex((task) => task.id === taskId); if (taskIndex === -1) { return { success: false, message: "Task not found" }; } // Check task status, completed tasks cannot be deleted if (tasks[taskIndex].status === TaskStatus.COMPLETED) { return { success: false, message: "Cannot delete completed tasks" }; } // Check if other tasks depend on this task const allTasks = tasks.filter((_, index) => index !== taskIndex); const dependentTasks = allTasks.filter((task) => task.dependencies.some((dep) => dep.taskId === taskId) ); if (dependentTasks.length > 0) { const dependentTaskNames = dependentTasks .map((task) => `"${task.name}" (ID: ${task.id})`) .join(", "); return { success: false, message: `Cannot delete this task, because the following tasks depend on it: ${dependentTaskNames}`, }; } // Execute delete operation tasks.splice(taskIndex, 1); await writeTasks(tasks); return { success: true, message: "Task deleted successfully" }; }
- src/index.ts:489-499 (registration)Dispatch handler in the CallToolRequest that parses arguments with the schema and calls the deleteTask handler.case "delete_task": parsedArgs = await deleteTaskSchema.safeParseAsync( request.params.arguments ); if (!parsedArgs.success) { throw new Error( `Invalid arguments for tool ${request.params.name}: ${parsedArgs.error.message}` ); } result = await deleteTask(parsedArgs.data); return result;