Skip to main content
Glama
jqlts1

OmniFocus MCP Enhanced

by jqlts1

edit_item

Modify tasks or projects in OmniFocus by updating names, notes, due dates, flags, statuses, tags, or folder locations to streamline task management and enhance productivity.

Instructions

Edit a task or project in OmniFocus

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
addTagsNoTags to add to the task
idNoThe ID of the task or project to edit
itemTypeYesType of item to edit ('task' or 'project')
nameNoThe name of the task or project to edit (as fallback if ID not provided)
newDeferDateNoNew defer date in ISO format (YYYY-MM-DD or full ISO date); set to empty string to clear
newDueDateNoNew due date in ISO format (YYYY-MM-DD or full ISO date); set to empty string to clear
newEstimatedMinutesNoNew estimated minutes
newFlaggedNoSet flagged status (set to false for no flag, true for flag)
newFolderNameNoNew folder to move the project to
newNameNoNew name for the item
newNoteNoNew note for the item
newProjectStatusNoNew status for projects
newSequentialNoWhether the project should be sequential
newStatusNoNew status for tasks (incomplete, completed, dropped)
removeTagsNoTags to remove from the task
replaceTagsNoTags to replace all existing tags with

Implementation Reference

  • The registered handler function for the 'edit_item' tool. Validates inputs, calls the primitive editItem, and formats success/error responses.
    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 edit an item." }], isError: true }; } // Call the editItem function const result = await editItem(args as EditItemParams); if (result.success) { // Item was edited successfully const itemTypeLabel = args.itemType === 'task' ? 'Task' : 'Project'; let changedText = ''; if (result.changedProperties) { changedText = ` (${result.changedProperties})`; } return { content: [{ type: "text" as const, text: `✅ ${itemTypeLabel} "${result.name}" updated successfully${changedText}.` }] }; } else { // Item editing failed let errorMsg = `Failed to update ${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 updating ${args.itemType}: ${error.message}` }], isError: true }; } }
  • Zod schema defining the input parameters for the 'edit_item' tool.
    export const schema = z.object({ id: z.string().optional().describe("The ID of the task or project to edit"), name: z.string().optional().describe("The name of the task or project to edit (as fallback if ID not provided)"), itemType: z.enum(['task', 'project']).describe("Type of item to edit ('task' or 'project')"), // Common editable fields newName: z.string().optional().describe("New name for the item"), newNote: z.string().optional().describe("New note for the item"), newDueDate: z.string().optional().describe("New due date in ISO format (YYYY-MM-DD or full ISO date); set to empty string to clear"), newDeferDate: z.string().optional().describe("New defer date in ISO format (YYYY-MM-DD or full ISO date); set to empty string to clear"), newFlagged: z.boolean().optional().describe("Set flagged status (set to false for no flag, true for flag)"), newEstimatedMinutes: z.number().optional().describe("New estimated minutes"), // Task-specific fields newStatus: z.enum(['incomplete', 'completed', 'dropped']).optional().describe("New status for tasks (incomplete, completed, dropped)"), addTags: z.array(z.string()).optional().describe("Tags to add to the task"), removeTags: z.array(z.string()).optional().describe("Tags to remove from the task"), replaceTags: z.array(z.string()).optional().describe("Tags to replace all existing tags with"), // Project-specific fields newSequential: z.boolean().optional().describe("Whether the project should be sequential"), newFolderName: z.string().optional().describe("New folder to move the project to"), newProjectStatus: z.enum(['active', 'completed', 'dropped', 'onHold']).optional().describe("New status for projects") });
  • src/server.ts:62-67 (registration)
    Registers the 'edit_item' tool on the MCP server using the schema and handler from editItemTool.
    server.tool( "edit_item", "Edit a task or project in OmniFocus", editItemTool.schema.shape, editItemTool.handler );
  • Core helper function that generates AppleScript and executes it via osascript to perform the actual editing in OmniFocus.
    export async function editItem(params: EditItemParams): Promise<{ success: boolean, id?: string, name?: string, changedProperties?: string, error?: string }> { try { // Generate AppleScript const script = generateAppleScript(params); console.error("Executing AppleScript for editing..."); 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, changedProperties: result.changedProperties, 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 editItem 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 editItem" }; } }

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