complete-task
Mark tasks as completed using their ID in Todo.txt files via the MCP server, enabling efficient task management without manual editing.
Instructions
Mark a task as completed by its 1-based ID.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| taskId | Yes |
Implementation Reference
- src/tools.ts:63-81 (handler)Handler function that implements the core logic for completing a task: loads tasks, validates task ID via helper, marks task as completed with current date, saves changes, or returns error if task not found.async ({ taskId }) => { const tasks = await loadTasks(); const idx = getTaskIndex(taskId, tasks); if (idx === null) { return { content: [ { type: "text", text: "Task not found." }, ], isError: true, }; } tasks[idx].setCompleted(new Date().toISOString().split("T")[0]); await saveTasks(tasks); return { content: [ { type: "text", text: "Task marked as completed." }, ], }; }
- src/tools.ts:62-62 (schema)Input schema definition using Zod: requires a single numeric 'taskId' parameter (1-based index).{ taskId: z.number() },
- src/tools.ts:59-82 (registration)Registration of the 'complete-task' tool on the McpServer instance, including name, description, schema, and inline handler function.server.tool( "complete-task", "Mark a task as completed 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: "Task not found." }, ], isError: true, }; } tasks[idx].setCompleted(new Date().toISOString().split("T")[0]); await saveTasks(tasks); return { content: [ { type: "text", text: "Task marked as completed." }, ], }; } );
- src/tools.ts:13-18 (helper)Helper function to convert 1-based taskId to 0-based array index, returns null if invalid, used by complete-task and other task tools.// Helper: Convert 1-based taskId to 0-based index, return null if out of bounds function getTaskIndex(taskId: number, tasks: Item[]): number | null { const idx = taskId - 1; if (idx < 0 || idx >= tasks.length) return null; return idx; }