Skip to main content
Glama

update-task

Modify task details in Todo.txt files using the specified task ID. Update description, priority, contexts, projects, or custom metadata to keep tasks organized and current.

Instructions

Update a task's fields (description, priority, contexts, projects, metadata) by ID.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
taskIdYes
updatesYes

Implementation Reference

  • Handler function that updates a specific task by its 1-based ID. It loads tasks, validates ID using getTaskIndex, modifies description, priority, contexts (replace), projects (replace), extensions, saves changes, and returns success or error.
    async ({ taskId, updates }) => { const tasks = await loadTasks(); const idx = getTaskIndex(taskId, tasks); if (idx === null) { return { content: [ { type: "text", text: "Invalid task ID." }, ], isError: true, }; } const task = tasks[idx]; if (updates.description) task.setBody(updates.description); if (updates.priority) task.setPriority(updates.priority); if (updates.contexts) { task.contexts().forEach((context: string) => task.removeContext(context)); updates.contexts.forEach((context: string) => task.addContext(context)); } if (updates.projects) { task.projects().forEach((project: string) => task.removeProject(project)); updates.projects.forEach((project: string) => task.addProject(project)); } if (updates.extensions) { Object.entries(updates.extensions).forEach(([key, value]) => task.setExtension(key as string, value as string)); } await saveTasks(tasks); return { content: [ { type: "text", text: "Task updated successfully." }, ], }; }
  • Input schema using Zod: requires taskId (number), updates object with optional fields for description (string), priority (string), contexts (array of strings), projects (array of strings), extensions (record of string to string).
    { taskId: z.number(), updates: z.object({ description: z.string().optional(), priority: z.string().optional(), contexts: z.array(z.string()).optional(), projects: z.array(z.string()).optional(), extensions: z.record(z.string(), z.string()).optional(), }), },
  • src/tools.ts:368-414 (registration)
    Tool registration via server.tool() call, specifying name 'update-task', description, input schema, and handler function.
    server.tool( "update-task", "Update a task's fields (description, priority, contexts, projects, metadata) by ID.", { taskId: z.number(), updates: z.object({ description: z.string().optional(), priority: z.string().optional(), contexts: z.array(z.string()).optional(), projects: z.array(z.string()).optional(), extensions: z.record(z.string(), z.string()).optional(), }), }, async ({ taskId, updates }) => { const tasks = await loadTasks(); const idx = getTaskIndex(taskId, tasks); if (idx === null) { return { content: [ { type: "text", text: "Invalid task ID." }, ], isError: true, }; } const task = tasks[idx]; if (updates.description) task.setBody(updates.description); if (updates.priority) task.setPriority(updates.priority); if (updates.contexts) { task.contexts().forEach((context: string) => task.removeContext(context)); updates.contexts.forEach((context: string) => task.addContext(context)); } if (updates.projects) { task.projects().forEach((project: string) => task.removeProject(project)); updates.projects.forEach((project: string) => task.addProject(project)); } if (updates.extensions) { Object.entries(updates.extensions).forEach(([key, value]) => task.setExtension(key as string, value as string)); } await saveTasks(tasks); return { content: [ { type: "text", text: "Task updated successfully." }, ], }; } );
  • Helper to convert 1-based taskId to 0-based array index, returns null if out of bounds. Used in update-task handler.
    function getTaskIndex(taskId: number, tasks: Item[]): number | null { const idx = taskId - 1; if (idx < 0 || idx >= tasks.length) return null; return idx; }
  • Helper to persist tasks to TODO_FILE_PATH by converting to strings and writing file. Used in update-task handler.
    async function saveTasks(tasks: Item[]) { const content = tasks.map((task) => task.toString()).join("\n"); await fs.writeFile(TODO_FILE_PATH, content, "utf-8"); }

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/guifelix/mcp-server-todotxt'

If you have feedback or need assistance with the MCP directory API, please join our Discord server