MCP HubMCP Hub
pnizer

wweb-mcp

by: pnizer

WhatsApp Web MCP Server

18created 14/03/2025
Visit
WhatsApp
Web

πŸ“ŒOverview

Purpose: To facilitate programmatic interaction with WhatsApp Web through AI models using the Model Context Protocol (MCP) for automated messaging and contact management.

Overview: WhatsApp Web MCP serves as a bridge between WhatsApp Web and AI models, providing a standardized interface for users to automate various functionalities like messaging, managing contacts, and coordinating group chats. By employing flexible deployment options, the framework allows for both direct integration with the WhatsApp client and connectivity through an API, catering to developers and businesses looking to leverage WhatsApp's capabilities in their applications.

Key Features:

  • Model Context Protocol (MCP): Provides a standardized interface that allows for seamless interactions between WhatsApp Web and AI models, facilitating automated workflows.

  • Flexible Deployment Options: Supports multiple modes of operation, including standalone MCP servers and WhatsApp API connections, enabling users to choose the best configuration for their needs.


WhatsApp Web MCP

A Node.js application that connects WhatsApp Web with AI models through the Model Context Protocol (MCP). It provides a standardized interface for programmatic interaction with WhatsApp, enabling automated messaging, contact management, and group chat functionality through AI-driven workflows.

Overview

WhatsApp Web MCP provides integration between WhatsApp Web and AI models by:

  • Creating a standardized interface through the Model Context Protocol (MCP)
  • Offering MCP Server access to WhatsApp functionality
  • Providing flexible deployment options through SSE or Command modes
  • Supporting both direct WhatsApp client integration and API-based connectivity

Disclaimer

IMPORTANT: This tool is for testing purposes only and should not be used in production environments.

Disclaimer from WhatsApp Web project:

This project is not affiliated with WhatsApp or its subsidiaries. Use is not guaranteed to avoid blocking. WhatsApp does not allow bots or unofficial clients, so this is not totally safe.

Learning Resources

To learn more about WhatsApp Web MCP, see these articles:

  • Integrating WhatsApp with AI: Guide to Setting Up a WhatsApp MCP server
  • Integrating OpenAI Agents Python SDK with Anthropic's MCP

Installation

  1. Clone the repository:

    git clone https://github.com/pnizer/wweb-mcp.git
    cd wweb-mcp
    
  2. Install globally or use with npx:

    # Install globally
    npm install -g .
    
    # Or use with npx directly
    npx .
    
  3. Build with Docker:

    docker build . -t wweb-mcp:latest
    

Configuration

Command Line Options

OptionAliasDescriptionChoicesDefault
--mode-mRun modemcp, whatsapp-apimcp
--mcp-mode-cMCP connection modestandalone, apistandalone
--transport-tMCP transport modesse, commandsse
--sse-port-pPort for SSE server-3002
--api-portPort for WhatsApp API server-3001
--auth-data-path-aPath to store authentication data-.wwebjs_auth
--auth-strategy-sAuthentication strategylocal, nonelocal
--api-base-url-bAPI base URL for MCP (api mode)-http://localhost:3001/api
--api-key-kAPI key for WhatsApp REST API (api mode)-''

API Key Authentication

In API mode, the WhatsApp API server requires an API key, displayed in logs when starting the server:

WhatsApp API key: 1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef

Connect the MCP server using:

npx wweb-mcp --mode mcp --mcp-mode api --api-base-url http://localhost:3001/api --api-key YOUR_API_KEY

The API key persists between server restarts.

Authentication Methods

  • Local Authentication (Recommended): Scan QR code once; credentials persist; stable for long-term use.
  • No Authentication: Default; requires QR scan every startup; good for testing.

Webhook Configuration

Configure webhooks by creating a webhook.json in the authentication data directory.

Webhook JSON Format

{
  "url": "https://your-webhook-endpoint.com/incoming",
  "authToken": "your-optional-authentication-token",
  "filters": {
    "allowedNumbers": ["+1234567890", "+0987654321"],
    "allowPrivate": true,
    "allowGroups": false
  }
}

