Skip to main content
Glama

delete_sections

Remove sections from Todoist projects by specifying section IDs or names to organize your task management workspace.

Instructions

Delete sections in Todoist Either 'id' or the 'name' to identify the target.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
itemsYes

Implementation Reference

  • Core batch handler function that implements the execution logic for the 'delete_sections' tool. It processes an array of items, resolves section IDs by name if provided (fetching all sections from Todoist), validates paths, constructs the API endpoint '/sections/{id}', and performs DELETE requests via todoistApi.delete for each valid item.
    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, }; };
  • Registers the 'delete_sections' tool with the MCP server by calling createBatchApiHandler, defining its name, description, input schema, HTTP method (DELETE), API path ('/sections/{id}'), ID/name fields, delete mode, and name-matching function.
    createBatchApiHandler({ name: 'delete_sections', description: 'Delete sections in Todoist', itemSchema: { id: z.string().optional().describe('ID of the section to delete (preferred over name)'), name: z.string().optional().describe('Name of the section to delete'), }, method: 'DELETE', path: '/sections/{id}', idField: 'id', nameField: 'name', mode: 'delete', findByName: (name, items) => items.find(item => item.name.toLowerCase().includes(name.toLowerCase())), });
  • Zod schema definition for individual items in the 'delete_sections' tool input, requiring either 'id' or 'name' of the Todoist section to delete.
    itemSchema: { id: z.string().optional().describe('ID of the section to delete (preferred over name)'), name: z.string().optional().describe('Name of the section to delete'), },

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