UNPKG

omnifocus-mcp-enhanced

Version:

🚀 NEW: Native Custom Perspective Access! Enhanced MCP server with OmniFocus custom perspective support, hierarchical task display, AI-optimized tool selection, and comprehensive task management

75 lines (74 loc) 2.98 kB
import { z } from 'zod'; import { batchRemoveItems } from '../primitives/batchRemoveItems.js'; 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") }); export async function handler(args, extra) { 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", 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); 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", text: `${message}\n\n${details}` }] }; } else { // Batch operation failed completely return { content: [{ type: "text", text: `Failed to process batch removal: ${result.error}` }], isError: true }; } } catch (err) { const error = err; console.error(`Tool execution error: ${error.message}`); return { content: [{ type: "text", text: `Error processing batch removal: ${error.message}` }], isError: true }; } }