todoist_task_delete
Delete a Todoist task using its ID or by searching for a partial name match to remove completed or unwanted items from your task list.
Instructions
Delete a task found by ID or partial name search (case-insensitive)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| task_id | No | Task ID to delete (optional, takes precedence over task_name) | |
| task_name | No | Partial task name to search for deletion (used if task_id not provided) |
Implementation Reference
- src/handlers/task-handlers.ts:461-483 (handler)Core handler function that deletes a Todoist task by ID or partial name. Finds the task, calls the Todoist API deleteTask method, clears cache, handles dry-run mode, and returns confirmation message.export async function handleDeleteTask( todoistClient: TodoistApi, args: any ): Promise<string> { // Handle both snake_case and camelCase const { taskId, taskName } = extractTaskIdentifiers(args); // Validate that at least one identifier is provided validateTaskIdentifier(taskId, taskName); // Clear cache since we're deleting taskCache.clear(); const matchingTask = await findTaskByIdOrName(todoistClient, args); await todoistClient.deleteTask(matchingTask.id); // Check if we're in dry-run mode const isDryRun = process.env.DRYRUN === "true"; const prefix = isDryRun ? "[DRY-RUN] " : ""; return `${prefix}Successfully deleted task: "${matchingTask.content}"`; }
- src/tools/task-tools.ts:174-194 (schema)Defines the MCP Tool schema for todoist_task_delete, including input validation for task_id or task_name.export const DELETE_TASK_TOOL: Tool = { name: "todoist_task_delete", description: "Delete a task found by ID or partial name search (case-insensitive)", inputSchema: { type: "object", properties: { task_id: { type: "string", description: "Task ID to delete (optional, takes precedence over task_name)", }, task_name: { type: "string", description: "Partial task name to search for deletion (used if task_id not provided)", }, }, required: [], }, };
- src/index.ts:170-175 (registration)Registers and routes calls to the todoist_task_delete tool in the MCP server's CallToolRequest handler switch statement.case "todoist_task_delete": if (!isDeleteTaskArgs(args)) { throw new Error("Invalid arguments for todoist_task_delete"); } result = await handleDeleteTask(apiClient, args); break;
- src/handlers/task-handlers.ts:68-116 (helper)Helper function to resolve task identifier (ID or partial name) to a concrete TodoistTask object, used by delete, update, and complete handlers.async function findTaskByIdOrName( todoistClient: TodoistApi, args: any ): Promise<TodoistTask> { // Handle both snake_case and camelCase from MCP framework const { taskId, taskName } = extractTaskIdentifiers(args); if (!taskId && !taskName) { throw new Error( "Either task_id/taskId or task_name/taskName must be provided" ); } let task: TodoistTask | null = null; // Try to find by ID first if provided if (taskId) { try { const response = await todoistClient.getTask(taskId); task = response as TodoistTask; } catch { // If not found by ID, continue to try by name if provided if (!taskName) { ErrorHandler.handleTaskNotFound(`ID: ${taskId}`); } } } // If not found by ID or ID not provided, try by name if (!task && taskName) { const result = await todoistClient.getTasks(); const tasks = extractArrayFromResponse<TodoistTask>(result); const matchingTask = tasks.find((t: TodoistTask) => t.content.toLowerCase().includes(taskName.toLowerCase()) ); if (matchingTask) { task = matchingTask; } else { ErrorHandler.handleTaskNotFound(taskName); } } if (!task) { ErrorHandler.handleTaskNotFound(taskId ? `ID: ${taskId}` : taskName!); } return task!; }
- src/tools/index.ts:62-69 (registration)Includes TASK_TOOLS (containing todoist_task_delete) in the complete list of tools served by the MCP server.export const ALL_TOOLS = [ ...TASK_TOOLS, ...PROJECT_TOOLS, ...COMMENT_TOOLS, ...LABEL_TOOLS, ...SUBTASK_TOOLS, ...TEST_TOOLS, ];