Webhook Options

OptionTypeDescription
urlStringEndpoint URL to receive message data
authTokenStringOptional token for Authorization header
filters.allowedNumbersArrayPhone numbers to accept messages from
filters.allowPrivateBooleanSend private messages (default: true)
filters.allowGroupsBooleanSend group messages (default: true)

Webhook Payload

Received messages trigger a POST with:

{
  "from": "+1234567890",
  "name": "Contact Name",
  "message": "Hello, world!",
  "isGroup": false,
  "timestamp": 1621234567890,
  "messageId": "ABCDEF1234567890"
}

Usage

Running Modes

  • WhatsApp API Server

    npx wweb-mcp --mode whatsapp-api --api-port 3001
    
  • MCP Server (Standalone)

    npx wweb-mcp --mode mcp --mcp-mode standalone --transport sse --sse-port 3002
    
  • MCP Server (API Client)

    Start API server first:

    npx wweb-mcp --mode whatsapp-api --api-port 3001
    

    Start MCP server with API key:

    npx wweb-mcp --mode mcp --mcp-mode api --api-base-url http://localhost:3001/api --api-key YOUR_API_KEY --transport sse --sse-port 3002
    

Available Tools

ToolDescriptionParameters
get_statusCheck WhatsApp client connectionNone
send_messageSend messagesnumber: Phone number
message: Text content
search_contactsSearch contacts by name or numberquery: Search term
get_messagesRetrieve messages from a chatnumber: Phone number
limit (optional)
get_chatsList all WhatsApp chatsNone
create_groupCreate a WhatsApp groupname: Group name
participants: Array of numbers
add_participants_to_groupAdd participants to a groupgroupId: Group ID
participants: Array of numbers
get_group_messagesGet messages from a groupgroupId: Group ID
limit (optional)
send_group_messageSend message to a groupgroupId: Group ID
message: Text content
search_groupsSearch groupsquery: Search term
get_group_by_idGet group infogroupId: Group ID
download_media_from_messageDownload mediamessageId: Message ID
send_media_messageSend media to contactnumber: Phone number
source: Media URI (http://, https://, file://)
caption (optional)

Available Resources

Resource URIDescription
whatsapp://contactsAll contacts
whatsapp://messages/{number}Messages from chat
whatsapp://chatsAll chats
whatsapp://groupsAll groups
whatsapp://groups/searchSearch groups
whatsapp://groups/{groupId}/messagesMessages from group

REST API Endpoints

Contacts & Messages

EndpointMethodDescriptionParameters
/api/statusGETWhatsApp connection statusNone
/api/contactsGETAll contactsNone
/api/contacts/searchGETSearch contactsquery: Search term
/api/chatsGETAll chatsNone
/api/messages/{number}GETMessages from chatlimit (query): Number of messages
/api/sendPOSTSend messagenumber: Recipient
message: Content
/api/send/mediaPOSTSend media messagenumber: Recipient
source: Media URI
caption (optional)
/api/messages/{messageId}/media/downloadPOSTDownload mediaNone

Group Management

EndpointMethodDescriptionParameters
/api/groupsGETAll groupsNone
/api/groups/searchGETSearch groupsquery: Search term
/api/groups/createPOSTCreate groupname: Group name
participants: Array
/api/groups/{groupId}GETGroup informationNone
/api/groups/{groupId}/messagesGETGroup messageslimit (query): Number of messages
/api/groups/{groupId}/participants/addPOSTAdd membersparticipants: Array
/api/groups/sendPOSTSend message to groupgroupId: Group ID
message: Content

AI Integration

Claude Desktop Integration

Option 1: Using NPX
  1. Start WhatsApp API server:

    npx wweb-mcp -m whatsapp-api -s local
    
  2. Scan the QR code with your WhatsApp app.

  3. Note the API key from logs.

  4. Add this to Claude Desktop configuration:

    {
        "mcpServers": {
            "whatsapp": {
                "command": "npx",
                "args": [
                    "wweb-mcp",
                    "-m", "mcp",
                    "-s", "local",
                    "-c", "api",
                    "-t", "command",
                    "--api-base-url", "http://localhost:3001/api",
                    "--api-key", "YOUR_API_KEY"
                ]
            }
        }
    }
    
Option 2: Using Docker
  1. Start WhatsApp API server in Docker:

    docker run -i -p 3001:3001 -v wweb-mcp:/wwebjs_auth --rm wweb-mcp:latest -m whatsapp-api -s local -a /wwebjs_auth
    
  2. Scan the QR code.

  3. Note API key.

  4. Add this to Claude Desktop configuration:

    {
        "mcpServers": {
            "whatsapp": {
                "command": "docker",
                "args": [
                    "run",
                    "-i",
                    "--rm",
                    "wweb-mcp:latest",
                    "-m", "mcp",
                    "-s", "local",
                    "-c", "api",
                    "-t", "command",
                    "--api-base-url", "http://host.docker.internal:3001/api",
                    "--api-key", "YOUR_API_KEY"
                ]
            }
        }
    }
    
  5. Restart Claude Desktop for changes to take effect.

Architecture

Components

  1. WhatsAppService: Core logic for WhatsApp interaction
  2. WhatsAppApiClient: Connects to WhatsApp API
  3. API Router: Express REST API routes
  4. MCP Server: Model Context Protocol implementation

Deployment Options

  • WhatsApp API Server
  • MCP Server (Standalone)
  • MCP Server (API Client)

This supports running servers on the same or different machines as needed.

Development

Project Structure

src/
β”œβ”€β”€ whatsapp-client.ts
β”œβ”€β”€ whatsapp-service.ts
β”œβ”€β”€ whatsapp-api-client.ts
β”œβ”€β”€ api.ts
β”œβ”€β”€ mcp-server.ts
└── main.ts

Building

npm run build

Testing

npm test           # Run all tests
npm run test:watch # Watch mode
npm run test:coverage # Generate coverage report

Linting & Formatting

npm run lint       # Lint
npm run lint:fix   # Auto fix lint issues
npm run format     # Format with Prettier
npm run validate   # Lint + test

Publishing

Publishing uses GitHub Actions, automating version bumps, git tagging, and npm publishing. Requires NPM_TOKEN secret configured.

Troubleshooting

  • Cannot run wweb-mcp command standalone mode with Claude Desktop due to multiple Puppeteer sessions conflicting. Use MCP + API mode instead.

Features

  • Send/receive messages
  • Send media messages (images)
  • Download media (images, audio, documents)
  • Group chat management
  • Contact search
  • Message history retrieval

Upcoming Features

  • Support all media types (video, audio, docs)
  • Enhanced message templates
  • Advanced group management
  • Contact add/remove
  • Improved error handling

Contributing

  1. Fork the repo
  2. Create a feature branch
  3. Commit changes
  4. Push branch
  5. Create Pull Request

Ensure PRs:

  • Follow code style
  • Include tests
  • Update docs
  • Detail changes

Dependencies

This project uses whatsapp-web.js, an unofficial JavaScript client for WhatsApp Web.

License

MIT License - see LICENSE file.

Logging

Built with Winston, the logging system offers:

  • Multiple levels: error, warn, info, http, debug
  • Colorized console output
  • HTTP request/response logging
  • Structured error handling
  • Environment-aware levels (dev vs prod)
  • Logs sent to stderr in MCP command mode

Log Levels

  1. error - Critical errors
  2. warn - Warnings that need attention
  3. info - General application info
  4. http - HTTP request logs
  5. debug - Detailed debug info

Configuring Log Level

Use --log-level or -l flag:

npm start -- --log-level=debug

Or if installed globally:

wweb-mcp --log-level=debug

Command Mode Logging

In MCP command mode (--mode mcp --transport command), logs are directed to stderr to prevent interfering with MCP protocol communication on stdout.

Test Environment

When running tests or in test environment (NODE_ENV=test), the logger adjusts automatically for testing suitability.