update_todo
Modify existing todo items by updating titles, descriptions, completion status, priority levels, or tags to keep tasks current and organized.
Instructions
Update an existing todo item
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | UUID of the todo to update | |
| title | No | New title | |
| description | No | New description | |
| completed | No | Mark as completed or not | |
| priority | No | New priority level | |
| tags | No | New tags |
Implementation Reference
- src/handlers/toolHandlers.ts:94-130 (handler)The main tool handler for 'update_todo' that sanitizes and validates input using UpdateTodoSchema, calls the todo service to update the todo, handles errors, and returns a formatted MCP response.
async handleUpdateTodo(request: CallToolRequest): Promise<CallToolResult> { try { const sanitizedArgs = sanitizeInput(request.params.arguments); const validatedRequest = validateData(UpdateTodoSchema, sanitizedArgs); const todo = this.todoService.updateTodo(validatedRequest); if (!todo) { return { content: [ { type: "text", text: `❌ Todo com ID ${validatedRequest.id} não encontrado`, }, ], }; } return { content: [ { type: "text", text: `✅ Todo atualizado com sucesso!\n\n${JSON.stringify(todo, null, 2)}`, }, ], }; } catch (error) { const errorResponse = createErrorResponse(error, "atualizar todo"); return { content: [ { type: "text", text: `❌ ${errorResponse.error}\n${errorResponse.details || ""}`, }, ], }; } } - src/schemas/todo.schemas.ts:26-33 (schema)Zod schema defining the input structure and validation rules for the update_todo tool, including optional fields for partial updates.
export const UpdateTodoSchema = z.object({ id: UuiSchema, title: NonEmptyStringSchema.max(200, 'Título não pode exceder 200 caracteres').optional(), description: z.string().max(500).optional(), completed: z.boolean().optional(), priority: z.enum(['low', 'medium', 'high']).optional(), tags: z.array(z.string().min(1).max(50)).max(10).optional() }); - src/config/toolDefinitions.ts:36-76 (registration)Registration of the 'update_todo' tool in the TOOL_DEFINITIONS array, including name, description, and JSON schema for input validation.
{ name: "update_todo", description: "Update an existing todo item", inputSchema: { type: "object", properties: { id: { type: "string", format: "uuid", description: "UUID of the todo to update", }, title: { type: "string", minLength: 1, maxLength: 200, description: "New title", }, description: { type: "string", maxLength: 1000, description: "New description", }, completed: { type: "boolean", description: "Mark as completed or not", }, priority: { type: "string", enum: ["low", "medium", "high"], description: "New priority level", }, tags: { type: "array", items: { type: "string", minLength: 1, maxLength: 50 }, maxItems: 10, description: "New tags", }, }, required: ["id"], }, }, - Core service method that validates the update request, merges partial updates into the existing todo, updates the in-memory store, and returns the updated todo or null if not found.
updateTodo(request: UpdateTodoRequest): Todo | null { // Validar entrada const validatedRequest = validateData(UpdateTodoSchema, request); const existingTodo = this.todos.get(validatedRequest.id); if (!existingTodo) { return null; } const updatedTodo: Todo = { ...existingTodo, ...(validatedRequest.title !== undefined && { title: validatedRequest.title }), ...(validatedRequest.description !== undefined && { description: validatedRequest.description }), ...(validatedRequest.priority !== undefined && { priority: validatedRequest.priority }), ...(validatedRequest.tags !== undefined && { tags: validatedRequest.tags }), ...(validatedRequest.completed !== undefined && { completed: validatedRequest.completed, completedAt: validatedRequest.completed ? new Date() : undefined }) }; this.todos.set(validatedRequest.id, updatedTodo); return updatedTodo; }