delete-task
Remove a task from your Todo.txt file by specifying its 1-based ID using a server-integrated tool for task management.
Instructions
Delete a task by its 1-based ID.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| taskId | Yes |
Implementation Reference
- src/tools.ts:88-106 (handler)The handler function for the 'delete-task' tool. It loads the tasks, converts the 1-based taskId to index, validates it, removes the task using splice, saves the tasks, and returns a success message or error if invalid ID.async ({ taskId }) => { const tasks = await loadTasks(); const idx = getTaskIndex(taskId, tasks); if (idx === null) { return { content: [ { type: "text", text: "Invalid task ID." }, ], isError: true, }; } tasks.splice(idx, 1); await saveTasks(tasks); return { content: [ { type: "text", text: "Task deleted successfully." }, ], }; }
- src/tools.ts:87-87 (schema)Input schema for the 'delete-task' tool, requiring a numeric taskId.{ taskId: z.number() },
- src/tools.ts:84-107 (registration)Registration of the 'delete-task' tool on the MCP server within the registerTools function.server.tool( "delete-task", "Delete a task by its 1-based ID.", { taskId: z.number() }, async ({ taskId }) => { const tasks = await loadTasks(); const idx = getTaskIndex(taskId, tasks); if (idx === null) { return { content: [ { type: "text", text: "Invalid task ID." }, ], isError: true, }; } tasks.splice(idx, 1); await saveTasks(tasks); return { content: [ { type: "text", text: "Task deleted successfully." }, ], }; } );
- src/tools.ts:14-18 (helper)Helper function used by delete-task (and others) to convert 1-based task ID to 0-based array index, returning null if invalid.function getTaskIndex(taskId: number, tasks: Item[]): number | null { const idx = taskId - 1; if (idx < 0 || idx >= tasks.length) return null; return idx; }