You signed in with another tab or window. Reload
to refresh your session. You signed out in another tab or window. Reload
to refresh your session. You switched accounts on another tab or window. Reload
to refresh your session. Dismiss alert
WhatsApp Web MCP Server
10 stars
0 forks
Branches
Tags
Activity
Notifications
You must be signed in to change notification settings
main
Go to file
Code
| Name | | Name | Last commit message | Last commit date |
| --- | --- | --- | --- |
| Latest commit
-------------
github-actions[bot]
chore: bump version to 0.2.3
Mar 22, 2025
fc085b5
· Mar 22, 2025
History
-------
12 Commits
| | |
| .cursor/rules | | .cursor/rules | Project initial commit | Mar 14, 2025 |
| .github/workflows | | .github/workflows | Add GitHub Actions workflows for PR checks and package publishing. (
#8
) | Mar 22, 2025 |
| bin | | bin | Project initial commit | Mar 14, 2025 |
| src | | src | Feat/download media messages (
#10
) | Mar 22, 2025 |
| test | | test | Feat/download media messages (
#10
) | Mar 22, 2025 |
| .eslintrc.js | | .eslintrc.js | Feat/add api key authentication (
#2
) | Mar 16, 2025 |
| .gitignore | | .gitignore | Feat/group management (
#6
) | Mar 18, 2025 |
| .nvmrc | | .nvmrc | Project initial commit | Mar 14, 2025 |
| .prettierrc | | .prettierrc | Feat/add api key authentication (
#2
) | Mar 16, 2025 |
| .puppeteer_ws | | .puppeteer_ws | Project initial commit | Mar 14, 2025 |
| Dockerfile | | Dockerfile | Project initial commit | Mar 14, 2025 |
| LICENSE | | LICENSE | Project initial commit | Mar 14, 2025 |
| README.md | | README.md | Feat/download media messages (
#10
) | Mar 22, 2025 |
| bin.js | | bin.js | Add WhatsApp API functionality and update dependencies | Mar 16, 2025 |
| eslint.config.js | | eslint.config.js | Feat/add api key authentication (
#2
) | Mar 16, 2025 |
| jest.config.js | | jest.config.js | Feat/add api key authentication (
#2
) | Mar 16, 2025 |
| nodemon.json | | nodemon.json | Project initial commit | Mar 14, 2025 |
| package-lock.json | | package-lock.json | chore: bump version to 0.2.3 | Mar 22, 2025 |
| package.json | | package.json | chore: bump version to 0.2.3 | Mar 22, 2025 |
| tsconfig.json | | tsconfig.json | Feat/add api key authentication (
#2
) | Mar 16, 2025 |
| tsconfig.test.json | | tsconfig.test.json | Feat/add api key authentication (
#2
) | Mar 16, 2025 |
| View all files | | |
A Node.js application that connects WhatsApp Web with AI models through the Model Context Protocol (MCP). This project provides a standardized interface for programmatic interaction with WhatsApp, enabling automated messaging, contact management, and group chat functionality through AI-driven workflows.
WhatsApp Web MCP provides a seamless integration between WhatsApp Web and AI models by:
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, associated, authorized, endorsed by, or in any way officially connected with WhatsApp or any of its subsidiaries or its affiliates. The official WhatsApp website can be found at whatsapp.com. "WhatsApp" as well as related names, marks, emblems and images are registered trademarks of their respective owners. Also it is not guaranteed you will not be blocked by using this method. WhatsApp does not allow bots or unofficial clients on their platform, so this shouldn't be considered totally safe.
To learn more about using WhatsApp Web MCP in real-world scenarios, check out these articles:
Clone the repository:
shell
git clone https://github.com/pnizer/wweb-mcp.git
cd wweb-mcp
Install globally or use with npx:
```shell
npm install -g .
npx .
```
Build with Docker:
shell
docker build . -t wweb-mcp:latest
Option | Alias | Description | Choices | Default |
---|---|---|---|---|
--mode |
-m |
Run mode | mcp , whatsapp-api |
mcp |
--mcp-mode |
-c |
MCP connection mode | standalone , api |
standalone |
--transport |
-t |
MCP transport mode | sse , command |
sse |
--sse-port |
-p |
Port for SSE server | - | 3002 |
--api-port |
- | Port for WhatsApp API server | - | 3001 |
--auth-data-path |
-a |
Path to store authentication data | - | .wwebjs_auth |
--auth-strategy |
-s |
Authentication strategy | local , none |
local |
--api-base-url |
-b |
API base URL for MCP when using api mode | - | http://localhost:3001/api |
--api-key |
-k |
API key for WhatsApp Web REST API when using api mode | - | '' |
When running in API mode, the WhatsApp API server requires authentication using an API key. The API key is automatically generated when you start the WhatsApp API server and is displayed in the logs:
WhatsApp API key: 1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef
To connect the MCP server to the WhatsApp API server, you need to provide this API key using the --api-key
or -k
option:
npx wweb-mcp --mode mcp --mcp-mode api --api-base-url http://localhost:3001/api --api-key 1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef
The API key is stored in the authentication data directory (specified by --auth-data-path
) and persists between restarts of the WhatsApp API server.
You can configure webhooks to receive incoming WhatsApp messages by creating a webhook.json
file in your authentication data directory (specified by --auth-data-path
).
{
"url": "https://your-webhook-endpoint.com/incoming",
"authToken": "your-optional-authentication-token",
"filters": {
"allowedNumbers": ["+1234567890", "+0987654321"],
"allowPrivate": true,
"allowGroups": false
}
}
Option | Type | Description |
---|---|---|
url |
String | The webhook endpoint URL where message data will be sent |
authToken |
String (optional) | Authentication token to be included in the Authorization header as a Bearer token |
filters.allowedNumbers |
Array (optional) | List of phone numbers to accept messages from. If provided, only messages from these numbers will trigger the webhook |
filters.allowPrivate |
Boolean (optional) | Whether to send private messages to the webhook. Default: true |
filters.allowGroups |
Boolean (optional) | Whether to send group messages to the webhook. Default: true |
When a message is received and passes the filters, a POST request will be sent to the configured URL with the following JSON payload:
{
"from": "+1234567890",
"name": "Contact Name",
"message": "Hello, world!",
"isGroup": false,
"timestamp": 1621234567890,
"messageId": "ABCDEF1234567890"
}
Run a standalone WhatsApp API server that exposes WhatsApp functionality through REST endpoints:
npx wweb-mcp --mode whatsapp-api --api-port 3001
Run an MCP server that directly connects to WhatsApp Web:
npx wweb-mcp --mode mcp --mcp-mode standalone --transport sse --sse-port 3002
Run an MCP server that connects to the WhatsApp API server:
# First, start the WhatsApp API server and note the API key from the logs
npx wweb-mcp --mode whatsapp-api --api-port 3001
# Then, start the MCP server with the 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
Tool | Description | Parameters |
---|---|---|
get_status |
Check WhatsApp client connection status | None |
send_message |
Send messages to WhatsApp contacts | number : Phone number to send to message : Text content to send |
search_contacts |
Search for contacts by name or number | query : Search term to find contacts |
get_messages |
Retrieve messages from a specific chat | number : Phone number to get messages from limit (optional): Number of messages to retrieve |
get_chats |
Get a list of all WhatsApp chats | None |
create_group |
Create a new WhatsApp group | name : Name of the group participants : Array of phone numbers to add |
add_participants_to_group |
Add participants to an existing group | groupId : ID of the group participants : Array of phone numbers to add |
get_group_messages |
Retrieve messages from a group | groupId : ID of the group limit (optional): Number of messages to retrieve |
send_group_message |
Send a message to a group | groupId : ID of the group message : Text content to send |
search_groups |
Search for groups by name, description, or member names | query : Search term to find groups |
get_group_by_id |
Get detailed information about a specific group | groupId : ID of the group to get |
download_media_from_message |
Download media from a message | messageId : ID of the message containing media to download |
Resource URI | Description |
---|---|
whatsapp://contacts |
List of all WhatsApp contacts |
whatsapp://messages/{number} |
Messages from a specific chat |
whatsapp://chats |
List of all WhatsApp chats |
whatsapp://groups |
List of all WhatsApp groups |
whatsapp://groups/search |
Search for groups by name, description, or member names |
whatsapp://groups/{groupId}/messages |
Messages from a specific group |
Endpoint | Method | Description | Parameters |
---|---|---|---|
/api/status |
GET | Get WhatsApp connection status | None |
/api/contacts |
GET | Get all contacts | None |
/api/contacts/search |
GET | Search for contacts | query : Search term |
/api/chats |
GET | Get all chats | None |
/api/messages/{number} |
GET | Get messages from a chat | limit (query): Number of messages |
/api/send |
POST | Send a message | number : Recipient message : Message content |
/api/messages/{messageId}/media/download |
POST | Download media from a message | None |
Endpoint | Method | Description | Parameters |
---|---|---|---|
/api/groups |
GET | Get all groups | None |
/api/groups/search |
GET | Search for groups | query : Search term |
/api/groups/create |
POST | Create a new group | name : Group name participants : Array of numbers |
/api/groups/{groupId} |
GET | Get detailed information about a specific group | None |
/api/groups/{groupId}/messages |
GET | Get messages from a group | limit (query): Number of messages |
/api/groups/{groupId}/participants/add |
POST | Add members to a group | participants : Array of numbers |
/api/groups/send |
POST | Send a message to a group | groupId : Group ID message : Message content |
Start WhatsApp API server:
shell
npx wweb-mcp -m whatsapp-api -s local
Scan the QR code with your WhatsApp mobile app
Note the API key displayed in the logs:
WhatsApp API key: 1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef
Add the following to your Claude Desktop configuration:
json
{
"mcpServers": {
"whatsapp": {
"command": "npx",
"args": [\
"wweb-mcp",\
"-m", "mcp",\
"-s", "local",\
"-c", "api",\
"-t", "command",\
"--api-base-url", "http://localhost:3001/api",\
"--api-key", "1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"\
]
}
}
}
Start WhatsApp API server in Docker:
shell
docker run -i -p 3001:3001 -v wweb-mcp:/wwebjs_auth --rm wweb-mcp:latest -m whatsapp-api -s local -a /wwebjs_auth
Scan the QR code with your WhatsApp mobile app
Note the API key displayed in the logs:
WhatsApp API key: 1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef
Add the following to your Claude Desktop configuration:
json
{
"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", "1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"\
]
}
}
}
Restart Claude Desktop
The WhatsApp functionality will be available through Claude's interface
The project is structured with a clean separation of concerns:
This architecture allows for flexible deployment scenarios, including:
src/
├── whatsapp-client.ts # WhatsApp Web client implementation
├── whatsapp-service.ts # Core business logic
├── whatsapp-api-client.ts # Client for the WhatsApp API
├── api.ts # REST API router
├── mcp-server.ts # MCP protocol implementation
└── main.ts # Application entry point
npm run build
The project uses Jest for unit testing. To run the tests:
# Run all tests
npm test
# Run tests in watch mode during development
npm run test:watch
# Generate test coverage report
npm run test:coverage
The project uses ESLint and Prettier for code quality and formatting:
# Run linter
npm run lint
# Fix linting issues automatically
npm run lint:fix
# Format code with Prettier
npm run format
# Validate code (lint + test)
npm run validate
The linting configuration enforces TypeScript best practices and maintains consistent code style across the project.
The project uses GitHub Actions for automated publishing to npm. The workflow handles:
patch
, minor
, or major
)To release a new version:
This workflow requires an NPM_TOKEN secret to be configured in your GitHub repository.
Please ensure your PR:
This project uses whatsapp-web.js
, an unofficial JavaScript client library for WhatsApp Web that connects through the WhatsApp Web browser app. For more information, visit the whatsapp-web.js GitHub repository
.
This project is licensed under the MIT License - see the LICENSE
file for details.
WhatsApp Web MCP includes a robust logging system built with Winston. The logging system provides:
The application supports the following log levels, in order of verbosity:
You can configure the log level when starting the application using the --log-level
or -l
flag:
npm start -- --log-level=debug
Or when using the global installation:
wweb-mcp --log-level=debug
When running in MCP command mode (--mode mcp --transport command
), all logs are directed to stderr. This is important for command-line tools where stdout might be used for data output while stderr is used for logging and diagnostics. This ensures that the MCP protocol communication over stdout is not interfered with by log messages.
In test environments (when NODE_ENV=test
or when running with Jest), the logger automatically adjusts its behavior to be suitable for testing environments.
WhatsApp Web MCP Server
No packages published
You can’t perform that action at this time.