send_group_message
Send messages to iMessage group chats by specifying the group name and message text. This tool enables direct communication with multiple recipients through the iMessage platform on macOS.
Instructions
Send a message to a named group chat.
Args: group_name: The display name of the group chat text: Message text to send
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| group_name | Yes | ||
| text | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- server.py:270-311 (handler)The main handler function for the `send_group_message` tool, which queries the database for the chat identifier and uses `osascript` to send the message via AppleScript.
async def send_group_message(group_name: str, text: str) -> str: """Send a message to a named group chat. Args: group_name: The display name of the group chat text: Message text to send """ # Resolve group name to chat identifier db = _get_db() row = db.execute( "SELECT chat_identifier FROM chat WHERE display_name = ? LIMIT 1", (group_name,), ).fetchone() db.close() if not row: return json.dumps({"error": f"Group chat '{group_name}' not found"}) escaped_text = _escape_applescript(text) chat_id = row["chat_identifier"] script = ( 'tell application "Messages"\n' f' send "{escaped_text}" to chat id "{chat_id}"\n' "end tell" ) proc = await asyncio.create_subprocess_exec( "osascript", "-e", script, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE, ) stdout, stderr = await proc.communicate() if proc.returncode != 0: return json.dumps( {"error": f"Failed to send to group: {stderr.decode().strip()}"} ) return json.dumps( {"status": "sent", "group": group_name, "chat_identifier": chat_id} ) - server.py:269-270 (registration)Tool registration using the `@mcp.tool()` decorator.
@mcp.tool() async def send_group_message(group_name: str, text: str) -> str: