mac-wa-mcp

v0.1.0
mac-wa-mcp Checked 1 day ago Published 4 months ago

WhatsApp MCP server (stdio) — pair with `wa` CLI (mac-wa)

This is a Model Context Protocol (MCP) server for WhatsApp. With this you can search and read your personal Whatsapp messages (including images, videos, documents, and audio messages), search your contacts and send messages to either individuals or groups. You can also send media files including images, videos, documents, and audio messages. It connects to your personal WhatsApp account directly via the Whatsapp web multidevice API (using the whatsmeow library).

Summary extracted from the README.

CLI + MCP (imsg pattern): wa / wa-mcp — see README.CLI.md

WhatsApp MCP Server

This is a Model Context Protocol (MCP) server for WhatsApp.

With this you can search and read your personal Whatsapp messages (including images, videos, documents, and audio messages), search your contacts and send messages to either individuals or groups. You can also send media files including images, videos, documents, and audio messages.

It connects to your personal WhatsApp account directly via the Whatsapp web multidevice API (using the whatsmeow library). All your messages are stored locally in a SQLite database and only sent to an LLM (such as Claude) when the agent accesses them through tools (which you control).

Here's an example of what you can do when it's connected to Claude.

WhatsApp MCP

To get updates on this and other projects I work on enter your email here

Caution: as with many MCP servers, the WhatsApp MCP is subject to the lethal trifecta. This means that project injection could lead to private data exfiltration.

Layout

This repo has three subprojects:

  • whatsapp-bridge/ (Go) — connects to WhatsApp's web API, handles QR-code auth, and stores message history in a local SQLite DB. Run this first; everything else talks to it over localhost:8080 or reads its SQLite files directly.
  • whatsapp-mcp-server/ (Python, PyPI mac-wa-mcp) — the MCP server. Most users install only this one: it's what you point Claude Desktop/Cursor at (see Installation below).
  • wa-mcp/ (Python, PyPI wa-mcp) — the optional wa CLI: a developer/operator convenience layer for driving the bridge from a terminal (start/stop daemons, send, search) instead of through an MCP client. See CLI (wa) below.

Installation

Prerequisites

  • Go
  • Python 3.6+
  • Anthropic Claude Desktop app (or Cursor)
  • UV (Python package manager), install with curl -LsSf https://astral.sh/uv/install.sh | sh
  • FFmpeg (optional) - Only needed for audio messages. If you want to send audio files as playable WhatsApp voice messages, they must be in .ogg Opus format. With FFmpeg installed, the MCP server will automatically convert non-Opus audio files. Without FFmpeg, you can still send raw audio files using the send_file tool.

Steps

  1. Clone this repository

    git clone https://github.com/lharries/whatsapp-mcp.git
    cd whatsapp-mcp
    
  2. Run the WhatsApp bridge

    Navigate to the whatsapp-bridge directory and run the Go application:

    cd whatsapp-bridge
    go run main.go
    

    The first time you run it, you will be prompted to scan a QR code. Scan the QR code with your WhatsApp mobile app to authenticate.

    After approximately 20 days, you will might need to re-authenticate.

    Keeping it running (macOS, recommended): go run/a manually-started binary dies when the terminal closes and misses messages that arrive while it's down (the next connection then only gets them via history-sync backfill, which has weaker media-prefetch guarantees than a live connection). Run it under launchd instead:

    cd whatsapp-bridge && go build -o whatsapp-bridge .
    

    If the bridge log reports Client outdated (405), WhatsApp has rejected the pinned whatsmeow protocol version. Update the dependency with go get go.mau.fi/whatsmeow@latest, then rebuild and restart the bridge. The repository's November 2026 pin is a verified recovery baseline.

    Create ~/Library/LaunchAgents/com.mlubich.whatsapp-bridge.plist with ProgramArguments pointing at that built binary, WorkingDirectory set to whatsapp-bridge/ (it opens store/ relative to cwd), RunAtLoad + KeepAlive both true, and StandardOutPath/StandardErrorPath pointed at a log file (e.g. ~/Library/Logs/whatsapp-bridge.log) — otherwise prefetch failures only ever print to a terminal nobody's watching. Load it with:

    launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.mlubich.whatsapp-bridge.plist
    

    Only ever run one bridge instance against store/ at a time — a second one logs in with the same linked-device session and WhatsApp sends the older connection a StreamReplaced error, dropping it. If you also use the wa CLI, use wa down/wa up only for the mcp daemon once the bridge itself is launchd-managed; don't let both start a bridge process.

  3. Connect to the MCP server

    Copy the below json with the appropriate {{PATH}} values:

    {
      "mcpServers": {
        "whatsapp": {
          "command": "{{PATH_TO_UV}}", // Run `which uv` and place the output here
          "args": [
            "--directory",
            "{{PATH_TO_SRC}}/whatsapp-mcp/whatsapp-mcp-server", // cd into the repo, run `pwd` and enter the output here + "/whatsapp-mcp-server"
            "run",
            "main.py"
          ]
        }
      }
    }
    

    For Claude, save this as claude_desktop_config.json in your Claude Desktop configuration directory at:

    ~/Library/Application Support/Claude/claude_desktop_config.json
    

    For Cursor, save this as mcp.json in your Cursor configuration directory at:

    ~/.cursor/mcp.json
    
  4. Restart Claude Desktop / Cursor

    Open Claude Desktop and you should now see WhatsApp as an available integration.

    Or restart Cursor.

