update_todo
Modify an existing todo item by updating its text or completion status using its unique ID, ensuring accurate task management in the Todo Markdown MCP Server.
Instructions
Update an existing todo item
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| completed | No | Whether the todo is completed | |
| id | Yes | The todo item ID | |
| text | No | New text for the todo item |
Implementation Reference
- src/todoManager.ts:153-196 (handler)The core handler function that finds the todo by ID, updates its text or completion status, rewrites the markdown file, and returns the updated todo item.async updateTodo(request: UpdateTodoRequest): Promise<TodoItem> { const todos = (await this.listTodos()).todos; const todoIndex = todos.findIndex((todo) => todo.id === request.id); if (todoIndex === -1) { throw new Error(`Todo with id ${request.id} not found`); } const todo = todos[todoIndex]!; if (request.text !== undefined) { todo.text = request.text.trim(); } if (request.completed !== undefined) { todo.completed = request.completed; if (request.completed && !todo.completedAt) { todo.completedAt = new Date(); } else if (!request.completed) { delete todo.completedAt; } } todos[todoIndex] = todo; const markdown = this.formatTodoMarkdown(todos); try { await writeFile(this.todoFilePath, markdown, 'utf-8'); } catch (error) { if (error instanceof Error && error.message.includes('EACCES')) { throw new Error( `Permission denied: Cannot write to ${this.todoFilePath}. Check file permissions or set TODO_FILE_PATH environment variable to a writable location.` ); } else if (error instanceof Error && error.message.includes('EROFS')) { throw new Error( `Read-only file system: Cannot write to ${this.todoFilePath}. Set TODO_FILE_PATH environment variable to a writable location.` ); } throw error; } return todo; }
- src/types.ts:18-22 (schema)TypeScript interface defining the input parameters for the update_todo tool.export interface UpdateTodoRequest { id: string; text?: string; completed?: boolean; }
- src/index.ts:64-86 (registration)Tool registration in the ListTools response, specifying name, description, and input schema matching UpdateTodoRequest.{ name: 'update_todo', description: 'Update an existing todo item', inputSchema: { type: 'object', properties: { id: { type: 'string', description: 'The todo item ID', }, text: { type: 'string', description: 'New text for the todo item', }, completed: { type: 'boolean', description: 'Whether the todo is completed', }, }, required: ['id'], additionalProperties: false, }, },
- src/index.ts:146-162 (handler)MCP server handler for CallToolRequest that validates input, delegates to TodoManager.updateTodo, and formats the response.case 'update_todo': { const args = request.params .arguments as unknown as UpdateTodoRequest; if (!args?.id || typeof args.id !== 'string') { throw new Error('ID is required and must be a string'); } const todo = await this.todoManager.updateTodo(args); return { content: [ { type: 'text', text: `Todo updated successfully: ${JSON.stringify(todo, null, 2)}`, }, ], }; }