add_todo
Add a new todo item to a markdown file. The tool accepts the todo text as input, enabling AI assistants to manage task lists efficiently.
Instructions
Add a new todo item
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | The todo item text |
Implementation Reference
- src/todoManager.ts:121-151 (handler)Core implementation of the add_todo tool: loads existing todos from markdown file, creates a new TodoItem with generated UUID, appends it, reformats and writes back to file, with error handling for permissions.async addTodo(request: AddTodoRequest): Promise<TodoItem> { const todos = (await this.listTodos()).todos; const newTodo: TodoItem = { id: randomUUID(), text: request.text.trim(), completed: false, createdAt: new Date(), }; todos.push(newTodo); 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 newTodo; }
- src/types.ts:14-16 (schema)TypeScript interface defining the input schema for the add_todo tool: requires a 'text' string.export interface AddTodoRequest { text: string; }
- src/index.ts:49-62 (registration)Tool registration in the ListTools response: defines name 'add_todo', description, and inputSchema matching AddTodoRequest.{ name: 'add_todo', description: 'Add a new todo item', inputSchema: { type: 'object', properties: { text: { type: 'string', description: 'The todo item text', }, }, required: ['text'], additionalProperties: false, },
- src/index.ts:129-144 (handler)MCP CallToolRequest dispatcher case for 'add_todo': performs basic validation and delegates to TodoManager.addTodo, formats success response.case 'add_todo': { const args = request.params.arguments as unknown as AddTodoRequest; if (!args?.text || typeof args.text !== 'string') { throw new Error('Text is required and must be a string'); } const todo = await this.todoManager.addTodo(args); return { content: [ { type: 'text', text: `Todo added successfully: ${JSON.stringify(todo, null, 2)}`, }, ], }; }