whatsapp-mcp
v0.1.1Lightweight WhatsApp MCP Server using Baileys
@vfunctt/whatsapp-mcp A lightweight WhatsApp Model Context Protocol (MCP) server built with Baileys and SQLite. Supports bidirectional messaging, media handling, contact resolution, search, and automatic LID/phone number deduplication. --- Features - Transports: Supports standard I/O (stdio) and Streamable HTTP (http). - Persistent Storage: Local SQLite database storing chats, messages, contacts, and LID mappings (better-sqlite3). - LID Resolution: Automatically resolves and merges WhatsApp @lid identifiers with canonical phone number JIDs (@s.whatsapp.net).
Summary extracted from the README.
@vfunctt/whatsapp-mcp
A lightweight WhatsApp Model Context Protocol (MCP) server built with Baileys and SQLite.
Supports bidirectional messaging, media handling, contact resolution, search, and automatic LID/phone number deduplication.
Features
- Transports: Supports standard I/O (
stdio) and Streamable HTTP (http). - Persistent Storage: Local SQLite database storing chats, messages, contacts, and LID mappings (
better-sqlite3). - LID Resolution: Automatically resolves and merges WhatsApp
@lididentifiers with canonical phone number JIDs (@s.whatsapp.net). - Media Support: Download inline media (images, stickers) and send media files/voice notes (automatic Opus encoding via
ffmpegwhen installed). - Safety: Differentiates incoming vs. outgoing (
fromMe), provides contextual surrounding messages, and marks destructive/send operations with appropriate MCP annotations.
Prerequisites
- Node.js:
v20.10.0or later - FFmpeg (Optional): Required for converting non-Opus audio to voice notes (
ptt) and generating waveforms.
Installation & Setup
1. Install Dependencies & Build
npm install
npm run build
2. Pair WhatsApp Account
Run the server directly once in terminal mode to display the QR code and link your device:
npm run dev
# Or after build:
npm start
Scan the terminal QR code using WhatsApp on your phone (Linked Devices > Link a device). Session credentials are saved locally in ~/.vfunct-mcp/whatsapp/auth/.
MCP Client Configuration
Claude Desktop (stdio)
Add to your claude_desktop_config.json:
{
"mcpServers": {
"whatsapp": {
"command": "node",
"args": ["/absolute/path/to/whatsapp-mcp/dist/index.js"],
"env": {
"WHATSAPP_LOG_LEVEL": "warn"
}
}
}
}
HTTP Mode
To expose the MCP server over HTTP (/mcp endpoint):
export MCP_TRANSPORT=http
export PORT=8080
export HOST=127.0.0.1
export MCP_AUTH_TOKEN="your-secure-token"
npm start
- MCP Endpoint:
POST /mcp(requiresAuthorization: Bearer <token>or?token=<token>) - Health Check:
GET /health - QR Code View:
GET /qr.png(access via browser to link device when headless)
Environment Variables
| Variable | Default | Description |
|---|---|---|
MCP_TRANSPORT |
stdio |
Transport type: stdio or http |
HOST |
127.0.0.1 |
HTTP bind host (HTTP mode only) |
PORT |
8080 |
HTTP bind port (HTTP mode only) |
MCP_AUTH_TOKEN |
None | Bearer token required for HTTP requests |
WHATSAPP_MCP_DATA_DIR |
~/.vfunct-mcp/whatsapp |
Directory for SQLite DB, auth keys, and media |
WHATSAPP_LOG_LEVEL |
warn |
Pino logger level (fatal, error, warn, info, debug) |
WHATSAPP_SYNC_FULL_HISTORY |
false |
Enable full history sync on initial connection |
Available MCP Tools
Connection & Lifecycle
connect: Open socket connection; returns status or generates pairing QR code.status: Get connection status, active phone number, and pairing state.qr_code: Retrieve QR code aspng,ascii,data_url, orraw.disconnect: Terminate socket without clearing auth credentials.logout: Invalidate session and wipe local authentication keys.
Chats & Messages
list_chats: List chats ordered by recent activity. Filters:onlyUnread,onlyGroups,awaitingMyReply,query.get_messages: Fetch chronological messages for a chat (chatIdor phone number). Supports pagination viabeforeTimestamp.search_messages: Full-text search across messages with optional date ranges, chat/sender filter, and context window.get_message_context: RetrieveNmessages before and after a specific message ID.fetch_history: Request older historical messages from WhatsApp.history_status: View WhatsApp history sync progress.
Contacts & Groups
resolve_jid: Validates and resolves a phone number or LID to canonical JID.search_contacts: Search known contacts and push names by text or number.get_contact: Fetch full contact details, DM state, interaction history, and mutual groups.get_group: Inspect group metadata, subject, description, and participant list.
Messaging Actions
send_text: Send plain text messages (supports replies viaquotedMessageId).send_media: Sendimage,video,audio(voice note), ordocument. AcceptsfilePath(stdio only) orbase64.send_reaction: Add or clear emoji reactions.mark_read: Mark incoming messages in a chat as read.edit_message: Edit previously sent messages.delete_message: Revoke messages.download_media: Download media content for a given message ID; returns inline base64 for images/stickers.
License
MIT