Enables secure loading of configuration and credentials from .env files, supporting environment-based configuration for the MCP server.
Provides settings validation and management through pydantic-settings, ensuring proper configuration of the MCP server.
Enables sending WhatsApp messages through Twilio's API, requiring Twilio credentials and allowing specification of recipient numbers and message content.
Provides a tool for sending WhatsApp messages to specified phone numbers, with support for Twilio's WhatsApp sandbox or purchased WhatsApp numbers.
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_whatsapptool for use with FastMCP clients (like AI models).🔒 Loads configuration securely from a
.envfile.🧪 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.pyis a WhatsApp number linked to your Twilio Sandbox (if using the Sandbox) or any valid WhatsApp number (if using a purchased Twilio number). Thefrom_number should typically be your Twilio Sandbox number (whatsapp:+14155238886) or your purchased Twilio WhatsApp number.Run the script:
:**
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 fastmcpAlternatively, if using the FastMCP framework features:
fastmcp install /home/rj/Code/mcp-generated/whatsapp_server.pyConfigure Environment Variables:
Sign up for a Twilio account if you don't have one.
Get your Account SID and Auth Token from the Twilio Console.
Set up the Twilio Sandbox for WhatsApp or configure a dedicated Twilio WhatsApp number.
Create a file named
.envin the project root directory (/home/rj/Code/mcp-generated/).Add your Twilio credentials and WhatsApp number to the
.envfile: 🔑# /home/rj/Code/mcp-generated/.env TWILIO_ACCOUNT_SID=ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxx TWILIO_AUTH_TOKEN=your_auth_token_here TWILIO_WHATSAPP_NUMBER=+14155238886 # Use your Twilio WhatsApp number (Sandbox or purchased)Important: Replace the placeholder values with your actual credentials and number. Ensure the
TWILIO_WHATSAPP_NUMBERstarts with a+and includes the country code (E.164 format). Thewhatsapp_server.pyscript will automatically add the+if it's missing from the.envfile. ❗Trial Account Note: If you are using a Twilio trial account, the
TWILIO_WHATSAPP_NUMBERwill likely be the Twilio Sandbox number (+14155238886). You must enroll any recipient (to_number) phone numbers in your Twilio Sandbox via the Twilio console for messages to be delivered successfully. Sending to non-enrolled numbers requires upgrading your Twilio account.
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):
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):
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. 🛠️
Modify the script: Ensure the
to=number in/home/rj/Code/mcp-generated/twilio_test.pyis a WhatsApp number linked to your Twilio Sandbox (if using the Sandbox) or any valid WhatsApp number (if using a purchased Twilio number). Thefrom_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.pyThis will attempt to send a hardcoded message ("Is this working?") from the specified Twilio number to the specified recipient.
This server cannot be installed
remote-capable server
The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.
A simple server that enables AI models to send WhatsApp messages via the Twilio API by exposing a send_whatsapp tool through the FastMCP framework.
Related MCP Servers
- -security-license-qualityA Model Context Protocol server that enables Claude and other AI assistants to send SMS and MMS messages using Twilio.Last updated -1810MIT License
- -security-license-qualityA Node.js application that connects WhatsApp Web with AI models through the Model Context Protocol, enabling automated messaging, contact management, and group chat functionality through AI-driven workflows.Last updated -2132MIT License
- -security-license-qualityAn implementation of the Model Context Protocol (MCP) server that exposes Twilio APIs to AI assistants and tools, allowing them to interact with Twilio services through the MCP protocol.Last updated -67MIT License
- -security-license-qualityAn MCP (Multi-Agent Conversation Protocol) Server that enables interaction with the WhatsApp Business API, allowing agents to send messages, manage media, and perform other WhatsApp business operations through natural language.Last updated -