ATHARVISM2804/Whatsapp-MCP-Server
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.
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!