filter_tasks
Filter tasks in OmniFocus by status, dates, projects, tags, search, and more. Customize perspectives, sort results, and apply advanced criteria to manage tasks effectively.
Instructions
Advanced task filtering with unlimited perspective combinations - status, dates, projects, tags, search, and more
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| completedAfter | No | Show tasks completed after this date (ISO format: YYYY-MM-DD) | |
| completedBefore | No | Show tasks completed before this date (ISO format: YYYY-MM-DD) | |
| completedThisMonth | No | Show tasks completed this month | |
| completedThisWeek | No | Show tasks completed this week | |
| completedToday | No | Show tasks completed today | |
| deferAfter | No | Show tasks with defer date after this date (ISO format: YYYY-MM-DD) | |
| deferAvailable | No | Show tasks whose defer date has passed (now available) | |
| deferBefore | No | Show tasks with defer date before this date (ISO format: YYYY-MM-DD) | |
| deferThisWeek | No | Show tasks deferred to this week | |
| deferToday | No | Show tasks deferred to today | |
| dueAfter | No | Show tasks due after this date (ISO format: YYYY-MM-DD) | |
| dueBefore | No | Show tasks due before this date (ISO format: YYYY-MM-DD) | |
| dueThisMonth | No | Show tasks due this month | |
| dueThisWeek | No | Show tasks due this week | |
| dueToday | No | Show tasks due today | |
| estimateMax | No | Maximum estimated minutes | |
| estimateMin | No | Minimum estimated minutes | |
| exactTagMatch | No | Set to true for exact tag name match, false for partial (default: false) | |
| flagged | No | Filter by flagged status | |
| hasEstimate | No | Filter tasks that have time estimates | |
| hasNote | No | Filter tasks that have notes | |
| inInbox | No | Filter tasks in inbox | |
| limit | No | Maximum number of tasks to return (default: 100) | |
| overdue | No | Show overdue tasks only | |
| perspective | No | Limit search to specific perspective: inbox, flagged, all tasks | |
| projectFilter | No | Filter by project name (partial match) | |
| searchText | No | Search in task names and notes | |
| sortBy | No | Sort results by field | |
| sortOrder | No | Sort order (default: asc) | |
| tagFilter | No | Filter by tag name(s). Can be single tag or array of tags | |
| taskStatus | No | Filter by task status. Can specify multiple statuses |
Implementation Reference
- MCP tool handler: calls the filterTasks primitive with validated args and returns formatted text response or error.export async function handler(args: z.infer<typeof schema>, extra: RequestHandlerExtra) { try { const result = await filterTasks(args); return { content: [{ type: "text" as const, text: result }] }; } catch (err: unknown) { const errorMessage = err instanceof Error ? err.message : 'Unknown error occurred'; return { content: [{ type: "text" as const, text: `Error filtering tasks: ${errorMessage}` }], isError: true }; } }
- Zod schema defining all input parameters for the filter_tasks tool with descriptions.export const schema = z.object({ // ๐ฏ ไปปๅก็ถๆ่ฟๆปค taskStatus: z.array(TaskStatusEnum).optional().describe("Filter by task status. Can specify multiple statuses"), // ๐ ้่ง่ๅด perspective: PerspectiveEnum.optional().describe("Limit search to specific perspective: inbox, flagged, all tasks"), // ๐ ้กน็ฎ/ๆ ็ญพ่ฟๆปค projectFilter: z.string().optional().describe("Filter by project name (partial match)"), tagFilter: z.union([z.string(), z.array(z.string())]).optional().describe("Filter by tag name(s). Can be single tag or array of tags"), exactTagMatch: z.boolean().optional().describe("Set to true for exact tag name match, false for partial (default: false)"), // ๐ ๆชๆญขๆฅๆ่ฟๆปค dueBefore: z.string().optional().describe("Show tasks due before this date (ISO format: YYYY-MM-DD)"), dueAfter: z.string().optional().describe("Show tasks due after this date (ISO format: YYYY-MM-DD)"), dueToday: z.boolean().optional().describe("Show tasks due today"), dueThisWeek: z.boolean().optional().describe("Show tasks due this week"), dueThisMonth: z.boolean().optional().describe("Show tasks due this month"), overdue: z.boolean().optional().describe("Show overdue tasks only"), // ๐ ๆจ่ฟๆฅๆ่ฟๆปค deferBefore: z.string().optional().describe("Show tasks with defer date before this date (ISO format: YYYY-MM-DD)"), deferAfter: z.string().optional().describe("Show tasks with defer date after this date (ISO format: YYYY-MM-DD)"), deferToday: z.boolean().optional().describe("Show tasks deferred to today"), deferThisWeek: z.boolean().optional().describe("Show tasks deferred to this week"), deferAvailable: z.boolean().optional().describe("Show tasks whose defer date has passed (now available)"), // โ ๅฎๆๆฅๆ่ฟๆปค completedBefore: z.string().optional().describe("Show tasks completed before this date (ISO format: YYYY-MM-DD)"), completedAfter: z.string().optional().describe("Show tasks completed after this date (ISO format: YYYY-MM-DD)"), completedToday: z.boolean().optional().describe("Show tasks completed today"), completedThisWeek: z.boolean().optional().describe("Show tasks completed this week"), completedThisMonth: z.boolean().optional().describe("Show tasks completed this month"), // ๐ฉ ๅ ถไป็ปดๅบฆ flagged: z.boolean().optional().describe("Filter by flagged status"), searchText: z.string().optional().describe("Search in task names and notes"), hasEstimate: z.boolean().optional().describe("Filter tasks that have time estimates"), estimateMin: z.number().optional().describe("Minimum estimated minutes"), estimateMax: z.number().optional().describe("Maximum estimated minutes"), hasNote: z.boolean().optional().describe("Filter tasks that have notes"), inInbox: z.boolean().optional().describe("Filter tasks in inbox"), // ๐ ่พๅบๆงๅถ limit: z.number().max(1000).optional().describe("Maximum number of tasks to return (default: 100)"), sortBy: z.enum(["name", "dueDate", "deferDate", "completedDate", "flagged", "project"]).optional().describe("Sort results by field"), sortOrder: z.enum(["asc", "desc"]).optional().describe("Sort order (default: asc)") });
- src/server.ts:128-133 (registration)Registers the filter_tasks tool on the MCP server using its schema and handler.server.tool( "filter_tasks", "Advanced task filtering with unlimited perspective combinations - status, dates, projects, tags, search, and more", filterTasksTool.schema.shape, filterTasksTool.handler );
- Core helper function that executes the OmniFocus filtering script, processes results, formats output grouped by project with rich details.export async function filterTasks(options: FilterTasksOptions = {}): Promise<string> { try { // ่ฎพ็ฝฎ้ป่ฎคๅผ const { perspective = "all", exactTagMatch = false, limit = 100, sortBy = "name", sortOrder = "asc" } = options; // ๆง่กๅธธ่ง่ฟๆปค่ๆฌ const result = await executeOmniFocusScript('@filterTasks.js', { ...options, perspective, exactTagMatch, limit, sortBy, sortOrder }); if (typeof result === 'string') { return result; } // ๅฆๆ็ปๆๆฏๅฏน่ฑก๏ผๆ ผๅผๅๅฎ if (result && typeof result === 'object') { const data = result as any; if (data.error) { throw new Error(data.error); } // ๆ ผๅผๅ่ฟๆปค็ปๆ let output = `# ๐ FILTERED TASKS\n\n`; // ๆพ็คบ่ฟๆปคๆกไปถๆ่ฆ const filterSummary = buildFilterSummary(options); if (filterSummary) { output += `**Filter**: ${filterSummary}\n\n`; } if (data.tasks && Array.isArray(data.tasks)) { if (data.tasks.length === 0) { output += "๐ฏ No tasks match your filter criteria.\n"; // ๆไพไธไบๅปบ่ฎฎ output += "\n**Tips**:\n"; output += "- Try broadening your search criteria\n"; output += "- Check if tasks exist in the specified project/tags\n"; output += "- Use `get_inbox_tasks` or `get_flagged_tasks` for basic views\n"; } else { const taskCount = data.tasks.length; const totalCount = data.totalCount || taskCount; output += `Found ${taskCount} task${taskCount === 1 ? '' : 's'}`; if (taskCount < totalCount) { output += ` (showing first ${taskCount} of ${totalCount})`; } output += `:\n\n`; // ๆ้กน็ฎๅ็ปๆพ็คบไปปๅก const tasksByProject = groupTasksByProject(data.tasks); tasksByProject.forEach((tasks, projectName) => { if (tasksByProject.size > 1) { output += `## ๐ ${projectName}\n`; } tasks.forEach((task: any) => { output += formatTask(task); output += '\n'; }); if (tasksByProject.size > 1) { output += '\n'; } }); // ๆพ็คบๆๅบไฟกๆฏ if (data.sortedBy) { output += `\n๐ **Sorted by**: ${data.sortedBy} (${data.sortOrder || 'asc'})\n`; } } } else { output += "No task data available\n"; } return output; } return "Unexpected result format from OmniFocus"; } catch (error) { console.error("Error in filterTasks:", error); throw new Error(`Failed to filter tasks: ${error instanceof Error ? error.message : 'Unknown error'}`); } }