Skip to main content
Glama
Google Messages MCP

Google Messages MCP

by ilakskill
README.md
# google-messages-mcp

Local MCP server (stdio) that drives **Google Messages for Web** (https://messages.google.com/web) with Playwright, so AI agents can read and send the SMS/RCS on your Android phone. There is no official API; this automates the web app in a dedicated, persistent Chromium profile.

- Entry: `src/server.mjs` (MCP tools, send-token safety)
- Browser/session + **all DOM selectors**: `src/browser.mjs` (`SELECTORS` at the top)
- Profile (pairing lives here; treat as a credential): `~/.google-messages-mcp/profile` (`%USERPROFILE%\.google-messages-mcp\profile` on Windows)
- QR screenshot: `~/.google-messages-mcp/qr.png`

## Install

```bash
git clone https://github.com/ilakskill/google-messages-mcp.git
cd google-messages-mcp
npm install
npx playwright install chromium
npm run smoke            # tools/list + gmsg_status, no browser launch
```

## MCP registration

Claude Code (user scope), with the absolute path to your clone:

```bash
claude mcp add google-messages --scope user -- node /absolute/path/to/google-messages-mcp/src/server.mjs
```

Generic JSON (Claude Desktop / Cursor / Gemini / Antigravity `mcpServers`; VS Code uses `servers`):

```json
{
  "mcpServers": {
    "google-messages": {
      "command": "node",
      "args": ["/absolute/path/to/google-messages-mcp/src/server.mjs"]
    }
  }
}
```

Only one process can open the profile at a time, so only one MCP client can actively use the server at once. A second client gets `PROFILE_LOCKED` until the first one exits.

## Pairing (one time, needs your phone)

Ask an agent to run `gmsg_pair` (or `wait_seconds: 0` first to get instructions right away).

1. The server opens a **visible** browser on the pairing page.
2. **If Google offers a QR code:** it turns on "Remember this computer", saves `qr.png` and returns the QR as an image. On the phone: Messages app > profile picture > **Device pairing** > **QR code scanner**, then scan.
3. **If Google offers no QR code** (what the live site did on 2026-12-01: `/web/authentication` redirected to `/web/welcome`, which only has "Sign In"): Google blocks sign-in in Playwright-controlled browsers, so the server opens the same profile in a **plain, non-automated** browser window. In that window: click **Sign In**, sign in with the **same Google account the phone's Messages app uses**, and approve on the phone when prompted (matching emoji / prompt). Say yes to remembering this computer if asked.
4. The server detects your conversation list, waits a few seconds, closes the window, and confirms pairing by reopening the profile under Playwright. Later calls run headless.

If the wait times out the window stays open; finish there and call `gmsg_pair` again (it resumes waiting). `gmsg_pair` with `method: "cancel"` closes a leftover sign-in window. Force a path with `method: "qr"` or `method: "signin"`.

## Tools

All tools return JSON text: `{"ok":true,"data":...}` or `{"ok":false,"code","message","remedy"}`. They never throw. Browser work is serialized through a single queue.

| Tool | Args | What it does |
|---|---|---|
| `gmsg_status` | `check?` | Browser up, paired, page URL, last error. `check:true` launches headless to test pairing. Never queued behind a running pair. |
| `gmsg_pair` | `wait_seconds?=120`, `method?=auto\|qr\|signin\|cancel` | Pairing (above). |
| `gmsg_list_conversations` | `limit?=20`, `unread_only?=false` | name, snippet, timestamp text, unread, `conversation_id` (from `/web/conversations/<id>`). |
| `gmsg_read_conversation` | `conversation_id` or `name`, `limit?=30` | Messages with direction (incoming/outgoing), text, timestamp, aria label, status. Scrolls up for older ones. |
| `gmsg_search` | `query`, `scan?=150` | Filters the conversation list by name, snippet or digits of a number. |
| `gmsg_send_message` | one of `conversation_id` / `name` / `phone_number`, `text`, `confirm_token?` | **Two-step.** Without token: preview (resolved recipient + text) and a 5-minute, single-use token bound to the exact recipient and text hash; nothing is sent. With token: sends, then verifies the outgoing bubble and reports its status. New numbers go through Start chat. |
| `gmsg_archive_conversations` | `conversation_ids` or `all_in_inbox:true`, `confirm_token?` | **Two-step.** Without token: resolves targets and returns a preview plus token; nothing is archived. With token: archives them and records id-to-name in `~/.google-messages-mcp/archived-map.json`. |
| `gmsg_unarchive_conversations` | see tool schema, `confirm_token?` | **Two-step.** Restores conversations from the Archived view. Only conversations archived through this server (recorded in `archived-map.json`) can be targeted by id. |

Error codes: `NOT_PAIRED`, `PAIRING_IN_PROGRESS`, `PROFILE_LOCKED`, `SESSION_IN_USE`, `SELECTOR_MISSING`, `TIMEOUT`, `NOT_FOUND`, `AMBIGUOUS`, `BAD_INPUT`, `TOKEN_INVALID`, `TOKEN_MISMATCH`, `SEND_UNVERIFIED`, `BROWSER_MISSING`, `LAUNCH_FAILED`, `INTERNAL`.

## Environment variables

| Var | Default | Meaning |
|---|---|---|
| `GMSG_PROFILE_DIR` | `~/.google-messages-mcp/profile` (`%USERPROFILE%\.google-messages-mcp\profile` on Windows) | Persistent browser profile. Changing it means re-pairing. |
| `GMSG_HEADLESS` | `1` | `0` = run normal operations in a visible window. |
| `GMSG_BROWSER` | `chromium` | `chromium` (Playwright build), `chrome` (installed Google Chrome) or `msedge`. Profile is tied to the browser; switching means re-pairing. Try `chrome` if Google refuses sign-in in the Chromium build. |
| `GMSG_BROWSER_PATH` | auto | Explicit browser .exe for the manual sign-in window. |
| `GMSG_AUTO_USE_HERE` | `1` | Auto-click "Use here" on the "open in another tab" dialog. `0` = return `SESSION_IN_USE` instead. |
| `GMSG_SIGNIN_WATCH` | `1` | Sign-in window gets `--remote-debugging-port=0` so the server can see when pairing finishes and close it. `0` = no port; close the window yourself. |
| `GMSG_NAV_TIMEOUT_MS` | `45000` | Navigation timeout. |

## Troubleshooting

- **Re-pair:** if tools return `NOT_PAIRED` (phone unpaired the device, or "Remember this computer" was off), run `gmsg_pair` again. To start over completely, stop all MCP clients and point `GMSG_PROFILE_DIR` at a new empty folder; the old profile is never deleted by the server.
- **`PROFILE_LOCKED`:** another server process, a smoke/probe run, or a sign-in window has the profile open. Close it (`gmsg_pair method=cancel` for a sign-in window) and retry.
- **"Messages for web is open in another tab/window" / "Use here":** the server owns its profile and keeps a single tab, so by default it closes stray tabs in its own browser and clicks "Use here". Your own Chrome is a separate paired device and isn't affected. Set `GMSG_AUTO_USE_HERE=0` to get `SESSION_IN_USE` instead.
- **Selector updates (Google changed the DOM):** symptoms are `SELECTOR_MISSING` or empty results. Stop the MCP server, then:
  ```bash
  cd google-messages-mcp
  node scripts/probe.mjs                     # conversation list page
  node scripts/probe.mjs <conversation_id>   # a thread
  node scripts/probe.mjs --new               # Start chat page
  GMSG_HEADLESS=0 node scripts/probe.mjs     # watch it
  ```
  It prints which `SELECTORS` entries match and saves `probe.png` + `probe-dom.html` in `~/.google-messages-mcp` (these contain message content; keep private). Fix the list in `SELECTORS` in `src/browser.mjs` (put the working selector first). In Git Bash, prefix path arguments with `MSYS_NO_PATHCONV=1`.
- **Headless blocked or blank:** set `GMSG_HEADLESS=0` and watch. The server already removes "HeadlessChrome" from the user agent.
- **Logs:** stderr only (stdout is the MCP channel). Claude Code shows them with `claude --debug` / MCP logs.

## Selector status

Verified live (unpaired) on 2026-12-01: the welcome page (`[data-e2e-welcome-page-sign-in-button]`) and the `/web/authentication` to `/web/welcome` redirect. **Everything for a paired session (conversation list, threads, compose, send, Start chat, QR element, Remember toggle, Use here) is best-known and UNVERIFIED** until a paired probe run. Entries are tagged `[UNVERIFIED]` in `SELECTORS`.

## Smoke test

```bash
cd google-messages-mcp
node scripts/smoke.mjs                       # tools/list + gmsg_status
node scripts/smoke.mjs --check --validate    # + headless pairing check + send input validation
node scripts/smoke.mjs --list                # + list 5 conversations (needs pairing)
node scripts/smoke.mjs --qr                  # + gmsg_pair method=qr wait 0 (visible window)
```

The smoke test never sends a message.

## Disclaimer

Unofficial. Not affiliated with or endorsed by Google. It automates the Google Messages web app, which can change or block automation at any time. The browser profile grants full access to your messages; never share or commit it.

## License

MIT. See [LICENSE](LICENSE).

TDQS

A4/5.0

Scored across 8 tools

Disambiguation5/5

Each tool targets a distinct action on a distinct resource: send, list, read, search, archive, unarchive, pair, status. The archive/unarchive pair are clearly opposite operations, and search vs. list are distinguished (query-based scan vs. recent conversations). Status (read state) vs. pair (initiate pairing) are separated by explicit descriptions.

Naming Consistency4/5

All tools share the gmsg_ prefix and snake_case, giving a predictable namespace. Minor deviation: several tools are bare verbs/nouns (gmsg_status, gmsg_pair, gmsg_search) rather than verb_noun, but the convention remains readable and consistent in style.

Tool Count5/5

Eight tools is well within the sweet spot and each earns its place: core messaging (send/list/read/search), lifecycle management (archive/unarchive), and setup/diagnostics (pair/status). Nothing appears redundant or padded.

Completeness4/5

The core read/send/search workflow plus archive lifecycle and pairing is covered, including two-step confirmation for destructive actions. Gaps remain: no way to list archived conversations directly (unarchive requires remembered ids), and no delete-conversation, mark read/unread, or media/attachment sending.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues