messages_compose_message
Open Messages app with a pre-filled message or automatically send it to a recipient using macOS AppleScript integration.
Instructions
[iMessage operations] Open Messages app with a pre-filled message to a recipient or automatically send a message
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| auto | No | Automatically send the message without user confirmation | |
| body | No | Message body text | |
| recipient | Yes | Phone number or email of the recipient |
Implementation Reference
- src/categories/messages.ts:257-302 (handler)Handler function that generates the AppleScript executed when 'messages_compose_message' tool is called. Handles both auto-send and pre-fill modes.script: (args) => ` on run -- Get the recipient and message body set recipient to "${args.recipient}" set messageBody to "${args.body || ''}" set autoSend to ${args.auto === true ? "true" : "false"} if autoSend then -- Automatically send the message using AppleScript tell application "Messages" -- Get the service (iMessage or SMS) set targetService to 1st service whose service type = iMessage -- Send the message set targetBuddy to buddy "${args.recipient}" of targetService send "${args.body || ''}" to targetBuddy return "Message sent to " & "${args.recipient}" end tell else -- Just open Messages app with pre-filled content -- Create the SMS URL with proper URL encoding set smsURL to "sms:" & recipient if messageBody is not equal to "" then -- Use percent encoding for spaces instead of plus signs set encodedBody to "" repeat with i from 1 to count of characters of messageBody set c to character i of messageBody if c is space then set encodedBody to encodedBody & "%20" else set encodedBody to encodedBody & c end if end repeat set smsURL to smsURL & "&body=" & encodedBody end if -- Open the URL with the default handler (Messages app) do shell script "open " & quoted form of smsURL return "Opening Messages app with recipient: " & recipient end if end run `
- src/categories/messages.ts:237-256 (schema)Input schema for the 'messages_compose_message' tool defining parameters: recipient (required), body, and auto-send flag.schema: { type: "object", properties: { recipient: { type: "string", description: "Phone number or email of the recipient" }, body: { type: "string", description: "Message body text", default: "" }, auto: { type: "boolean", description: "Automatically send the message without user confirmation", default: false } }, required: ["recipient"] },
- src/framework.ts:221-232 (registration)Dynamic registration of all tools in ListToolsRequestSchema handler. Constructs tool name as 'messages_compose_message' from category 'messages' and script 'compose_message'.this.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: this.categories.flatMap((category) => category.scripts.map((script) => ({ name: `${category.name}_${script.name}`, // Changed from dot to underscore description: `[${category.description}] ${script.description}`, inputSchema: script.schema || { type: "object", properties: {}, }, })), ), }));
- src/index.ts:34-34 (registration)Registers the 'messages' category (containing compose_message script) with the MCP server framework.server.addCategory(messagesCategory);
- src/index.ts:11-11 (registration)Imports the messages category definition containing the 'compose_message' script.import { messagesCategory } from "./categories/messages.js";