Skip to main content
Glama

add-metadata

Add custom metadata (key-value pairs) to specific tasks in Todo.txt files using task ID, enabling enhanced task management and categorization.

Instructions

Add custom metadata (key-value pairs) to a task by ID.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
metadataYes
taskIdYes

Implementation Reference

  • src/tools.ts:221-249 (registration)
    Full registration of the 'add-metadata' MCP tool, including name, description, input schema, and inline handler function.
    server.tool( "add-metadata", "Add custom metadata (key-value pairs) to a task by ID.", { taskId: z.number(), metadata: z.record(z.string()), }, async ({ taskId, metadata }) => { const tasks = await loadTasks(); const idx = getTaskIndex(taskId, tasks); if (idx === null) { return { content: [ { type: "text", text: "Invalid task ID." }, ], isError: true, }; } Object.entries(metadata).forEach(([key, value]) => { tasks[idx].setExtension(key as string, value as string); }); await saveTasks(tasks); return { content: [ { type: "text", text: "Metadata added successfully." }, ], }; } );
  • Handler logic for 'add-metadata': loads tasks, validates task ID, sets extensions (metadata key-values) on the task using jstodotxt Item.setExtension, persists changes with saveTasks.
    async ({ taskId, metadata }) => { const tasks = await loadTasks(); const idx = getTaskIndex(taskId, tasks); if (idx === null) { return { content: [ { type: "text", text: "Invalid task ID." }, ], isError: true, }; } Object.entries(metadata).forEach(([key, value]) => { tasks[idx].setExtension(key as string, value as string); }); await saveTasks(tasks); return { content: [ { type: "text", text: "Metadata added successfully." }, ], }; }
  • Input schema using Zod: taskId as number (1-based), metadata as object of string keys to string values.
    { taskId: z.number(), metadata: z.record(z.string()), },
  • Shared helper function used by the add-metadata handler (and others) to map 1-based task ID to 0-based array index.
    function getTaskIndex(taskId: number, tasks: Item[]): number | null { const idx = taskId - 1; if (idx < 0 || idx >= tasks.length) return null; return idx;

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