Windows Compatibility

If you're running this project on Windows, be aware that go-sqlite3 requires CGO to be enabled in order to compile and work properly. By default, CGO is disabled on Windows, so you need to explicitly enable it and have a C compiler installed.

Steps to get it working:

  1. Install a C compiler
    We recommend using MSYS2 to install a C compiler for Windows. After installing MSYS2, make sure to add the ucrt64\bin folder to your PATH.
    → A step-by-step guide is available here.

  2. Enable CGO and run the app

    cd whatsapp-bridge
    go env -w CGO_ENABLED=1
    go run main.go
    

Without this setup, you'll likely run into errors like:

Binary was compiled with 'CGO_ENABLED=0', go-sqlite3 requires cgo to work.

CLI (wa)

This repo also ships wa, a gradient-styled Python CLI that operates the bridge and MCP server as background daemons, sends messages via the bridge REST API, and reads contacts/chats directly from the bridge's local SQLite stores (read-only). It's a developer/operator convenience layer — it doesn't replace the MCP server or the bridge.

Installing wa

Requires uv and Python 3.11+.

cd wa-mcp
uv sync
uv run wa --help

Or install it as a standalone tool so wa is on your PATH:

uv tool install ./wa-mcp

Before you start: authenticate the bridge

wa up starts the bridge process, but a reachable bridge is not the same as an authenticated one. On first run the bridge still needs the QR-code scan described in Installation above (run cd whatsapp-bridge && go run main.go once, scan the code with your phone) before wa send/wa contacts/wa chats will return real data. wa status and wa doctor report REST reachability on port 8080, not WhatsApp auth state — a "bridge up" badge only means the process is listening.

Commands

Command Description
wa up Start the bridge and MCP server as detached background daemons (idempotent).
wa down Stop both daemons (SIGTERM, escalating to SIGKILL).
wa status Show PID and reachability for both daemons.
wa logs [-f] Tail the last 50 lines of both daemon logs; -f/--follow streams new lines.
wa send <recipient> <message> Send a WhatsApp message through the bridge REST API.
wa contacts <query> Search contacts (read-only) in the local contacts store.
wa chats [--limit N] List recent chats (read-only), most recent first.
wa media get <message-id> [-c JID] [-o DIR] [-j] Copy a message's image/video/pdf to a local file and print the path (see below).
wa media latest [-c JID | --name TEXT] [-n N] [-o DIR] [-j] Same for the newest N media messages.
wa mcp enable|disable|status [-n] Register/unregister the MCP server in Claude Code (user scope) on demand.
wa doctor Run aggregated health checks (binary, uv, daemons, DBs) with an overall verdict.

Run wa <command> --help for full per-command help.

Usage examples

# Start both daemons in the background
wa up

# Check daemon status and bridge reachability
wa status

# Tail the last 50 log lines from both daemons
wa logs

# Follow logs live
wa logs -f

# Send a message (recipient can be a phone number, a full JID like
# 15551234567@s.whatsapp.net, an @lid JID, or a @g.us group JID)
wa send 15551234567 "hello from wa"

# Search contacts by name, push name, business name, or JID substring
wa contacts "jane"

# List the 20 most recent chats (default)
wa chats

# List the 5 most recent chats
wa chats --limit 5

# Run health checks
wa doctor

# Stop both daemons
wa down

Media: wa media and the MCP download_media tool

Both use one resolver (wa-mcp/wa_cli/media.py): (1) your earlier copy, (2) the bridge's /api/download, (3) a read-only lookup in WhatsApp Desktop's local store (~/Library/Group Containers/group.net.whatsapp.WhatsApp.shared/ChatStorage.sqlite, joined on ZWAMESSAGE.ZSTANZAID = bridge message id, file at Message/<ZMEDIALOCALPATH>). The file is always copied (never moved) to ~/.wa-cli/media/<chat-jid>/<message-id>.<ext>; override with -o DIR. Why the fallback: WhatsApp's CDN returns 403 for older media and the phone no longer holds it ("media no longer available on phone"), so the bridge cannot fetch it, but Desktop downloaded it on arrival. If macOS blocks the Desktop container, the error says to grant Full Disk Access to the app running wa (Terminal/iTerm/Claude Code); nothing tries to bypass it. All databases are opened mode=ro.

wa media get 3B68BAE7B5A4D9333750 --chat 120363430434063376@g.us -j
wa media latest --name "family" -n 3 -j

MCP on demand, bridge always on

The Go bridge stays a launchd service (com.mlubich.whatsapp-bridge): it is the only thing recording incoming messages, so it must keep running. The MCP server does not: it is a stdio process that Claude Code spawns for every registered server at session start, and importing it does no work (no bridge spawn, no DB reads; the media resolver loads on the first download_media call). Keep it unregistered and turn it on only when you want tools:

