add_todo
Create a new task with title, priority, due date, and tags for organization in the Todokit task management system.
Instructions
Add a new todo item
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| title | Yes | The title of the todo | |
| description | No | Optional description of the todo | |
| priority | No | Priority level (default: normal) | |
| dueDate | No | Due date in ISO format (YYYY-MM-DD) | |
| tags | No | Tags for categorization |
Implementation Reference
- src/tools/add_todo.ts:9-39 (registration)Registers the 'add_todo' MCP tool, including metadata, schemas, and inline handler function that invokes the storage addTodo helper.export function registerAddTodo(server: McpServer): void { server.registerTool( 'add_todo', { title: 'Add Todo', description: 'Add a new todo item', inputSchema: AddTodoSchema, outputSchema: DefaultOutputSchema, annotations: { readOnlyHint: false, idempotentHint: false, }, }, async ({ title, description, priority, dueDate, tags }) => { try { const todo = await addTodo(title, description, priority, dueDate, tags); const structured = { ok: true, result: { item: todo, summary: `Added todo "${todo.title}"`, nextActions: ['list_todos', 'update_todo', 'complete_todo'], }, }; return createToolResponse(structured); } catch (err) { return createErrorResponse('E_ADD_TODO', getErrorMessage(err)); } } ); }
- src/tools/add_todo.ts:22-36 (handler)The inline handler function executing the core logic: calls addTodo storage helper, formats success/error responses.async ({ title, description, priority, dueDate, tags }) => { try { const todo = await addTodo(title, description, priority, dueDate, tags); const structured = { ok: true, result: { item: todo, summary: `Added todo "${todo.title}"`, nextActions: ['list_todos', 'update_todo', 'complete_todo'], }, }; return createToolResponse(structured); } catch (err) { return createErrorResponse('E_ADD_TODO', getErrorMessage(err)); }
- src/schemas/inputs.ts:9-32 (schema)Defines AddTodoSchema (alias for TodoInputSchema) for input validation of title, description, priority, dueDate, tags.const TodoInputSchema = z .object({ title: z.string().min(1).max(200).describe('The title of the todo'), description: z .string() .max(2000) .optional() .describe('Optional description of the todo'), priority: z .enum(['low', 'normal', 'high']) .optional() .describe('Priority level (default: normal)'), dueDate: IsoDateSchema.optional().describe( 'Due date in ISO format (YYYY-MM-DD)' ), tags: z .array(TagSchema) .max(50) .optional() .describe('Tags for categorization'), }) .strict(); export const AddTodoSchema = TodoInputSchema;
- src/lib/storage.ts:254-268 (helper)addTodo helper function invoked by the tool handler; wraps addTodos for single-item addition to persistent storage.export async function addTodo( title: string, description?: string, priority: 'low' | 'normal' | 'high' = 'normal', dueDate?: string, tags: string[] = [] ): Promise<Todo> { const [todo] = await addTodos([ { title, description, priority, dueDate, tags }, ]); if (!todo) { throw new Error('Failed to create todo'); } return todo; }
- src/lib/storage.ts:270-290 (helper)Core storage helper for batch-adding todos: reads existing todos, generates new Todo objects with UUIDs and timestamps, appends and persists to todos.json atomically.export async function addTodos(items: NewTodoInput[]): Promise<Todo[]> { return queueWrite(async () => { const todos = await readTodosFromDisk(); const timestamp = new Date().toISOString(); const newTodos: Todo[] = items.map((item) => ({ id: randomUUID(), title: item.title, description: item.description, completed: false, priority: item.priority ?? 'normal', dueDate: item.dueDate, tags: normalizeTags(item.tags ?? []), createdAt: timestamp, updatedAt: timestamp, completedAt: undefined, })); const nextTodos = [...todos, ...newTodos]; await persistTodos(nextTodos); return newTodos; }); }