Skip to main content
Glama

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
NameRequiredDescriptionDefault
titleYes

Implementation Reference

  • 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}` }] };
    }
  • 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}` }] };
      }
    );
  • 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 [];
      }
    }
  • 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");
    }
Install Server

Other 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/CalamityAdam/mcp-todo'

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