search_contacts
Search contacts by name, phone, or email directly through the iMessage MCP Server, enabling quick access to contact details within the macOS Contacts and Messages apps.
Instructions
Search contacts by name, phone, or email
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Search query |
Implementation Reference
- src/index.ts:141-154 (registration)Registration of the 'search_contacts' tool in the ListToolsRequestSchema handler, including name, description, and input schema definition.{ name: "search_contacts", description: "Search contacts by name, phone, or email", inputSchema: { type: "object", properties: { query: { type: "string", description: "Search query", }, }, required: ["query"], }, },
- src/index.ts:199-262 (handler)Handler implementation for the 'search_contacts' tool in the CallToolRequestSchema switch statement. It constructs an AppleScript to search contacts by query string matching name, executes it via runAppleScript, and returns JSON results or error.case "search_contacts": { const query = String(request.params.arguments?.query).toLowerCase(); const script = ` tell application "Contacts" set output to "[" set isFirst to true repeat with p in every person if ((name of p as text) contains "${query}") then if not isFirst then set output to output & "," end if set output to output & "{" set output to output & "\\"name\\":\\"" & (name of p as text) & "\\"," set output to output & "\\"phones\\":[" set firstPhone to true repeat with ph in phones of p if not firstPhone then set output to output & "," end if set output to output & "\\"" & (value of ph) & "\\"" set firstPhone to false end repeat set output to output & "]," set output to output & "\\"emails\\":[" set firstEmail to true repeat with em in emails of p if not firstEmail then set output to output & "," end if set output to output & "\\"" & (value of em) & "\\"" set firstEmail to false end repeat set output to output & "]" set output to output & "}" set isFirst to false end if end repeat return output & "]" end tell `; try { const results = await runAppleScript(script); return { content: [ { type: "text", text: results, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Search failed: ${getErrorMessage(error)}`, }, ], isError: true, }; } }