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
| Name | Required | Description | Default |
|---|---|---|---|
| format | No | Output 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); } })();