Skip to main content
Glama
greirson

Todoist MCP Server

todoist_label_delete

Remove labels from your Todoist tasks by specifying either the label ID or name to clean up your task organization.

Instructions

Delete a label from Todoist

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
label_idNoID of the label to delete (provide this OR label_name)
label_nameNoName of the label to delete (provide this OR label_id)

Implementation Reference

  • Main handler function that finds the label using findLabel helper and calls the Todoist API to delete it, with caching invalidation and error handling.
    export async function handleDeleteLabel(
      todoistClient: TodoistApi,
      args: LabelNameArgs
    ): Promise<string> {
      const label = await findLabel(todoistClient, args);
    
      try {
        await todoistClient.deleteLabel(label.id);
    
        labelCache.clear();
        labelStatsCache.clear();
    
        return `Label "${label.name}" deleted successfully`;
      } catch (error) {
        throw new TodoistAPIError(
          `Failed to delete label "${label.name}"`,
          error instanceof Error ? error : undefined
        );
      }
    }
  • Tool schema defining the input parameters for deletion: either label_id or label_name.
    export const DELETE_LABEL_TOOL: Tool = {
      name: "todoist_label_delete",
      description: "Delete a label from Todoist",
      inputSchema: {
        type: "object",
        properties: {
          label_id: {
            type: "string",
            description: "ID of the label to delete (provide this OR label_name)",
          },
          label_name: {
            type: "string",
            description: "Name of the label to delete (provide this OR label_id)",
          },
        },
      },
    };
  • src/index.ts:275-280 (registration)
    Switch case in the main CallToolRequest handler that dispatches to the handleDeleteLabel function after type guard validation.
    case "todoist_label_delete":
      if (!isLabelNameArgs(args)) {
        throw new Error("Invalid arguments for todoist_label_delete");
      }
      result = await handleDeleteLabel(apiClient, args);
      break;
  • Helper function to find a label by ID (direct API call) or by name (cached list lookup), used by update and delete handlers.
    async function findLabel(
      todoistClient: TodoistApi,
      args: LabelNameArgs
    ): Promise<TodoistLabel> {
      if (args.label_id) {
        try {
          const label = await todoistClient.getLabel(args.label_id);
          return label as TodoistLabel;
        } catch {
          throw new LabelNotFoundError(`Label with ID ${args.label_id} not found`);
        }
      }
    
      if (!args.label_name) {
        throw new ValidationError("Either label_id or label_name must be provided");
      }
    
      const cached = labelCache.get("labels:all");
      let labels: TodoistLabel[];
    
      if (cached) {
        labels = cached;
      } else {
        try {
          const response = await todoistClient.getLabels();
          labels = extractArrayFromResponse(response) as TodoistLabel[];
          labelCache.set("labels:all", labels);
        } catch (error) {
          throw new TodoistAPIError(
            "Failed to fetch labels for search",
            error instanceof Error ? error : undefined
          );
        }
      }
    
      const matchingLabel = labels.find(
        (label: TodoistLabel) =>
          label.name.toLowerCase() === args.label_name!.toLowerCase()
      );
    
      if (!matchingLabel) {
        throw new LabelNotFoundError(
          `No label found with name: "${args.label_name}"`
        );
      }
    
      return matchingLabel;
    }
  • Aggregation of all tools including LABEL_TOOLS (which contains todoist_label_delete), exported and used in server ListTools handler.
    export const ALL_TOOLS = [
      ...TASK_TOOLS,
      ...PROJECT_TOOLS,
      ...COMMENT_TOOLS,
      ...LABEL_TOOLS,
      ...SUBTASK_TOOLS,
      ...TEST_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/greirson/mcp-todoist'

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