taskUpdate
Update existing task information in GonMCPtool, including title, description, due date, priority, status, and tags.
Instructions
更新現有任務信息
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | ||
| updates | Yes |
Implementation Reference
- tools/taskManagerTool.ts:150-174 (handler)Core implementation of the taskUpdate functionality. Loads tasks from JSON file, finds the task by ID, applies updates (excluding id and createdAt, prevents setting to COMPLETED), updates timestamp, and persists changes.public static async updateTask(id: string, updates: Partial<Omit<Task, 'id' | 'createdAt'>>): Promise<Task | null> { const tasks = await this.readTasks(); const taskIndex = tasks.findIndex(t => t.id === id); if (taskIndex === -1) { return null; } // 檢查是否嘗試將任務設置為已完成狀態 if (updates.status === TaskStatus.COMPLETED) { throw new Error('不能使用 updateTask 方法將任務標記為已完成,請使用 completeTask 方法'); } // 更新任務 tasks[taskIndex] = { ...tasks[taskIndex], ...updates, updatedAt: new Date().toISOString() }; // 保存所有任務 await this.writeTasks(tasks); return tasks[taskIndex]; }
- main.ts:647-684 (registration)MCP tool registration for 'taskUpdate', including Zod input schema validation and thin wrapper handler that calls TaskManagerTool.updateTask and formats response.server.tool("taskUpdate", "更新現有任務信息", { id: z.string(), updates: z.object({ title: z.string().optional(), description: z.string().optional(), tags: z.array(z.string()).optional(), dueDate: z.string().optional(), priority: z.number().optional(), status: z.enum([ TaskStatus.PENDING, TaskStatus.IN_PROGRESS, TaskStatus.COMPLETED, TaskStatus.CANCELLED ]).optional() }) }, async ({ id, updates }) => { try { const updatedTask = await TaskManagerTool.updateTask(id, updates); if (!updatedTask) { return { content: [{ type: "text", text: `未找到ID為 ${id} 的任務` }] }; } return { content: [{ type: "text", text: `任務更新成功:\n${JSON.stringify(updatedTask, null, 2)}` }] }; } catch (error) { return { content: [{ type: "text", text: `更新任務失敗: ${error instanceof Error ? error.message : "未知錯誤"}` }] }; } } );
- main.ts:649-664 (schema)Zod schema defining input parameters for taskUpdate tool: task ID and optional updates for title, description, tags, dueDate, priority, status.{ id: z.string(), updates: z.object({ title: z.string().optional(), description: z.string().optional(), tags: z.array(z.string()).optional(), dueDate: z.string().optional(), priority: z.number().optional(), status: z.enum([ TaskStatus.PENDING, TaskStatus.IN_PROGRESS, TaskStatus.COMPLETED, TaskStatus.CANCELLED ]).optional() }) },