Skip to main content
Glama
danjdewhurst

Todo Markdown MCP Server

by danjdewhurst

add_todo

Create a new todo item by adding text to a markdown-based todo list managed through an MCP server.

Instructions

Add a new todo item

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYesThe todo item text

Implementation Reference

  • Core handler function that implements the logic for adding a new todo item: generates ID, appends to list, formats markdown, and writes to file with error handling for permissions.
    async addTodo(request: AddTodoRequest): Promise<TodoItem> {
      const todos = (await this.listTodos()).todos;
    
      const newTodo: TodoItem = {
        id: randomUUID(),
        text: request.text.trim(),
        completed: false,
        createdAt: new Date(),
      };
    
      todos.push(newTodo);
    
      const markdown = this.formatTodoMarkdown(todos);
    
      try {
        await writeFile(this.todoFilePath, markdown, 'utf-8');
      } catch (error) {
        if (error instanceof Error && error.message.includes('EACCES')) {
          throw new Error(
            `Permission denied: Cannot write to ${this.todoFilePath}. Check file permissions or set TODO_FILE_PATH environment variable to a writable location.`
          );
        } else if (error instanceof Error && error.message.includes('EROFS')) {
          throw new Error(
            `Read-only file system: Cannot write to ${this.todoFilePath}. Set TODO_FILE_PATH environment variable to a writable location.`
          );
        }
        throw error;
      }
    
      return newTodo;
    }
  • src/index.ts:49-63 (registration)
    Tool registration in ListToolsRequestHandler, defining name, description, and JSON input schema for 'add_todo'.
    {
      name: 'add_todo',
      description: 'Add a new todo item',
      inputSchema: {
        type: 'object',
        properties: {
          text: {
            type: 'string',
            description: 'The todo item text',
          },
        },
        required: ['text'],
        additionalProperties: false,
      },
    },
  • MCP CallToolRequest dispatch handler for 'add_todo': validates input, calls todoManager.addTodo, and formats success response.
    case 'add_todo': {
      const args = request.params.arguments as unknown as AddTodoRequest;
      if (!args?.text || typeof args.text !== 'string') {
        throw new Error('Text is required and must be a string');
      }
    
      const todo = await this.todoManager.addTodo(args);
      return {
        content: [
          {
            type: 'text',
            text: `Todo added successfully: ${JSON.stringify(todo, null, 2)}`,
          },
        ],
      };
    }
  • TypeScript interface used for type-checking the AddTodoRequest parameters in handlers.
    export interface AddTodoRequest {
      text: string;
    }

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/danjdewhurst/todo-md-mcp'

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