Skip to main content
Glama

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
NameRequiredDescriptionDefault
completedAfterNoShow tasks completed after this date (ISO format: YYYY-MM-DD)
completedBeforeNoShow tasks completed before this date (ISO format: YYYY-MM-DD)
completedThisMonthNoShow tasks completed this month
completedThisWeekNoShow tasks completed this week
completedTodayNoShow tasks completed today
deferAfterNoShow tasks with defer date after this date (ISO format: YYYY-MM-DD)
deferAvailableNoShow tasks whose defer date has passed (now available)
deferBeforeNoShow tasks with defer date before this date (ISO format: YYYY-MM-DD)
deferThisWeekNoShow tasks deferred to this week
deferTodayNoShow tasks deferred to today
dueAfterNoShow tasks due after this date (ISO format: YYYY-MM-DD)
dueBeforeNoShow tasks due before this date (ISO format: YYYY-MM-DD)
dueThisMonthNoShow tasks due this month
dueThisWeekNoShow tasks due this week
dueTodayNoShow tasks due today
estimateMaxNoMaximum estimated minutes
estimateMinNoMinimum estimated minutes
exactTagMatchNoSet to true for exact tag name match, false for partial (default: false)
flaggedNoFilter by flagged status
hasEstimateNoFilter tasks that have time estimates
hasNoteNoFilter tasks that have notes
inInboxNoFilter tasks in inbox
limitNoMaximum number of tasks to return (default: 100)
overdueNoShow overdue tasks only
perspectiveNoLimit search to specific perspective: inbox, flagged, all tasks
projectFilterNoFilter by project name (partial match)
searchTextNoSearch in task names and notes
sortByNoSort results by field
sortOrderNoSort order (default: asc)
tagFilterNoFilter by tag name(s). Can be single tag or array of tags
taskStatusNoFilter 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'}`);
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions 'advanced task filtering' but doesn't describe whether this is a read-only operation, what permissions are needed, how results are returned (format, pagination), or any rate limits. The phrase 'unlimited perspective combinations' suggests flexibility but lacks concrete behavioral details needed for safe invocation.

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

Conciseness4/5

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

The description is a single, efficient sentence that front-loads the core purpose ('Advanced task filtering') and key capabilities. It avoids unnecessary words while conveying the tool's scope, though it could be slightly more structured by explicitly separating primary from secondary features.

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 complex filtering tool with 31 parameters and no output schema, the description is insufficient. It doesn't explain the return format, how multiple filters combine (AND/OR logic), default behaviors, or error conditions. Without annotations and with rich parameter schema, the description should provide more operational context to complement the technical specifications.

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?

The schema description coverage is 100%, so all 31 parameters are well-documented in the schema itself. The description adds marginal value by listing some filter categories (status, dates, projects, tags, search) but doesn't provide additional semantic context beyond what's already in the parameter descriptions. This meets the baseline for high schema coverage.

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 tool's purpose as 'Advanced task filtering' with 'unlimited perspective combinations', specifying the resource (tasks) and key filtering dimensions (status, dates, projects, tags, search). It distinguishes from simpler sibling tools like get_flagged_tasks or get_inbox_tasks by emphasizing comprehensive filtering capabilities, though it doesn't explicitly name alternatives.

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 get_tasks_by_tag or get_custom_perspective_tasks. It mentions 'unlimited perspective combinations' which implies broad applicability but gives no explicit when/when-not instructions or prerequisites for usage.

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