Skip to main content
Glama
jqlts1

OmniFocus MCP Enhanced

by jqlts1

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