Skip to main content
Glama

remove_item

Delete tasks or projects from OmniFocus by specifying their ID or name, ensuring efficient task management and organization.

Instructions

Remove a task or project from OmniFocus

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idNoThe ID of the task or project to remove
itemTypeYesType of item to remove ('task' or 'project')
nameNoThe name of the task or project to remove (as fallback if ID not provided)

Implementation Reference

  • The main handler function for the 'remove_item' tool. Validates input parameters, calls the primitive removeItem function, handles success/error cases, and returns formatted MCP response content.
    export async function handler(args: z.infer<typeof schema>, extra: RequestHandlerExtra) {
      try {
        // Validate that either id or name is provided
        if (!args.id && !args.name) {
          return {
            content: [{
              type: "text" as const,
              text: "Either id or name must be provided to remove an item."
            }],
            isError: true
          };
        }
        
        // Validate itemType
        if (!['task', 'project'].includes(args.itemType)) {
          return {
            content: [{
              type: "text" as const,
              text: `Invalid item type: ${args.itemType}. Must be either 'task' or 'project'.`
            }],
            isError: true
          };
        }
        
        // Log the remove operation for debugging
        console.error(`Removing ${args.itemType} with ID: ${args.id || 'not provided'}, Name: ${args.name || 'not provided'}`);
        
        // Call the removeItem function 
        const result = await removeItem(args as RemoveItemParams);
        
        if (result.success) {
          // Item was removed successfully
          const itemTypeLabel = args.itemType === 'task' ? 'Task' : 'Project';
          
          return {
            content: [{
              type: "text" as const,
              text: `✅ ${itemTypeLabel} "${result.name}" removed successfully.`
            }]
          };
        } else {
          // Item removal failed
          let errorMsg = `Failed to remove ${args.itemType}`;
          
          if (result.error) {
            if (result.error.includes("Item not found")) {
              errorMsg = `${args.itemType.charAt(0).toUpperCase() + args.itemType.slice(1)} not found`;
              if (args.id) errorMsg += ` with ID "${args.id}"`;
              if (args.name) errorMsg += `${args.id ? ' or' : ' with'} name "${args.name}"`;
              errorMsg += '.';
            } else {
              errorMsg += `: ${result.error}`;
            }
          }
          
          return {
            content: [{
              type: "text" as const,
              text: errorMsg
            }],
            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 removing ${args.itemType}: ${error.message}`
          }],
          isError: true
        };
      }
    } 
  • Zod schema defining the input shape for the 'remove_item' tool: optional id or name, and required itemType ('task' or 'project').
    export const schema = 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')")
    });
  • src/server.ts:55-60 (registration)
    Registers the 'remove_item' tool with the MCP server, providing its name, description, input schema, and handler function.
    server.tool(
      "remove_item",
      "Remove a task or project from OmniFocus",
      removeItemTool.schema.shape,
      removeItemTool.handler
    );
  • Core primitive function implementing the removal logic: generates AppleScript to find and delete the item in OmniFocus via osascript, parses JSON result.
    export async function removeItem(params: RemoveItemParams): Promise<{success: boolean, id?: string, name?: string, error?: string}> {
      try {
        // Generate AppleScript
        const script = generateAppleScript(params);
        
        console.error("Executing AppleScript for removal...");
        console.error(`Item type: ${params.itemType}, ID: ${params.id || 'not provided'}, Name: ${params.name || 'not provided'}`);
        
        // Log a preview of the script for debugging (first few lines)
        const scriptPreview = script.split('\n').slice(0, 10).join('\n') + '\n...';
        console.error("AppleScript preview:\n", scriptPreview);
        
        // Execute AppleScript directly
        const { stdout, stderr } = await execAsync(`osascript -e '${script}'`);
        
        if (stderr) {
          console.error("AppleScript stderr:", stderr);
        }
        
        console.error("AppleScript stdout:", stdout);
        
        // Parse the result
        try {
          const result = JSON.parse(stdout);
          
          // Return the result
          return {
            success: result.success,
            id: result.id,
            name: result.name,
            error: result.error
          };
        } catch (parseError) {
          console.error("Error parsing AppleScript result:", parseError);
          return {
            success: false,
            error: `Failed to parse result: ${stdout}`
          };
        }
      } catch (error: any) {
        console.error("Error in removeItem execution:", error);
        
        // Include more detailed error information
        if (error.message && error.message.includes('syntax error')) {
          console.error("This appears to be an AppleScript syntax error. Review the script generation logic.");
        }
        
        return {
          success: false,
          error: error?.message || "Unknown error in removeItem"
        };
      }
    } 
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 only states the action without behavioral details. It doesn't disclose if removal is permanent, requires specific permissions, has side effects, or what happens to dependent items, which is critical for a destructive operation.

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

Conciseness5/5

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

The description is a single, efficient sentence that front-loads the core action and resource without any wasted words. It's appropriately sized for a simple tool, making it easy to parse quickly.

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 destructive tool with no annotations and no output schema, the description is incomplete. It lacks critical context such as the permanence of removal, error handling, or return values, leaving significant gaps for safe agent invocation.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema fully documents all parameters. The description adds no extra meaning beyond implying removal targets tasks or projects, matching the schema. Baseline 3 is appropriate as the schema handles parameter semantics adequately.

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 ('Remove') and the resource ('a task or project from OmniFocus'), making the purpose immediately understandable. It doesn't distinguish from sibling tools like 'batch_remove_items' or 'edit_item', which prevents a perfect score.

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 'batch_remove_items' for multiple items or 'edit_item' for modifications. It also doesn't mention prerequisites or context for removal, leaving usage unclear.

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

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

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