list_todos
Retrieve and display all todo items from a markdown file, enabling efficient task tracking and management within a structured environment.
Instructions
List all todos from the markdown file
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/todoManager.ts:97-119 (handler)Core handler function for list_todos tool. Reads todo.md file, parses markdown checkboxes into TodoItem objects using parseTodoMarkdown, calculates stats, and returns structured ListTodosResponse.async listTodos(): Promise<ListTodosResponse> { if (!(await this.fileExists())) { return { todos: [], total: 0, completed: 0, pending: 0, }; } const content = await readFile(this.todoFilePath, 'utf-8'); const todos = this.parseTodoMarkdown(content); const completed = todos.filter((todo) => todo.completed).length; const pending = todos.length - completed; return { todos, total: todos.length, completed, pending, }; }
- src/index.ts:41-48 (registration)Tool registration in ListTools response, including name 'list_todos', description, and empty input schema (no parameters).name: 'list_todos', description: 'List all todos from the markdown file', inputSchema: { type: 'object', properties: {}, additionalProperties: false, }, },
- src/index.ts:117-127 (handler)MCP server CallToolRequest handler case for 'list_todos' that delegates to todoManager.listTodos() and returns JSON-stringified result as text content.case 'list_todos': { const result = await this.todoManager.listTodos(); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; }
- src/types.ts:28-33 (schema)TypeScript interface defining the output structure returned by listTodos handler.export interface ListTodosResponse { todos: TodoItem[]; total: number; completed: number; pending: number; }
- src/types.ts:1-7 (schema)TypeScript interface for individual todo items parsed from markdown.export interface TodoItem { id: string; text: string; completed: boolean; createdAt: Date; completedAt?: Date; }
- src/todoManager.ts:44-83 (helper)Helper function to parse markdown lines into TodoItem array, matching checkbox format and extracting/comment IDs.private parseTodoMarkdown(content: string): TodoItem[] { const lines = content.split('\n'); const todos: TodoItem[] = []; for (const line of lines) { const trimmed = line.trim(); // Match markdown checkbox format: - [ ] text or - [x] text const checkboxMatch = trimmed.match(/^-\s*\[([x\s])\]\s*(.+)$/i); if (checkboxMatch) { const [, checkbox, text] = checkboxMatch; if (!checkbox || !text) continue; const completed = checkbox.toLowerCase() === 'x'; // Extract ID from text if it exists (format: text <!-- id:uuid -->) const idMatch = text.match(/^(.*?)\s*<!--\s*id:([a-f0-9-]+)\s*-->$/); let todoText: string; let id: string; if (idMatch) { todoText = idMatch[1]?.trim() || ''; id = idMatch[2] || randomUUID(); } else { todoText = text.trim(); id = randomUUID(); } todos.push({ id, text: todoText, completed, createdAt: new Date(), ...(completed && { completedAt: new Date() }), }); } } return todos; }