taskDelete
Remove a specific task by its ID using the delete function on the MCP server. Streamline task management by eliminating unnecessary or completed tasks.
Instructions
刪除指定ID的任務
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes |
Implementation Reference
- main.ts:687-709 (registration)Registration of the 'taskDelete' MCP tool, including description, Zod input schema { id: z.string() }, and inline handler function that delegates to TaskManagerTool.deleteTask(id) and handles responses.server.tool("taskDelete", "刪除指定ID的任務", { id: z.string() }, async ({ id }) => { try { const result = await TaskManagerTool.deleteTask(id); if (!result) { return { content: [{ type: "text", text: `未找到ID為 ${id} 的任務` }] }; } return { content: [{ type: "text", text: `任務已成功刪除` }] }; } catch (error) { return { content: [{ type: "text", text: `刪除任務失敗: ${error instanceof Error ? error.message : "未知錯誤"}` }] }; } } );
- main.ts:690-708 (handler)The core handler function for the taskDelete tool, which calls the helper TaskManagerTool.deleteTask(id), checks result, and returns success or error messages in MCP format.async ({ id }) => { try { const result = await TaskManagerTool.deleteTask(id); if (!result) { return { content: [{ type: "text", text: `未找到ID為 ${id} 的任務` }] }; } return { content: [{ type: "text", text: `任務已成功刪除` }] }; } catch (error) { return { content: [{ type: "text", text: `刪除任務失敗: ${error instanceof Error ? error.message : "未知錯誤"}` }] }; } }
- tools/taskManagerTool.ts:210-224 (helper)TaskManagerTool.deleteTask(id): the underlying helper method that loads tasks from JSON file, filters out the task by ID, writes back the updated list, returns true if deleted.public static async deleteTask(id: string): Promise<boolean> { const tasks = await this.readTasks(); const initialLength = tasks.length; const filteredTasks = tasks.filter(t => t.id !== id); if (filteredTasks.length === initialLength) { return false; } // 保存所有任務 await this.writeTasks(filteredTasks); return true; }