add_todo
Add a new task to your todo list by providing a title, enabling persistent task management through natural language commands.
Instructions
Add a todo item
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| title | Yes |
Implementation Reference
- src/server.ts:79-85 (handler)The handler function that implements the add_todo tool logic: loads todos, generates next ID, appends new todo with given title (done=false), saves to file, returns success message.async ({ title }) => { const todos = await readTodos(); const id = (todos.at(-1)?.id ?? 0) + 1; todos.push({ id, title, done: false }); await writeTodos(todos); return { content: [{ type: "text", text: `Added #${id}: ${title}` }] }; }
- src/server.ts:77-77 (schema)Input schema definition for the add_todo tool, validating the 'title' parameter as a non-empty string.inputSchema: { title: z.string().min(1) },
- src/server.ts:72-86 (registration)The server.registerTool call that registers the 'add_todo' tool with its schema and handler.server.registerTool( "add_todo", { title: "Add Todo", description: "Add a todo item", inputSchema: { title: z.string().min(1) }, }, async ({ title }) => { const todos = await readTodos(); const id = (todos.at(-1)?.id ?? 0) + 1; todos.push({ id, title, done: false }); await writeTodos(todos); return { content: [{ type: "text", text: `Added #${id}: ${title}` }] }; } );
- src/server.ts:20-27 (helper)Helper function to read the list of todos from the persistent JSON file, returning empty array if not found.async function readTodos(): Promise<Todo[]> { try { const s = await fs.readFile(DB_PATH, "utf-8"); return JSON.parse(s); } catch { return []; } }
- src/server.ts:28-30 (helper)Helper function to persist the list of todos to the JSON file.async function writeTodos(todos: Todo[]) { await fs.writeFile(DB_PATH, JSON.stringify(todos, null, 2), "utf-8"); }