send_imessage
Send iMessages via the Messages app by specifying a recipient and message content using a local server interface.
Instructions
Send an iMessage using Messages app
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| message | Yes | Message content to send | |
| recipient | Yes | Phone number or email of the recipient |
Implementation Reference
- src/index.ts:161-197 (handler)Handler for the 'send_imessage' tool. Extracts recipient and message from arguments, escapes the message, runs AppleScript via runAppleScript to send the iMessage, and returns success or error content.case "send_imessage": { const recipient = String(request.params.arguments?.recipient); const message = String(request.params.arguments?.message); if (!recipient || !message) { throw new Error("Recipient and message are required"); } const escapedMessage = message.replace(/"/g, '\\"'); const script = ` tell application "Messages" send "${escapedMessage}" to buddy "${recipient}" of (service 1 whose service type = iMessage) end tell `; try { await runAppleScript(script); return { content: [ { type: "text", text: `Message sent successfully to ${recipient}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Failed to send message: ${getErrorMessage(error)}`, }, ], isError: true, }; } }
- src/index.ts:126-139 (schema)Input schema for the 'send_imessage' tool, defining required 'recipient' and 'message' string properties.inputSchema: { type: "object", properties: { recipient: { type: "string", description: "Phone number or email of the recipient", }, message: { type: "string", description: "Message content to send", }, }, required: ["recipient", "message"], },
- src/index.ts:123-141 (registration)Registration of the 'send_imessage' tool in the ListToolsRequestSchema handler, including name, description, and input schema.{ name: "send_imessage", description: "Send an iMessage using Messages app", inputSchema: { type: "object", properties: { recipient: { type: "string", description: "Phone number or email of the recipient", }, message: { type: "string", description: "Message content to send", }, }, required: ["recipient", "message"], }, }, {
- src/index.ts:29-36 (helper)Helper function used by the send_imessage handler to execute AppleScript for sending the message.async function runAppleScript(script: string): Promise<string> { try { const { stdout } = await execFileAsync("osascript", ["-e", script]); return stdout.trim(); } catch (error) { throw new Error(`AppleScript error: ${getErrorMessage(error)}`); } }