update_task
Modify existing task details including title, description, priority, category, due date, and status to keep task information current and accurate.
Instructions
Update an existing task
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| category | No | New category | |
| description | No | New description | |
| dueDate | No | New due date (YYYY-MM-DD) | |
| priority | No | New priority | |
| status | No | New status | |
| taskId | Yes | Task ID (use first 8 characters) | |
| title | No | New title |
Implementation Reference
- src/tools.ts:129-189 (handler)The main handler function that executes the update_task tool logic: parses arguments with UpdateTaskSchema, loads tasks from storage, finds task by partial ID, updates specified fields, handles status changes including completedAt timestamp, saves changes, and returns a formatted success message with the updated task.export async function updateTask(args: unknown) { // Validate input const validated = UpdateTaskSchema.parse(args); // Load tasks const storage = await loadTasks(); // Find task by ID (partial match) const taskIndex = storage.tasks.findIndex((t) => t.id.startsWith(validated.taskId) ); if (taskIndex === -1) { return { content: [ { type: "text", text: `❌ Task with ID ${validated.taskId} not found.`, }, ], }; } const task = storage.tasks[taskIndex]!; // Update fields if provided if (validated.title !== undefined) { task.title = validated.title; } if (validated.description !== undefined) { task.description = validated.description; } if (validated.priority !== undefined) { task.priority = validated.priority as Priority; } if (validated.category !== undefined) { task.category = validated.category; } if (validated.dueDate !== undefined) { task.dueDate = validated.dueDate; } if (validated.status !== undefined) { task.status = validated.status as Status; if (validated.status === "completed" && !task.completedAt) { task.completedAt = new Date().toISOString(); } else if (validated.status !== "completed") { task.completedAt = undefined; } } await saveTasks(storage); return { content: [ { type: "text", text: `✅ Task updated successfully!\n\n${formatTask(task)}`, }, ], }; }
- src/types.ts:48-59 (schema)Zod schema defining the input shape and validation rules for the update_task tool, used internally in the handler to parse and validate arguments.export const UpdateTaskSchema = z.object({ taskId: z.string().min(8, "Task ID must be at least 8 characters"), title: z.string().optional(), description: z.string().optional(), priority: z.enum(["low", "medium", "high"]).optional(), category: z.string().optional(), dueDate: z .string() .regex(/^\d{4}-\d{2}-\d{2}$/, "Date must be YYYY-MM-DD") .optional(), status: z.enum(["pending", "in_progress", "completed"]).optional(), });
- src/index.ts:84-125 (registration)Tool registration in the MCP server's TOOLS array, providing name, description, and inputSchema for the update_task tool to be discoverable and callable by clients.{ name: "update_task", description: "Update an existing task", inputSchema: { type: "object", properties: { taskId: { type: "string", description: "Task ID (use first 8 characters)", minLength: 8, }, title: { type: "string", description: "New title", }, description: { type: "string", description: "New description", }, priority: { type: "string", enum: ["low", "medium", "high"], description: "New priority", }, category: { type: "string", description: "New category", }, dueDate: { type: "string", pattern: "^\\d{4}-\\d{2}-\\d{2}$", description: "New due date (YYYY-MM-DD)", }, status: { type: "string", enum: ["pending", "in_progress", "completed"], description: "New status", }, }, required: ["taskId"], }, },
- src/index.ts:221-222 (registration)Dispatch case in the server's CallToolRequestHandler switch statement that routes 'update_task' calls to the updateTask handler function.case "update_task": return await updateTask(args);