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