Purpose
WhatsApp MCP Stream is a WhatsApp MCP server used to connect to and operate WhatsApp through the MCP (Model Context Protocol) protocol. It is built around the Streamable HTTP transport, uses Baileys to implement the WhatsApp connection, and also provides a web management interface and bidirectional media streaming (upload and download). It is suitable for automation scenarios or integration projects that need to access WhatsApp messaging and media capabilities over HTTP.
Main capabilities
- Transport: Streamable HTTP, with the MCP endpoint at /mcp.
- Engine: Baileys.
- Management interface: Supports QR code login, status viewing, logout, runtime settings, chat history viewing, export, and more.
- Media: Provides an upload endpoint, /media hosting, and an MCP download tool; supports bidirectional media streaming (upload + download).
- Runtime settings: Can be edited in the management interface and persisted to SETTINGS_PATH (defaults to MEDIA_DIR/settings.json). Supported settings include media_public_base_url, max_files_per_upload, require_upload_token, auto_download_media, auto_download_max_mb.
- Media upload API: Supports multipart (recommended for large files); returns url and (if configured) publicUrl.
- Sending local files: The ./files/ directory in the project root is bind-mounted to /app/files inside the container; after placing files there, they can be referenced directly without restarting the container. For URL sources, media_url can be passed directly to send_media or stage_media, and the server downloads the file itself without needing base64.
- Upload authentication (optional): When require_upload_token=true, the token can be provided via x-upload-token: <token> or Authorization: Bearer <token>.
- MCP protocol interaction: POST /mcp and initialize with JSON-RPC initialize; subsequent requests use the returned mcp-session-id header; the client must send Accept: application/json, text/event-stream during initialize.
- Session recovery and health checks: Includes an intentional recovery approach for corrupted Baileys/WhatsApp session state. When application state corruption signals appear, first try forceResync() soft recovery; if the same type of failure repeats within the time window, escalate to an internal WhatsApp client restart. For disconnections such as Connection Terminated, a disconnect watchdog is scheduled and escalates to an internal restart if the socket does not recover to open in time. The reconnection lifecycle is protected to avoid nested lock deadlocks. The dedicated /healthz endpoint returns 503 only when the service is truly stuck outside the allowed recovery window; the Docker health check uses /healthz, so the container will only be restarted after in-process recovery has been attempted.
- Persistence: Chats and messages are saved to a local SQLite database stored in the session volume.
- Chat history API: GET /api/chats?limit=50&offset=0&q=<search> returns a paginated chat list (filterable by name); GET /api/chats/:jid/messages?limit=50&offset=0 returns paginated messages (newest first). Both endpoints are used by the Chats tab of the management interface. Chats can be exported via GET /api/export/chat/:jid?include_media=true (JSON + optionally downloaded media). When include_media=true, the ZIP contains files already downloaded via download_media and does not pull missing media from WhatsApp.
- Transport diagnostic logs: /mcp POST requests record request lifecycle events in logs/mcp-whatsapp.log, including request entry, transport dispatch, transport.handleRequest completion, and HTTP finish / close, to determine whether latency occursbefore or after the response leaves whatsapp-mcp-stream (gateway/client side).
Usage
Quick start (Docker)
After the server starts, the following addresses are available:
- Management interface:http://localhost:3003/admin
- MCP endpoint:http://localhost:3003/mcp
- Media files:http://localhost:3003/media/<filename>
Configuring DNS on hosts with --iptables=false enabled
On some NAS / hardened hosts (for example Synology using dockerd --iptables=false), Docker's embedded DNS proxy (127.0.0.11) has no iptables DNAT rules and will refuse connections inside containers. Fix: copy resolv.conf.example to resolv.conf and add a volume override; then add the override configuration in a local docker-compose.override.yml (not committed). docker compose up will automatically pick up that override configuration.
Runtime settings
Can be edited in the admin interface and persisted to SETTINGS_PATH.
MCP tool regression smoke test
The project provides a quick regression smoke test and supports an optional custom target.
Built-in authentication notes
Built-in authentication is not yet implemented. In production environments, a gateway that enforces authentication should be used. This project can be used together with authmcp-gateway.
Environment variables
The project uses environment variables for configuration (the specific variable names are not yet provided).
Use cases
- Automation or integration scenarios that need to connect to WhatsApp over HTTP in an MCP manner.
- Scenarios that need an admin interface for QR code login, status monitoring, and chat history browsing.
- Scenarios that need bidirectional media streaming (upload and download) and sending local files or URL media files in chats.
- Scenarios deployed in a Docker environment (including hosts such as NAS) and requiring session recovery fault tolerance.
Limitations
- Built-in authentication is not yet implemented; production environments need to enforce authentication via an external gateway (such as authmcp-gateway).
- On some hosts with --iptables=false enabled, additional DNS resolution configuration is required.
- When exporting chats, include_media=true only includes media already downloaded via download_media and will not pull missing media from WhatsApp.
- The specific names of other environment variables and deployment details beyond the default port are not yet provided.