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); } })();