WhatsApp MCP Server

WhatsApp MCP Server

Enables Claude to read and send WhatsApp messages through a self-hosted REST API, supporting multi-user sessions, media, groups, contacts, and webhooks.

Category
访问服务器

README

WhatsApp REST API + MCP Server

Self-hosted WhatsApp REST API built on @whiskeysockets/baileys, with:

  • Multi-user, multi-session: each user registers, gets an API key, and connects their own WhatsApp number(s) via QR code. Sessions are strictly scoped per user.
  • REST API for messages, media, groups, contacts, presence, webhooks (Swagger docs at /api-docs).
  • React management dashboard at /dashboard (sessions, QR pairing, logs).
  • MCP server (mcp/) so Claude (Claude Code / Claude Desktop) can read and send WhatsApp messages through your deployment.

Based on Baileys-2025-Rest-API by Abid (MIT). Heavily extended: per-user auth with registration gate, per-session proxy support, LID→phone JID canonicalization, self-healing reconnect, React dashboard.

⚠️ Disclaimer: Baileys is an unofficial WhatsApp Web client. Using it violates WhatsApp's Terms of Service and carries a (small) risk of your number being banned. Use a number you can afford to lose, don't spam, and don't use this for bulk unsolicited messaging.


Requirements

  • Node.js ≥ 20
  • PostgreSQL ≥ 14
  • A server with a domain + HTTPS (any reverse proxy; examples below)

1. Deploy the API

Option A — Docker (fastest)

git clone <this-repo>
cd whatsapp-api
cp .env.example .env      # edit it — see "Environment" below
docker compose up -d

This starts Postgres, Redis, the API on port 3001, and (optionally) nginx. Edit the secrets in docker-compose.yml / .env first — never keep the defaults.

Option B — Bare metal (PM2)

git clone <this-repo>
cd whatsapp-api

# deps
npm install
cd frontend && npm install && cd ..

# config
cp .env.example .env
# edit .env — set DATABASE_URL, JWT_SECRET, REGISTER_PASSWORD (see below)

# database
npx prisma generate
npx prisma db push          # first install (or: npx prisma migrate deploy)

# build backend + dashboard
npm run build

# run
npm install -g pm2
pm2 start dist/app.js --name whatsapp-api
pm2 save && pm2 startup

Put a reverse proxy with TLS in front (Caddy, nginx, or your hosting panel). The app listens on PORT (default 3001). WebSockets (Socket.IO) must be proxied too — with nginx, set proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; on the location block (see nginx.conf for a full example).

Environment

Minimum you must set in .env:

Variable What
DATABASE_URL Postgres connection string
JWT_SECRET Long random string (dashboard login tokens)
REGISTER_PASSWORD Long random string — required by POST /api/auth/register. This is your signup gate: only people who know it can create accounts on your instance.
API_BASE_URL / FRONTEND_URL Your public URL, e.g. https://wa.example.com
CORS_ORIGIN Your public URL (not * in production)

Optional: WA_PROXY_URL / WA_PROXY_COUNTRY to route WhatsApp connections through a residential proxy (helps if your server IP is flagged).

Everything else in .env.example has sane defaults.

2. Create your account + connect WhatsApp

# 1. Register (needs REGISTER_PASSWORD)
curl -X POST https://your-domain.com/api/auth/register \
  -H "Content-Type: application/json" \
  -d '{"email":"you@example.com","name":"You","password":"choose-a-login-password","registerPassword":"<REGISTER_PASSWORD>"}'
# → response contains your apiKey. Save it.

# 2. Create a session
curl -X POST https://your-domain.com/api/sessions \
  -H "X-API-Key: <your apiKey>" \
  -H "Content-Type: application/json" \
  -d '{"sessionId":"my-session"}'

# 3. Scan the QR code
# Easiest: log into https://your-domain.com/dashboard with your email+password
# and scan the QR with WhatsApp (Settings → Linked Devices → Link a Device).

Send a test message:

curl -X POST https://your-domain.com/api/messages/my-session/send \
  -H "X-API-Key: <your apiKey>" \
  -H "Content-Type: application/json" \
  -d '{"to":"49123456789@s.whatsapp.net","message":{"text":"hello from the API"}}'

Full API reference: https://your-domain.com/api-docs (Swagger UI). More recipes in QUICK_START_GUIDE.md and USER_MANAGEMENT.md.

3. MCP server (Claude integration)

mcp/server.py is a stdio MCP server that wraps this API — gives Claude tools like get_chat_overview, get_messages, send_message, send_media, send_reaction.

Setup

cd mcp
python3 -m venv .venv
.venv/bin/pip install -r requirements.txt

Register with Claude Code (user scope = available in every project):

claude mcp add whatsapp --scope user \
  -e WHATSAPP_API_BASE=https://your-domain.com \
  -e WHATSAPP_API_KEY=<your apiKey> \
  -e WHATSAPP_DEFAULT_SESSION=my-session \
  -- /absolute/path/to/mcp/.venv/bin/python /absolute/path/to/mcp/server.py

Or add it to Claude Desktop's claude_desktop_config.json:

{
  "mcpServers": {
    "whatsapp": {
      "command": "/absolute/path/to/mcp/.venv/bin/python",
      "args": ["/absolute/path/to/mcp/server.py"],
      "env": {
        "WHATSAPP_API_BASE": "https://your-domain.com",
        "WHATSAPP_API_KEY": "<your apiKey>",
        "WHATSAPP_DEFAULT_SESSION": "my-session"
      }
    }
  }
}

Then ask Claude something like "show me my latest WhatsApp chats".

Tip: treat send tools as confirm-before-send. In Claude Code, allowlist only the read tools in your settings and let the harness prompt on every send_* call.

Security notes

  • Never commit .env or auth_sessions/auth_sessions/ holds live WhatsApp credentials; anyone with those files IS your WhatsApp. Both are gitignored.
  • REGISTER_PASSWORD is the only thing standing between the internet and account creation on your instance. Make it long and random.
  • API keys are per-user; every session and message is scoped to its owner. Don't share your key.
  • Run behind HTTPS. Always.

License

MIT — see LICENSE. Original work © Abid (pointersoftware), modifications © contributors.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选