Skip to main content
Glama
README.md
# wuzapi-mcp

A small [Model Context Protocol](https://modelcontextprotocol.io) server that lets an AI agent (Claude Code, opencode, or any MCP client) send WhatsApp messages through a [WuzAPI](https://github.com/asternic/wuzapi) server.

It is deliberately narrow: it only sends messages and reads history, every send is checked against a recipient allowlist, and it never exposes session management (logout, disconnect, QR code or pairing).

## Requirements

- Node.js 22 or newer
- A running WuzAPI server with at least one connected user session

## Install

```bash
git clone <this repository> wuzapi-mcp
cd wuzapi-mcp
npm install
npm test   # local tests with a fake HTTP server, no network
```

## Configuration

All configuration comes from environment variables:

| Variable | Required | Description |
|---|---|---|
| `WUZAPI_URL` | yes | Base URL of the WuzAPI server, e.g. `https://wuzapi.example.com` |
| `WUZAPI_TOKENS` | yes | JSON object mapping a session name (your choice) to a WuzAPI user token, e.g. `{"main":"YOUR_USER_TOKEN"}`. A value of the form `"env:VAR_NAME"` reads the token from another environment variable, e.g. `{"main":"env:WUZAPI_MAIN_TOKEN"}` |
| `WA_ALLOW` | yes, to send | Comma-separated phone numbers or JIDs that may receive messages, e.g. `15551234567,120363000000000000@g.us`. `*` allows every recipient. Empty means no sends are allowed |
| `WA_ENV_FILE` | no | Path to a dotenv file to load. Variables already present in the environment take precedence |

Example `wuzapi.env` (keep it out of version control; `*.env` is git-ignored):

```dotenv
WUZAPI_URL=https://wuzapi.example.com
WUZAPI_TOKENS={"main":"YOUR_USER_TOKEN"}
WA_ALLOW=15551234567
```

## Client setup

### Claude Code

```bash
claude mcp add wuzapi -e WA_ENV_FILE=/path/to/wuzapi.env -- node /path/to/wuzapi-mcp/server.mjs
```

### opencode

In `opencode.json`:

```json
{
  "mcp": {
    "wuzapi": {
      "type": "local",
      "command": ["node", "/path/to/wuzapi-mcp/server.mjs"],
      "environment": { "WA_ENV_FILE": "/path/to/wuzapi.env" },
      "enabled": true
    }
  }
}
```

## Tools

| Tool | WuzAPI endpoint | Notes |
|---|---|---|
| `sessions` | `GET /session/status` | Status of every configured session |
| `send_text` | `POST /chat/send/text` | Optional `reply_to` message id |
| `send_media` | `POST /chat/send/{image,video,document,audio}` | URL or base64 data URL |
| `send_buttons` | `POST /chat/send/buttons` | Button types `reply`, `url`, `call`, `copy`, `voice_call`; optional `envelope` (`original`, `fork`, `viewonce`) |
| `send_list` | `POST /chat/send/list` | Sections with selectable rows |
| `send_poll` | `POST /chat/send/poll` | Single choice only |
| `send_carousel` | `POST /chat/send/carousel` | 2+ image cards; buttons `reply`, `url`, `call` |
| `history` | `GET /chat/messages` | Requires message history to be enabled on the server |

All tools target the routes of upstream WuzAPI. Interactive messages (buttons, the `envelope` modes, voice-call buttons, carousel) were added to WuzAPI relatively recently: older releases or other forks may lack those endpoints or fields, so check the routes of the version you run. Whether WhatsApp actually renders buttons, lists and carousels depends on the recipient's client (phone, desktop, web) and can change without notice.

Not included on purpose:

- **Status (stories) posting**: limiting the audience requires a field that upstream WuzAPI does not support; without it a status would go to all contacts.
- **Product catalog management**: the endpoints exist only in some forks, and WhatsApp currently does not answer those catalog queries for most accounts, so it is experimental and may not work.

## Safety notes

- Every `send_*` call is checked against `WA_ALLOW` before any HTTP request is made. With an empty allowlist nothing can be sent. Use `*` only on test numbers.
- Sending to `status@broadcast` is refused.
- No logout, disconnect, QR code or pairing tools are exposed, so an agent cannot break or hijack a session.
- Tokens are sent only in the `Token` header. They are never accepted as tool arguments, any echo of a configured token in a response is replaced with `[REDACTED]`, and any response field named `token` is redacted.
- There is no automatic retry. A transport error is reported as "result may be uncertain" so the agent does not send duplicates.
- Prefer a dedicated test session over a production number while experimenting.

## License

MIT