Twilio WhatsApp FastMCP Server ๐ฌ
This project provides a simple FastMCP server that allows sending WhatsApp messages using the Twilio API.
Features
- ๐ฒ Sends WhatsApp messages via Twilio.
- ๐ค Exposes a
send_whatsapp tool for use with FastMCP clients (like AI models).
- ๐ Loads configuration securely from a
.env file.
- ๐งช Includes a basic test script (
/home/rj/Code/mcp-generated/twilio_test.py) for direct Twilio API interaction.
Setup
-
Get the Code:
Clone this repository or download the source files into /home/rj/Code/mcp-generated/.
-
**Create a Virtual Environment (Recommended){
@@ -77,11 +77,11 @@
2. Running the Test Script
-The /home/rj/Code/mcp-generated/twilio_test.py script provides a way to directly test sending a message using your Twilio credentials without the FastMCP server.
+The /home/rj/Code/mcp-generated/twilio_test.py script provides a way to directly test sending a message using your Twilio credentials without the FastMCP server. ๐ ๏ธ
- Modify the script: Ensure the
to= number in /home/rj/Code/mcp-generated/twilio_test.py is a WhatsApp number linked to your Twilio Sandbox (if using the Sandbox) or any valid WhatsApp number (if using a purchased Twilio number). The from_ number should typically be your Twilio Sandbox number (whatsapp:+14155238886) or your purchased Twilio WhatsApp number.
- Run the script:
python /home/rj/Code/mcp-generated/twilio_test.py
```
This will attempt to send a hardcoded message ("Is this working?") from the specified Twilio number to the specified recipient.
:**
bash ๐ฑ cd /home/rj/Code/mcp-generated/ python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install Dependencies:
The necessary dependencies are listed in /home/rj/Code/mcp-generated/whatsapp_server.py. You can install them using pip:
pip install twilio python-dotenv pydantic-settings fastmcp
Alternatively, if using the FastMCP framework features:
fastmcp install /home/rj/Code/mcp-generated/whatsapp_server.py
-
Configure Environment Variables:
Usage
1. Running the FastMCP Server
To make the send_whatsapp tool available for remote calls (e.g., from an AI model integrated with FastMCP):
python /home/rj/Code/mcp-generated/whatsapp_server.py
The server will start and print the Twilio number it's configured to use. It will listen for incoming requests (by default via stdio, but FastMCP supports other transports). A FastMCP client can then call the send_whatsapp tool with to_number (including the whatsapp: prefix, e.g., whatsapp:+15551234567) and message arguments.
Example Interaction (Conceptual):
A client (like an AI ๐ค) might send a request like this (format depends on the transport):
{
"tool_name": "send_whatsapp",
"arguments": {
"to_number": "whatsapp:+15551234567",
"message": "Hello from the FastMCP server!"
}
}
The server will process this, call the Twilio API, and return a confirmation or error message.
2. Running the Test Script
The /home/rj/Code/mcp-generated/twilio_test.py script provides a way to directly test sending a message using your Twilio credentials without the FastMCP server. ๐ ๏ธ