Skip to main content
Glama
jcontini

macOS Contacts MCP

by jcontini

get_contact

Retrieve complete contact details from the macOS Contacts app by providing a contact name or unique ID, enabling quick access to essential information.

Instructions

Get full contact details by name or ID

Input Schema

NameRequiredDescriptionDefault
identifierYesContact name or unique ID

Input Schema (JSON Schema)

{ "properties": { "identifier": { "description": "Contact name or unique ID", "type": "string" } }, "required": [ "identifier" ], "type": "object" }

Implementation Reference

  • The core handler function for the 'get_contact' tool. It takes an identifier (name or ID), executes AppleScript to fetch basic contact info from macOS Contacts app, then separately fetches emails, phones, and URLs, assembling a complete Contact object.
    private async getContact(args: any): Promise<any> { const { identifier } = args; // Simple approach - get basic info first, then build up let script = `tell application "Contacts" try set targetPerson to person id "${identifier}" on error try set targetPerson to person "${identifier}" on error return "Contact not found" end try end try return id of targetPerson & "|" & name of targetPerson & "|" & organization of targetPerson & "|" & job title of targetPerson & "|" & note of targetPerson end tell`; try { const result = this.executeAppleScript(script); if (result === 'Contact not found') { return { success: false, message: 'Contact not found' }; } const parts = result.split('|'); const contact: any = { id: parts[0] || '', name: parts[1] || '', organization: parts[2] || '', job_title: parts[3] || '', note: parts[4] || '', }; // Get emails separately try { const emailScript = `tell application "Contacts" set targetPerson to person id "${contact.id}" set emailList to {} repeat with anEmail in emails of targetPerson set end of emailList to value of anEmail end repeat return emailList end tell`; const emailResult = this.executeAppleScript(emailScript); contact.emails = emailResult ? emailResult.split(', ') : []; } catch { contact.emails = []; } // Get phones separately try { const phoneScript = `tell application "Contacts" set targetPerson to person id "${contact.id}" set phoneList to {} repeat with aPhone in phones of targetPerson set end of phoneList to value of aPhone end repeat return phoneList end tell`; const phoneResult = this.executeAppleScript(phoneScript); contact.phones = phoneResult ? phoneResult.split(', ') : []; } catch { contact.phones = []; } // Get URLs separately try { const urlScript = `tell application "Contacts" set targetPerson to person id "${contact.id}" set urlList to {} repeat with aUrl in urls of targetPerson set end of urlList to (label of aUrl & ":" & value of aUrl) end repeat return urlList end tell`; const urlResult = this.executeAppleScript(urlScript); if (urlResult) { contact.urls = urlResult.split(', ').map(item => { const [label, ...valueParts] = item.split(':'); return { label: label || '', value: valueParts.join(':') || '' }; }); } else { contact.urls = []; } } catch { contact.urls = []; } return { success: true, contact }; } catch (error) { throw new Error(`Get contact failed: ${error}`); } }
  • src/index.ts:66-79 (registration)
    Registration of the 'get_contact' tool in the ListToolsRequestSchema handler, defining its name, description, and input schema.
    { name: 'get_contact', description: 'Get full contact details by name or ID', inputSchema: { type: 'object', properties: { identifier: { type: 'string', description: 'Contact name or unique ID', }, }, required: ['identifier'], }, },
  • Input schema definition for the 'get_contact' tool, specifying the required 'identifier' parameter.
    inputSchema: { type: 'object', properties: { identifier: { type: 'string', description: 'Contact name or unique ID', }, }, required: ['identifier'], },
  • Dispatcher case in the CallToolRequestSchema handler that routes 'get_contact' calls to the getContact method.
    case 'get_contact': result = await this.getContact(args); break;
  • Helper method used by getContact to execute AppleScript commands against the macOS Contacts app.
    private executeAppleScript(script: string): string { try { // Use stdin to pass the script, avoiding shell escaping issues entirely const result = execSync(`osascript`, { input: script, encoding: 'utf8', }).trim(); return result; } catch (error: any) { throw new Error(`AppleScript execution failed: ${error}`); } }

Other Tools

Related Tools

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/jcontini/macos-contacts-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server