Skip to main content
Glama

get_labels

Retrieve personal labels from Todoist by ID or name to organize and categorize tasks effectively.

Instructions

Get a personal label from Todoist Either 'id' or the 'name' to identify the target.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
itemsYes

Implementation Reference

  • Core handler logic for batch API operations (used by get_labels). For 'read' mode, fetches all labels if name provided (no ID), finds matching label by name, performs GET /labels/{id}, aggregates results with success/failure summary.
    const handler = async (args: z.infer<typeof batchSchema>): Promise<any> => {
        const { items } = args;
    
        // For modes other than create, check if name lookup is needed
        let allItems: any[] = [];
    
        const needsNameLookup =
            options.mode !== 'create' &&
            options.nameField &&
            options.findByName &&
            items.some(item => item[options.nameField!] && !item[options.idField!]);
    
        if (needsNameLookup) {
            // Determine the base path for fetching all items
            // Example: /tasks from /tasks/{id}
            const lookupPath =
                options.basePath || (options.path ? options.path.split('/{')[0] : '');
            allItems = await todoistApi.get(lookupPath, {});
        }
    
        const results = await Promise.all(
            items.map(async item => {
                if (options.validateItem) {
                    const validation = options.validateItem(item);
    
                    if (!validation.valid) {
                        return {
                            success: false,
                            error: validation.error || 'Validation failed',
                            item,
                        };
                    }
                }
    
                try {
                    let finalPath = '';
                    const apiParams = { ...item };
    
                    // For modes where need id
                    if (options.mode !== 'create' && options.idField) {
                        let itemId = item[options.idField];
                        let matchedName = null;
                        let matchedContent = null;
    
                        // If no ID but name is provided, search by name
                        if (!itemId && item[options.nameField!] && options.findByName) {
                            const searchName = item[options.nameField!];
                            const matchedItem = options.findByName(searchName, allItems);
    
                            if (!matchedItem) {
                                return {
                                    success: false,
                                    error: `Item not found with name: ${searchName}`,
                                    item,
                                };
                            }
    
                            itemId = matchedItem.id;
                            matchedName = searchName;
                            matchedContent = matchedItem.content;
                        }
    
                        if (!itemId) {
                            return {
                                success: false,
                                error: `Either ${options.idField} or ${options.nameField} must be provided`,
                                item,
                            };
                        }
    
                        // Apply security validation to itemId before using in path
                        const safeItemId = validatePathParameter(itemId, options.idField || 'id');
    
                        if (options.basePath && options.pathSuffix) {
                            finalPath = `${options.basePath}${options.pathSuffix.replace('{id}', safeItemId)}`;
                        } else if (options.path) {
                            finalPath = options.path.replace('{id}', safeItemId);
                        }
    
                        delete apiParams[options.idField];
                        if (options.nameField) {
                            delete apiParams[options.nameField];
                        }
    
                        let result;
                        switch (options.method) {
                            case 'GET':
                                result = await todoistApi.get(finalPath, apiParams);
                                break;
                            case 'POST':
                                result = await todoistApi.post(finalPath, apiParams);
                                break;
                            case 'DELETE':
                                result = await todoistApi.delete(finalPath);
                                break;
                        }
    
                        const response: any = {
                            success: true,
                            id: itemId,
                            result,
                        };
    
                        if (matchedName) {
                            response.found_by_name = matchedName;
                            response.matched_content = matchedContent;
                        }
    
                        return response;
                    }
                    // Create mode
                    else {
                        finalPath = options.path || options.basePath || '';
    
                        let result;
                        switch (options.method) {
                            case 'GET':
                                result = await todoistApi.get(finalPath, apiParams);
                                break;
                            case 'POST':
                                result = await todoistApi.post(finalPath, apiParams);
                                break;
                            case 'DELETE':
                                result = await todoistApi.delete(finalPath);
                                break;
                        }
    
                        return {
                            success: true,
                            created_item: result,
                        };
                    }
                } catch (error) {
                    return {
                        success: false,
                        error: error instanceof Error ? error.message : String(error),
                        item,
                    };
                }
            })
        );
    
        const successCount = results.filter(r => r.success).length;
        return {
            success: successCount === items.length,
            summary: {
                total: items.length,
                succeeded: successCount,
                failed: items.length - successCount,
            },
            results,
        };
    };
  • Registration of the 'get_labels' MCP tool via createBatchApiHandler, configuring it for reading a single label by ID or name using Todoist REST API.
    createBatchApiHandler({
        name: 'get_labels',
        description: 'Get a personal label from Todoist',
        itemSchema: {
            id: z.string().optional().describe('ID of the label to retrieve (preferred over name)'),
            name: z.string().optional().describe('Name of the label to retrieve'),
        },
        method: 'GET',
        path: '/labels/{id}',
        mode: 'read',
        idField: 'id',
        nameField: 'name',
        findByName: (name, items) =>
            items.find(item => item.name.toLowerCase().includes(name.toLowerCase())),
    });
  • Input schema definition using Zod: optional 'id' (preferred) or 'name' for the label to retrieve. Enables batch input as array of items.
    itemSchema: {
        id: z.string().optional().describe('ID of the label to retrieve (preferred over name)'),
        name: z.string().optional().describe('Name of the label to retrieve'),
    },
  • Helper function for name-based lookup: finds first label where name partially matches (case-insensitive). Used when ID not provided.
        findByName: (name, items) =>
            items.find(item => item.name.toLowerCase().includes(name.toLowerCase())),
    });
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It implies a read operation ('Get') but doesn't disclose behavioral traits such as authentication needs, rate limits, error handling, or what happens if multiple labels match. The description is minimal and leaves critical behavioral aspects unspecified.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is very concise with two sentences, front-loading the purpose. There's no wasted text, but it may be overly brief, risking under-specification. Every sentence adds value, though more detail could improve clarity without sacrificing efficiency.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations, 0% schema coverage, no output schema, and a parameter count of 1 with nested objects, the description is incomplete. It doesn't explain the return format, error conditions, or how the tool interacts with sibling tools like 'get_labels_list'. For a tool with minimal structured data, more context is needed.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It mentions using 'id' or 'name' to identify the target, which adds some meaning beyond the schema's property names. However, it doesn't explain the 'items' array structure, clarify if both 'id' and 'name' can be used together, or provide examples. With 1 parameter and low coverage, this is insufficient.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states the tool 'Get a personal label from Todoist', which provides a clear verb ('Get') and resource ('personal label'), distinguishing it from sibling tools like 'get_labels_list' or 'get_shared_labels'. However, it lacks specificity about what 'get' entails (e.g., retrieve details, fetch metadata) and doesn't fully differentiate from similar tools beyond mentioning 'personal'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'get_labels_list' or 'get_shared_labels'. It mentions identifying a target with 'id' or 'name', but this is parameter guidance rather than usage context. No exclusions, prerequisites, or comparative advice are given.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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/stanislavlysenko0912/todoist-mcp-server'

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