Skip to main content
Glama

list_custom_perspectives

Retrieve all custom perspectives in OmniFocus with options for simple or detailed output, enabling efficient task management and workflow organization through the Model Context Protocol server.

Instructions

List all custom perspectives defined in OmniFocus

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
formatNoOutput format: simple (names only) or detailed (with identifiers) - default: simple

Implementation Reference

  • src/server.ts:136-141 (registration)
    Registration of the 'list_custom_perspectives' tool in the MCP server, linking to schema and handler from definitions.
    server.tool(
      "list_custom_perspectives",
      "List all custom perspectives defined in OmniFocus",
      listCustomPerspectivesTool.schema.shape,
      listCustomPerspectivesTool.handler
    );
  • Zod schema defining the input parameters for the list_custom_perspectives tool.
    export const schema = z.object({
      format: z.enum(['simple', 'detailed']).optional().describe("Output format: simple (names only) or detailed (with identifiers) - default: simple")
    });
  • MCP tool handler for list_custom_perspectives, which calls the primitive function and formats the response.
    export async function handler(args: z.infer<typeof schema>, extra: RequestHandlerExtra) {
      try {
        const result = await listCustomPerspectives({
          format: args.format || 'simple'
        });
        
        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 listing custom perspectives: ${errorMessage}`
          }],
          isError: true
        };
      }
    }
  • Helper function that executes the OmniFocus script, processes the JSON result, and formats the output based on format option.
    export async function listCustomPerspectives(options: ListCustomPerspectivesOptions = {}): Promise<string> {
      const { format = 'simple' } = options;
      
      try {
        console.log('🚀 匀始执行 listCustomPerspectives 脚本...');
        
        // Execute the list custom perspectives script
        const result = await executeOmniFocusScript('@listCustomPerspectives.js', {});
        
        console.log('📋 脚本执行完成结果类型:', typeof result);
        console.log('📋 脚本执行结果:', result);
        
        // 倄理各种可胜的返回类型
        let data: any;
        
        if (typeof result === 'string') {
          console.log('📝 结果是字笊䞲尝试解析 JSON...');
          try {
            data = JSON.parse(result);
            console.log('✅ JSON 解析成功:', data);
          } catch (parseError) {
            console.error('❌ JSON 解析倱莥:', parseError);
            throw new Error(`解析字笊䞲结果倱莥: ${result}`);
          }
        } else if (typeof result === 'object' && result !== null) {
          console.log('🔄 结果是对象盎接䜿甚...');
          data = result;
        } else {
          console.error('❌ 无效的结果类型:', typeof result, result);
          throw new Error(`脚本执行返回了无效的结果类型: ${typeof result}, 倌: ${result}`);
        }
        
        // 检查是吊有错误
        if (!data.success) {
          throw new Error(data.error || 'Unknown error occurred');
        }
        
        // 栌匏化蟓出
        if (data.count === 0) {
          return "📋 **自定义透视列衚**\n\n暂无自定义透视。";
        }
        
        if (format === 'simple') {
          // 简单栌匏只星瀺名称列衚
          const perspectiveNames = data.perspectives.map((p: any) => p.name);
          return `📋 **自定义透视列衚** (${data.count}䞪)\n\n${perspectiveNames.map((name: string, index: number) => `${index + 1}. ${name}`).join('\n')}`;
        } else {
          // 诊细栌匏星瀺名称和标识笊
          const perspectiveDetails = data.perspectives.map((p: any, index: number) => 
            `${index + 1}. **${p.name}**\n   🆔 ${p.identifier}`
          );
          return `📋 **自定义透视列衚** (${data.count}䞪)\n\n${perspectiveDetails.join('\n\n')}`;
        }
        
      } catch (error) {
        console.error('Error in listCustomPerspectives:', error);
        return `❌ **错误**: ${error instanceof Error ? error.message : String(error)}`;
      }
    }
  • Core OmniFocus AppleScript/JXA script that fetches all custom perspectives using Perspective.Custom.all and returns JSON.
    // 获取所有自定义透视列衚
    // 基于 OmniJS API: Perspective.Custom.all
    
    (() => {
      try {
        // 获取所有自定义透视
        const customPerspectives = Perspective.Custom.all;
        
        // 栌匏化结果
        const perspectives = customPerspectives.map(p => ({
          name: p.name,
          identifier: p.identifier
        }));
        
        // 返回结果
        const result = {
          success: true,
          count: perspectives.length,
          perspectives: perspectives
        };
        
        return JSON.stringify(result);
        
      } catch (error) {
        // 错误倄理
        const errorResult = {
          success: false,
          error: error.message || String(error),
          count: 0,
          perspectives: []
        };
        
        return JSON.stringify(errorResult);
      }
    })();

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