Skip to main content
Glama

reopen_tasks

Reopen completed tasks in Todoist using task IDs or names to restore them to active status.

Instructions

Reopen tasks in Todoist Either 'task_id' or the 'task_name' to identify the target.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
itemsYes

Implementation Reference

  • Registration of the 'reopen_tasks' tool using createBatchApiHandler. Defines the tool name, description, input schema for batch items (task_id or task_name), HTTP method POST to path '/tasks/{id}/reopen', update mode with ID/name resolution using findByName on task content.
    createBatchApiHandler({
        name: 'reopen_tasks',
        description: 'Reopen tasks in Todoist',
        itemSchema: {
            task_id: z.string().optional(),
            task_name: z.string().optional(),
        },
        method: 'POST',
        path: '/tasks/{id}/reopen',
        mode: 'update',
        idField: 'task_id',
        nameField: 'task_name',
        findByName: (name, items) =>
            items.find(item => item.content.toLowerCase().includes(name.toLowerCase())),
    });
  • Core handler function created by createBatchApiHandler for batch tools like reopen_tasks. Processes array of items, resolves task_id from task_name by searching task content, validates and sanitizes ID, constructs path '/tasks/{id}/reopen', executes todoistApi.post, aggregates success/failure results with 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,
        };
    };
  • Factory function createBatchApiHandler that generates the MCP tool handler for batch API operations, used by reopen_tasks registration. Handles schema refinement, batch input validation, name-to-ID lookup, path templating, API execution, and registration via createHandler.
    export function createBatchApiHandler<T extends z.ZodRawShape>(
        options: {
            name: string;
            description: string;
            itemSchema: T;
            method: HttpMethod;
            mode?: 'read' | 'create' | 'update' | 'delete';
            idField?: string;
            nameField?: string;
            findByName?: (name: string, items: any[]) => any | undefined;
            validateItem?: (item: any) => { valid: boolean; error?: string };
        } & ( // Or we specify full path
            | {
                  path: string;
                  basePath?: never;
                  pathSuffix?: never;
              }
            // Or we specify base path and path suffix
            | {
                  path?: never;
                  basePath: string;
                  pathSuffix: string;
              }
        )
    ) {
        // Create basic description, we cant properly use 'anyOf' here so for now we will add info to description
        let finalDescription = options.description;
        const requiresIdOrName = options.idField && options.nameField && options.mode !== 'create';
    
        if (requiresIdOrName) {
            const requirementText = `\nEither '${options.idField}' or the '${options.nameField}' to identify the target.`;
            finalDescription += requirementText;
        }
    
        const itemSchemaObject = z.object(options.itemSchema);
    
        const enhancedItemSchema: z.ZodTypeAny = requiresIdOrName
            ? itemSchemaObject.refine(
                  (data: any) =>
                      data[options.idField!] !== undefined || data[options.nameField!] !== undefined,
                  {
                      message: `Either ${options.idField} or ${options.nameField} must be provided`,
                      path: [options.idField!, options.nameField!],
                  }
              )
            : itemSchemaObject;
    
        const batchSchema = z.object({
            items: z.array(enhancedItemSchema),
        });
    
        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,
            };
        };
    
        return createHandler(options.name, finalDescription, batchSchema.shape, handler);
    }
  • Input schema for reopen_tasks batch items, allowing either task_id or task_name for identification.
    itemSchema: {
        task_id: z.string().optional(),
        task_name: z.string().optional(),
    },
Behavior2/5

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

With no annotations provided, the description carries full burden but offers limited behavioral insight. It implies a mutation operation ('Reopen') but doesn't disclose permissions needed, whether changes are reversible, rate limits, error conditions, or what happens if tasks are already open. The description adds minimal context beyond the basic action.

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 brief and front-loaded with the core purpose. Both sentences are relevant, with the second clarifying identification options. There's no redundant information, though it could be more structured (e.g., separating purpose from parameter guidance).

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?

For a mutation tool with no annotations, 0% schema coverage, and no output schema, the description is insufficient. It lacks details on behavioral traits, error handling, return values, and comprehensive parameter usage. Given the complexity of reopening tasks (which may involve state transitions), more context is needed for effective tool invocation.

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 but provides incomplete parameter guidance. It mentions 'task_id' or 'task_name' as identification methods, but doesn't explain the 'items' array structure, whether both fields can be used together, or if multiple tasks can be reopened at once. The description adds some meaning but leaves key parameter semantics unclear.

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

Purpose4/5

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

The description clearly states the action ('Reopen') and resource ('tasks in Todoist'), making the purpose unambiguous. It distinguishes from siblings like 'close_tasks' by specifying the opposite operation. However, it doesn't explicitly mention what 'reopen' means in this context (e.g., marking incomplete tasks from a completed state).

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 minimal guidance by mentioning two identification methods ('task_id' or 'task_name'), but offers no context on when to use this tool versus alternatives. It doesn't specify prerequisites (e.g., tasks must be closed), compare with similar tools like 'update_tasks', or indicate typical scenarios for reopening tasks.

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