messaging-mcp
by familiar-ai
README.md
# messaging-mcp
A local macOS service and stdio MCP server. An AI agent uses it to send iMessage, WhatsApp and Signal messages as you, under a send policy you control. It can also read recent incoming iMessage and WhatsApp messages. It works with Claude Code, Codex and other MCP clients.
A launchd service alone holds the macOS privacy grants, the policy file and the send log. Agents reach it through `messaging-mcp mcp`, an unprivileged stdio bridge. [DESIGN.md](DESIGN.md) explains why.
**Status:** pre-release. Tested against fake `imsg`, `wacli`, `signal-cli`, `qrencode` and `osascript` binaries and with real Claude Code. Not yet tested with real iMessage, WhatsApp or Signal accounts or with real launchd privacy grants.
## Security model
It protects against a **confused agent**: a mistake, or a prompt injection in an incoming message.
- **Recipients:** an allowlist by default, or your approval per message, or open. Never groups.
- **Volume:** an hourly cap, a same-text window per contact, and at most one send per `(job_id, contact_id)`.
- **Kill switch:** `sending: false` refuses every send at once.
- **No blind retries:** a send that may have gone out (`unknown`) blocks that contact until you check and run `messaging-mcp resolve`.
- **Reads:** off by default. Text shows only for allowlisted 1:1 contacts, never for groups or SMS.
It does **not** protect against an agent with shell access as your user. Such an agent can edit `~/.config/messaging-mcp/allowlist.json`, add a client hook that answers approvals, or run `wacli` or `signal-cli` itself. Deny agents access to `~/.config/messaging-mcp/`, to client settings files, to `messaging-mcp setup` and `messaging-mcp resolve`, and to `wacli` and `signal-cli`, for example with Claude Code `permissions.deny` or a sandbox. Never grant Full Disk Access or Automation to a terminal or an agent app.
## Requirements
- macOS 15 or later, kept awake, and [Bun](https://bun.sh) on `PATH`.
- iMessage: Messages signed in, and `brew install steipete/tap/imsg`.
- WhatsApp: `brew install openclaw/tap/wacli`.
- Signal: `brew install signal-cli` and `brew install qrencode`. Without `qrencode` the link shows as text, which a phone cannot scan.
A service you turn off needs none of its CLIs or permissions. Only iMessage is on by default.
## Quick start
1. Clone the repository:
```sh
git clone https://github.com/familiar-ai/messaging-mcp ~/code/messaging-mcp
cd ~/code/messaging-mcp
```
2. Write the policy file. With no flags, `setup` prompts for contacts, which needs a terminal. Pick the line for your services:
```sh
# iMessage only
bun cli.ts setup --contact 'imessage:+14155551212=Mum'
# WhatsApp only: --whatsapp shows a QR code; scan it in WhatsApp > Settings > Linked devices > Link a device
bun cli.ts setup --service imessage=off --whatsapp --contact 'whatsapp:+14155551212=Mum'
# Signal only: --signal shows a QR code; scan it in Signal > Settings > Linked devices > Link new device
bun cli.ts setup --service imessage=off --signal --contact 'signal:+14155551212=Mum'
```
3. Install and start the service:
```sh
bun cli.ts install-service
```
This builds `~/.local/share/messaging-mcp/bin/messaging-mcp`, links it as `~/.local/bin/messaging-mcp`, writes and loads `~/Library/LaunchAgents/com.familiar.messaging-mcp.plist`. It stops and changes nothing if another file holds `~/.local/bin/messaging-mcp`. If `~/.local/bin` is not on your `PATH`, it says so. `--no-load` writes the files without loading them. With iMessage on, it prints the grant steps for the service binary:
- **Full Disk Access:** System Settings > Privacy & Security > Full Disk Access > `+` > `Cmd-Shift-G` > paste `~/.local/share/messaging-mcp/bin/messaging-mcp`.
- **Automation:** click **Allow** when the service first asks to control Messages.
- **After a change**, restart the service: `launchctl kickstart -k gui/$(id -u)/com.familiar.messaging-mcp`.
The last line is `Next:` with the doctor command to run.
4. Check everything. Run the `Next:` line as printed: it is the bare `messaging-mcp` only when `~/.local/bin` is on your `PATH`, else the full path, and the same holds for every `fix:` line.
```sh
messaging-mcp doctor # one line per check; exits 1 on any failure
messaging-mcp doctor --json # {"ok", "next", "checks": [{"name", "ok", "detail", "fix"}]}
```
Each failed check prints its `fix:`, and the last line is `Next:` with the first fix to run, or `All checks passed.` A send still running shows as `send in progress`, not a failure. Doctor checks the policy file, each CLI that is on (on the service PATH, `/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin`), WhatsApp pairing and the Signal link, the service and its socket (`0600` in a `0700` directory), the iMessage grants, and unresolved `unknown` sends.
5. Add the server to your agent:
```sh
claude mcp add messages -- ~/.local/bin/messaging-mcp mcp
```
Codex, in `~/.codex/config.toml`:
```toml
[mcp_servers.messages]
command = "/Users/<you>/.local/bin/messaging-mcp"
args = ["mcp"]
```
Later changes with `messaging-mcp setup` take effect on the next call. No restart is needed, also not after you install a CLI or pair a service. To update, pull and run `bun cli.ts install-service` again, then give the grants again: a new binary loses them.
If you set `MESSAGING_MCP_HOME`, set it for setup, the service and the MCP client alike. While the service is down, calls fail with `service_unavailable`. A client that starts while the service is down fails to connect to the server: run `messaging-mcp doctor`, then restart the client. A call in flight when the service stops fails with `service_disconnected`: check the conversation before you retry. The bridge reconnects by itself.
## Tools
| Tool | Default | What it does |
|---|---|---|
| `messages_send` | always on | Sends one 1:1 message: `job_id`, `contact_id`, `text`. |
| `messages_contacts` | on | Lists allowlisted contacts (`id`, `label`, `service`) of the services that are on. Does not read Contacts.app. |
| `messages_recent_incoming` | off | Recent incoming iMessage and WhatsApp messages (`channel`, `since_minutes`, `limit`), newest first. Text and label only for allowlisted 1:1 contacts. Never Signal. |
A tool that is off is missing from `tools/list` and answers as an unknown tool.
`messages_send` returns `{effect_id, delivery, duplicate, summary}` and, when one applies, `condition: {type, message}`. The message tells the agent what to do next. `delivery` is `sent`, `not_sent` or `unknown`. A repeat of the same `(job_id, contact_id)` returns the first result with `duplicate: true` and sends nothing. A refusal is an error result `{refused, delivery: "not_sent", message}`, for example `not_allowlisted`, `rate_limited`, `same_text`, `service_off` or `contact_unresolved`.
## Configuration
The policy file is `~/.config/messaging-mcp/allowlist.json` (mode `0600`). Every call reads it again. An invalid file refuses every send. Missing keys take their defaults, and `schema` is optional.
```json
{
"schema": "messaging-mcp.allowlist.v1",
"sending": true,
"max_sends_per_hour": 10,
"same_text_window_minutes": 10,
"tools": { "contacts": true, "recent_incoming": false },
"services": { "imessage": true, "whatsapp": false, "signal": false },
"send_policy": "allowlist",
"approval_command": ["/Users/<you>/bin/approve-message"],
"contacts": [{ "id": "imessage:+14155551212", "label": "Mum" }]
}
```
| Key | Default | `setup` flag | Meaning |
|---|---|---|---|
| `sending` | `true` | `--sending on\|off` | Kill switch for every policy. |
| `max_sends_per_hour` | `10` | `--max-sends-per-hour <n>` | Cap for all contacts, 1 to 100. Denied approvals count. |
| `same_text_window_minutes` | `10` | edit the file | Refuses the same text to the same contact within this many minutes. 0 to 1440, `0` turns it off. |
| `tools.contacts` | `true` | `--contacts-tool on\|off` | Offer `messages_contacts`. |
| `tools.recent_incoming` | `false` | `--recent-incoming on\|off` | Offer `messages_recent_incoming`. |
| `services` | iMessage on | `--service <name>=on\|off`, `--whatsapp`, `--signal` | A service that is off never sends, never shows and never runs. |
| `send_policy` | `allowlist` | `--send-policy allowlist\|approve\|open` | Who the agent can message. |
| `approval_command` | none | `--approval-command '<JSON list>'`, `'[]'` clears | Your approver program under `approve`. |
| `contacts` | none | `--contact <id>=<label>`, `--remove <id>` | Allowlisted 1:1 contacts. |
Contact IDs are printable ASCII and take these forms: `imessage:+14155551212` or `imessage:sam@icloud.com`, `whatsapp:14155551212@s.whatsapp.net` (also `whatsapp:+14155551212`), and `signal:+14155551212` or `signal:<uuid>`.
### Send policies
- **`allowlist`** (default): sends only to listed contacts, with no prompt.
- **`approve`:** sends to any valid 1:1 contact after you approve it. An unlisted Signal contact must be a phone number; a Signal UUID must be on the allowlist. The service asks in this order:
1. `approval_command`, if set. It runs without a shell and gets `{"effect_id","contact_id","label","service","text"}` on stdin (`label` is `null` for an unlisted contact). Exit 0 approves. Any other exit, or no answer in 30 s, denies.
2. MCP elicitation, if the client declared it. The prompt names the service and the recipient first and quotes each line of the text. Only `accept` approves. Claude Code supports it in interactive sessions (tested on 2.1.332). In `claude -p`, a prompt is cancelled at once.
3. Neither: the send is refused with `approval_unavailable`.
A denial, a timeout or a cancelled call is `not_sent` (`ApprovalDenied` or `ApprovalTimedOut`) and does not block the contact. The same `job_id` does not ask again. The policy file and the limits are checked again after you approve.
- **`open`:** sends to any valid 1:1 contact with no approval, with the same Signal rule. To turn it on, or to turn reading on under it, you type `OPEN` at a terminal.
> **CAUTION:** Do not use `open` with `recent_incoming`. Untrusted incoming text can make the agent message anyone.
## Delivery states and `resolve`
Each send writes a row to `~/.config/messaging-mcp/sends.sqlite` before it runs the CLI. Text is 1 to 2000 characters, with no control characters other than newline and tab, and no bidi controls.
| `delivery` | When |
|---|---|
| `sent` | `imsg` printed `"status":"sent"`, `wacli` returned `sent: true`, or `signal-cli` exited 0 and every result is `SUCCESS`. |
| `not_sent` | A refusal or denied approval, a CLI that could not start, or a CLI error that proves nothing left the Mac: `imsg` `not_started`, `wacli` `not authenticated` or `store locked`, Signal not linked or more than one Signal account, `signal-cli` `UNREGISTERED_FAILURE` with exit 1, `IDENTITY_FAILURE` with 4, `RATE_LIMIT_FAILURE` with 5. |
| `unknown` | No answer in 90 s, a crash, any other CLI error, or a send log that could not be written. |
While a contact has an `unknown` send, new sends to it are refused. Check the conversation, then settle it. `resolve` refuses a send that may still be running, up to 100 s after it started.
```sh
messaging-mcp resolve <effect_id> sent # or not-sent
```
## Limits
- **Per ID, not per person.** Dedupe, the same-text window, the `unknown` block and open approvals apply per contact ID. A phone number and an email of one person, a Signal phone number and UUID, or one person on two services are separate contacts.
- **Dedupe:** a new `job_id` is a new send. The rate limit, the same-text window and the `unknown` block still apply.
- **Allowlist visibility:** with `messages_contacts` off, refusals still show whether an ID is listed.
- **Approval programs:** a timeout or cancel kills only the process the service started. Use `exec` in wrapper scripts.
- **iMessage:** sends with `--service=imessage`, never SMS. SMS is never read: its sender can be spoofed. Reads check the 50 newest chats up to 24 h back. Attachments show as `[attachment]`.
- **WhatsApp:** `wacli` uses the unofficial WhatsApp Web protocol, so the account can be banned. While WhatsApp is on and paired, the service keeps `wacli sync --follow` running. Media shows as `[image]` and similar.
- **Signal:** send only, through the unofficial GPL-3.0 `signal-cli` run as a separate program, so the account can be banned. Its data is in `~/.config/messaging-mcp/signal/`, of which only `data/accounts.json` is read. The service never runs `signal-cli receive`. Not tested: whether Signal unlinks a device that never receives. If sends fail, link again with `setup --signal`. That `signal-cli link` prints its URI on stdout is assumed from its source, not tested.
## Uninstall
```sh
claude mcp remove messages
launchctl bootout gui/$(id -u)/com.familiar.messaging-mcp
rm ~/Library/LaunchAgents/com.familiar.messaging-mcp.plist ~/.local/bin/messaging-mcp
rm -r ~/.local/share/messaging-mcp
```
Remove the binary from Full Disk Access and Automation in System Settings. To delete the policy file, the send log and the WhatsApp and Signal links, also delete `~/.config/messaging-mcp/`.
## Development
`bun install`, then `bun run check` runs `tsc`, the unit tests and `test/e2e.ts` against the fake CLIs in `test/fake-bin/`. It never sends a message. Tests point the service at the fakes with `MESSAGING_MCP_IMSG`, `MESSAGING_MCP_WACLI`, `MESSAGING_MCP_SIGNAL_CLI`, `MESSAGING_MCP_OSASCRIPT` and `MESSAGING_MCP_CHAT_DB`, and shorten its timeouts with `MESSAGING_MCP_SEND_TIMEOUT_MS`, `MESSAGING_MCP_READ_TIMEOUT_MS`, `MESSAGING_MCP_APPROVAL_TIMEOUT_MS`, `MESSAGING_MCP_LINK_TIMEOUT_MS` and `MESSAGING_MCP_SYNC_INTERVAL_MS`.
## License
MIT. See [LICENSE](LICENSE).
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues