Skip to main content
Glama

batch_remove_items

Bulk delete multiple tasks or projects from OmniFocus in a single operation, streamlining task management and reducing manual effort.

Instructions

Remove multiple tasks or projects from OmniFocus in a single operation

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
itemsYesArray of items (tasks or projects) to remove

Implementation Reference

  • Tool handler for batch_remove_items that validates input and calls the primitive batchRemoveItems function
    export async function handler(args: z.infer<typeof schema>, extra: RequestHandlerExtra) {
      try {
        // Validate that each item has at least an ID or name
        for (const item of args.items) {
          if (!item.id && !item.name) {
            return {
              content: [{
                type: "text" as const,
                text: "Each item must have either id or name provided to remove it."
              }],
              isError: true
            };
          }
        }
        
        // Call the batchRemoveItems function
        const result = await batchRemoveItems(args.items as BatchRemoveItemsParams[]);
        
        if (result.success) {
          const successCount = result.results.filter(r => r.success).length;
          const failureCount = result.results.filter(r => !r.success).length;
          
          let message = `✅ Successfully removed ${successCount} items.`;
          
          if (failureCount > 0) {
            message += ` ⚠️ Failed to remove ${failureCount} items.`;
          }
          
          // Include details about removed items
          const details = result.results.map((item, index) => {
            if (item.success) {
              const itemType = args.items[index].itemType;
              return `- ✅ ${itemType}: "${item.name}"`;
            } else {
              const itemType = args.items[index].itemType;
              const identifier = args.items[index].id || args.items[index].name;
              return `- ❌ ${itemType}: ${identifier} - Error: ${item.error}`;
            }
          }).join('\n');
          
          return {
            content: [{
              type: "text" as const,
              text: `${message}\n\n${details}`
            }]
          };
        } else {
          // Batch operation failed completely
          return {
            content: [{
              type: "text" as const,
              text: `Failed to process batch removal: ${result.error}`
            }],
            isError: true
          };
        }
      } catch (err: unknown) {
        const error = err as Error;
        console.error(`Tool execution error: ${error.message}`);
        return {
          content: [{
            type: "text" as const,
            text: `Error processing batch removal: ${error.message}`
          }],
          isError: true
        };
      }
    } 
  • Zod schema defining the input parameters for batch_remove_items tool
    export const schema = z.object({
      items: z.array(z.object({
        id: z.string().optional().describe("The ID of the task or project to remove"),
        name: z.string().optional().describe("The name of the task or project to remove (as fallback if ID not provided)"),
        itemType: z.enum(['task', 'project']).describe("Type of item to remove ('task' or 'project')")
      })).describe("Array of items (tasks or projects) to remove")
    });
  • src/server.ts:76-81 (registration)
    Registers the batch_remove_items tool using schema and handler from batchRemoveItemsTool
    server.tool(
      "batch_remove_items",
      "Remove multiple tasks or projects from OmniFocus in a single operation",
      batchRemoveItemsTool.schema.shape,
      batchRemoveItemsTool.handler
    );
  • Core implementation of batch removal logic, processing multiple items by calling removeItem sequentially
    export async function batchRemoveItems(items: BatchRemoveItemsParams[]): Promise<BatchResult> {
      try {
        // Results array to track individual operation outcomes
        const results: ItemResult[] = [];
        
        // Process each item in sequence
        for (const item of items) {
          try {
            // Remove item
            const itemResult = await removeItem(item);
            results.push({
              success: itemResult.success,
              id: itemResult.id,
              name: itemResult.name,
              error: itemResult.error
            });
          } catch (itemError: any) {
            // Handle individual item errors
            results.push({
              success: false,
              error: itemError.message || "Unknown error processing item"
            });
          }
        }
        
        // Determine overall success (true if at least one item was removed successfully)
        const overallSuccess = results.some(result => result.success);
        
        return {
          success: overallSuccess,
          results: results
        };
      } catch (error: any) {
        console.error("Error in batchRemoveItems:", error);
        return {
          success: false,
          results: [],
          error: error.message || "Unknown error in batchRemoveItems"
        };
      }
    } 

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/jqlts1/omnifocus-mcp-enhanced'

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