Skip to main content
Glama

toggle_todo

Change the completion status of a specific todo item by its ID in the MCP Todo server's persistent task list.

Instructions

Toggle a todo by id

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYes

Implementation Reference

  • Executes the toggle_todo tool: loads todos, finds the todo by ID, flips its 'done' status, saves the list, and returns a confirmation or error message.
    async ({ id }) => {
      const todos = await readTodos();
      const i = todos.findIndex((t) => t.id === id);
      if (i === -1)
        return { content: [{ type: "text", text: `No todo with id ${id}` }] };
      const todo = todos[i]!;
      todo.done = !todo.done;
      await writeTodos(todos);
      return {
        content: [
          {
            type: "text",
            text: `Toggled #${id} to ${todo.done ? "done" : "not done"}`,
          },
        ],
      };
    }
  • Tool metadata and input schema for toggle_todo: requires a positive integer 'id'.
    {
      title: "Toggle Todo",
      description: "Toggle a todo by id",
      inputSchema: { id: z.number().int().positive() },
    },
  • src/server.ts:88-112 (registration)
    Registers the toggle_todo tool on the MCP server with schema and handler function.
    server.registerTool(
      "toggle_todo",
      {
        title: "Toggle Todo",
        description: "Toggle a todo by id",
        inputSchema: { id: z.number().int().positive() },
      },
      async ({ id }) => {
        const todos = await readTodos();
        const i = todos.findIndex((t) => t.id === id);
        if (i === -1)
          return { content: [{ type: "text", text: `No todo with id ${id}` }] };
        const todo = todos[i]!;
        todo.done = !todo.done;
        await writeTodos(todos);
        return {
          content: [
            {
              type: "text",
              text: `Toggled #${id} to ${todo.done ? "done" : "not done"}`,
            },
          ],
        };
      }
    );
  • Helper functions readTodos and writeTodos for loading and saving the todo list from/to JSON file, used by the toggle_todo handler.
    async function readTodos(): Promise<Todo[]> {
      try {
        const s = await fs.readFile(DB_PATH, "utf-8");
        return JSON.parse(s);
      } catch {
        return [];
      }
    }
    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