wa mcp enable -n   # prints: claude mcp add --scope user whatsapp -- uv --directory <repo>/whatsapp-mcp-server run main.py
wa mcp enable      # registers; new Claude sessions start it
wa mcp disable     # claude mcp remove --scope user whatsapp
wa mcp status

Most tasks need only the CLI (wa chats, wa media ...), which costs nothing when idle.

State directory

wa stores pidfiles and logs outside the repo, under $XDG_STATE_HOME/wa-cli if XDG_STATE_HOME is set, otherwise ~/.wa-cli. This directory contains bridge.pid, bridge.log, mcp.pid, mcp.log.

Sensitive data warning: bridge.log and mcp.log under the wa state directory can contain real WhatsApp message content and contact identifiers logged by the bridge/MCP processes. Treat this directory as sensitive — don't paste its contents into issues, chats, or logs you share, and don't commit it anywhere.

wa never writes to whatsapp-bridge/store/ — contacts/chats queries open the SQLite databases read-only (mode=ro) and the bridge/MCP processes are the only writers.

Architecture Overview

This application consists of two main components:

  1. Go WhatsApp Bridge (whatsapp-bridge/): A Go application that connects to WhatsApp's web API, handles authentication via QR code, and stores message history in SQLite. It serves as the bridge between WhatsApp and the MCP server.

  2. Python MCP Server (whatsapp-mcp-server/): A Python server implementing the Model Context Protocol (MCP), which provides standardized tools for Claude to interact with WhatsApp data and send/receive messages.

Data Storage

  • All message history is stored in a SQLite database within the whatsapp-bridge/store/ directory
  • The database maintains tables for chats and messages
  • Messages are indexed for efficient searching and retrieval

Usage

Once connected, you can interact with your WhatsApp contacts through Claude, leveraging Claude's AI capabilities in your WhatsApp conversations.

MCP Tools

Claude can access the following tools to interact with WhatsApp:

  • search_contacts: Search for contacts by name or phone number
  • list_messages: Retrieve messages with optional filters and context
  • list_chats: List available chats with metadata
  • get_chat: Get information about a specific chat
  • get_direct_chat_by_contact: Find a direct chat with a specific contact
  • get_contact_chats: List all chats involving a specific contact
  • get_last_interaction: Get the most recent message with a contact
  • get_message_context: Retrieve context around a specific message
  • send_message: Send a WhatsApp message to a specified phone number or group JID
  • send_file: Send a file (image, video, raw audio, document) to a specified recipient
  • send_audio_message: Send an audio file as a WhatsApp voice message (requires the file to be an .ogg opus file or ffmpeg must be installed)
  • download_media: Download media from a WhatsApp message and get the local file path

Media Handling Features

The MCP server supports both sending and receiving various media types:

Media Sending

You can send various media types to your WhatsApp contacts:

  • Images, Videos, Documents: Use the send_file tool to share any supported media type.
  • Voice Messages: Use the send_audio_message tool to send audio files as playable WhatsApp voice messages.
    • For optimal compatibility, audio files should be in .ogg Opus format.
    • With FFmpeg installed, the system will automatically convert other audio formats (MP3, WAV, etc.) to the required format.
    • Without FFmpeg, you can still send raw audio files using the send_file tool, but they won't appear as playable voice messages.

Media Downloading

By default, just the metadata of the media is stored in the local database. The message will indicate that media was sent. To access this media you need to use the download_media tool which takes the message_id and chat_jid (which are shown when printing messages containing the meda), this downloads the media and then returns the file path which can be then opened or passed to another tool.

Technical Details

  1. Claude sends requests to the Python MCP server
  2. The MCP server queries the Go bridge for WhatsApp data or directly to the SQLite database
  3. The Go accesses the WhatsApp API and keeps the SQLite database up to date
  4. Data flows back through the chain to Claude
  5. When sending messages, the request flows from Claude through the MCP server to the Go bridge and to WhatsApp

Troubleshooting

  • If you encounter permission issues when running uv, you may need to add it to your PATH or use the full path to the executable.
  • Make sure both the Go application and the Python server are running for the integration to work properly.

Authentication Issues

  • QR Code Not Displaying: If the QR code doesn't appear, try restarting the authentication script. If issues persist, check if your terminal supports displaying QR codes.
  • WhatsApp Already Logged In: If your session is already active, the Go bridge will automatically reconnect without showing a QR code.
  • Device Limit Reached: WhatsApp limits the number of linked devices. If you reach this limit, you'll need to remove an existing device from WhatsApp on your phone (Settings > Linked Devices).
  • No Messages Loading: After initial authentication, it can take several minutes for your message history to load, especially if you have many chats.
  • WhatsApp Out of Sync: If your WhatsApp messages get out of sync with the bridge, delete both database files (whatsapp-bridge/store/messages.db and whatsapp-bridge/store/whatsapp.db) and restart the bridge to re-authenticate.

For additional Claude Desktop integration troubleshooting, see the MCP documentation. The documentation includes helpful tips for checking logs and resolving common issues.