Whatsapp-MCP-Server

ATHARVISM2804/Whatsapp-MCP-Server

3.2

If you are the rightful owner of Whatsapp-MCP-Server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

The WhatsApp MCP Server is a Python-based microservice that leverages the Twilio WhatsApp API to send messages, built using FastMCP for efficient tool management and automation.

Tools
  1. send_whatsapp_message

    Tool to send a WhatsApp message using Twilio API.

WhatsApp MCP Server πŸš€

πŸ“² FastMCP WhatsApp Server

A Python-based MCP (Model Context Protocol) microservice that uses the Twilio WhatsApp API to send messages. Built with FastMCP for fast, modular AI tools and automations.


πŸš€ Features

  • βœ… Send WhatsApp messages using Twilio
  • βš™οΈ Powered by FastMCP for easy tool management
  • πŸ”’ Uses .env for secure credential storage
  • πŸ§ͺ Includes client script to test message sending

πŸ“ Project Structure

whatsapp-mcp-server/ β”œβ”€β”€ .env # Twilio credentials (not committed) β”œβ”€β”€ .gitignore # Ignores venv and env files β”œβ”€β”€ whatsapp_server.py # Main FastMCP server β”œβ”€β”€ client_test.py # Example client to call MCP tool β”œβ”€β”€ requirements.txt # Project dependencies β”œβ”€β”€ README.md # You’re reading it! └── venv/ # Python virtual environment (auto-generated)

yaml Copy Edit


βš™οΈ Requirements

  • Python 3.10 or above
  • Twilio account with WhatsApp Sandbox setup
  • FastMCP installed

πŸ› οΈ Setup Guide

1. πŸ“¦ Clone or Download the Project

git clone https://github.com/yourusername/whatsapp-mcp-server.git
cd whatsapp-mcp-server
2. πŸ§ͺ Create and Activate Virtual Environment
bash
Copy
Edit
python -m venv venv
.\venv\Scripts\activate    # For Windows (VS Code, PowerShell, CMD)
3. πŸ“₯ Install Dependencies
bash
Copy
Edit
pip install -r requirements.txt
4. πŸ” Create .env File
Create a file named .env in the root directory:

ini
Copy
Edit
TWILIO_ACCOUNT_SID=your_account_sid
TWILIO_AUTH_TOKEN=your_auth_token
TWILIO_WHATSAPP_FROM=whatsapp:+14155238886
πŸ›‘ Important: Never share this file publicly.

▢️ Running the Server
Start the MCP WhatsApp Server
bash
Copy
Edit
python whatsapp_server.py
Output will show:

arduino
Copy
Edit
Server running at http://127.0.0.1:8000/mcp
πŸ“€ Sending a WhatsApp Message
Use the included test client to send a message:

bash
Copy
Edit
python client_test.py
Make sure to update client_test.py with the recipient WhatsApp number like:

python
Copy
Edit
"to": "whatsapp:+919999999999",
"body": "Hello from FastMCP πŸš€"
πŸ§ͺ Sample Tool Code
Tool to send WhatsApp message:

python
Copy
Edit
@mcp.tool
def send_whatsapp_message(to: str, body: str) -> str:
    try:
        message = twilio_client.messages.create(
            body=body,
            from_=from_number,
            to=to
        )
        return f"βœ… Sent! SID: {message.sid}"
    except Exception as e:
        return f"❌ Error: {str(e)}"
πŸ’‘ Tips
You can expose more tools in whatsapp_server.py for different message types.

Try deploying the MCP server to the cloud using Render, Replit, or Railway.

Connect this MCP tool to a bigger AI Agent stack.

πŸ“œ License
This project is licensed under the Apache 2.0 License.

πŸ™Œ Acknowledgements
FastMCP β€” for simplifying MCP servers

Twilio β€” for the WhatsApp API

yaml
Copy
Edit

---

Let me know if you'd like this auto-generated in your project as a real file or need a zipped version!