Whatsapp-MCP-Server

ATHARVISM2804/Whatsapp-MCP-Server

3.1

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 dayong@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
Resources
0
Prompts
0

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!