Labsco
fyimail logo

WhatsApp Web MCP

β˜… 7

from fyimail

Connects AI models to WhatsApp Web using the Model Context Protocol (MCP) to automate and enhance interactions.

πŸ”₯πŸ”₯πŸ”₯βœ“ VerifiedFreeAdvanced setup

WhatsApp Web MCP

A powerful bridge between WhatsApp Web and AI models using the Model Context Protocol (MCP). This project enables AI models like Claude to interact with WhatsApp through a standardized interface, making it easy to automate and enhance WhatsApp interactions programmatically.

Overview

WhatsApp Web MCP provides a seamless 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, 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.

Architecture

The project is structured with a clean separation of concerns:

Components

  1. WhatsAppService: Core business logic for interacting with WhatsApp
  2. WhatsAppApiClient: Client for connecting to the WhatsApp API
  3. API Router: Express routes for the REST API
  4. MCP Server: Model Context Protocol implementation

Deployment Options

  1. WhatsApp API Server: Standalone REST API server
  2. MCP Server (Standalone): Direct connection to WhatsApp Web
  3. MCP Server (API Client): Connection to WhatsApp API server

This architecture allows for flexible deployment scenarios, including:

  • Running the API server and MCP server on different machines
  • Using the MCP server as a client to an existing API server
  • Running everything on a single machine for simplicity

Development

Project Structure

Copy & paste β€” that's it
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

Building from Source

Copy & paste β€” that's it
npm run build

Testing

The project uses Jest for unit testing. To run the tests:

Copy & paste β€” that's it
# Run all tests
npm test

# Run tests in watch mode during development
npm run test:watch

# Generate test coverage report
npm run test:coverage

Linting and Formatting

The project uses ESLint and Prettier for code quality and formatting:

Copy & paste β€” that's it
# 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.

Upcoming Features

  • Create webhooks for incoming messages and other WhatsApp events
  • Support for sending media files (images, audio, documents)
  • Group chat management features
  • Contact management (add/remove contacts)
  • Message templates for common scenarios
  • Enhanced error handling and recovery

Contributing

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

Please ensure your PR:

  • Follows the existing code style
  • Includes appropriate tests
  • Updates documentation as needed
  • Describes the changes in detail

Dependencies

WhatsApp Web.js

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.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Logging

WhatsApp Web MCP includes a robust logging system built with Winston. The logging system provides:

  • Multiple log levels (error, warn, info, http, debug)
  • Console output with colorized logs
  • HTTP request/response logging for API endpoints
  • Structured error handling
  • Environment-aware log levels (development vs. production)
  • All logs directed to stderr when running in MCP command mode

Log Levels

The application supports the following log levels, in order of verbosity:

  1. error - Critical errors that prevent the application from functioning
  2. warn - Warnings that don't stop the application but require attention
  3. info - General information about application state and events
  4. http - HTTP request/response logging
  5. debug - Detailed debugging information

Configuring Log Level

You can configure the log level when starting the application using the --log-level or -l flag:

Copy & paste β€” that's it
npm start -- --log-level=debug

Or when using the global installation:

Copy & paste β€” that's it
wweb-mcp --log-level=debug

Command Mode Logging

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.

Test Environment

In test environments (when NODE_ENV=test or when running with Jest), the logger automatically adjusts its behavior to be suitable for testing environments.