This Python-based MCP server integrates with Twilio to provide messaging capabilities through a simple API. It currently offers tools for sending messages and retrieving message logs, with plans for future expansion to include prompts and call features.
To set up the Twilio MCP server on your system, follow these steps:
Make sure you have Python 3.8+ installed on your system.
git clone https://github.com/yourusername/twilio-mcp-python.git
cd twilio-mcp-python
pip install -r requirements.txt
Create a .env
file in the root directory with your Twilio credentials:
TWILIO_ACCOUNT_SID=your_account_sid
TWILIO_AUTH_TOKEN=your_auth_token
TWILIO_PHONE_NUMBER=your_twilio_phone_number
The MCP server provides two main functions: sending messages and retrieving message logs.
To send a message using the MCP server:
from twilio_mcp import send_message
# Send a simple text message
response = send_message(
to="+1234567890",
body="Hello from MCP server!",
media_url=None # Optional: URL to media to include with message
)
# Check the response
print(f"Message SID: {response.sid}")
print(f"Status: {response.status}")
To retrieve logs of messages sent through your Twilio account:
from twilio_mcp import get_message_logs
# Get all message logs
logs = get_message_logs()
# Get logs with filters
filtered_logs = get_message_logs(
from_number="+1234567890", # Optional: filter by sender
to_number="+10987654321", # Optional: filter by recipient
date_sent="2023-06-01", # Optional: filter by date
limit=100 # Optional: limit number of results
)
# Process the logs
for message in filtered_logs:
print(f"From: {message.from_}")
print(f"To: {message.to}")
print(f"Body: {message.body}")
print(f"Date Sent: {message.date_sent}")
print("---")
The MCP server can be configured with additional options for greater flexibility:
Set a custom webhook URL to receive status updates:
from twilio_mcp import send_message
response = send_message(
to="+1234567890",
body="Message with status updates",
status_callback="https://your-webhook-url.com/updates"
)
Send MMS messages by including media URLs:
from twilio_mcp import send_message
response = send_message(
to="+1234567890",
body="Check out this image!",
media_url=["https://example.com/image.jpg"]
)
Multiple media URLs can be included as a list.
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "twilio-mcp-python" '{"command":"python","args":["-m","twilio-mcp-python"]}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"twilio-mcp-python": {
"command": "python",
"args": [
"-m",
"twilio-mcp-python"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"twilio-mcp-python": {
"command": "python",
"args": [
"-m",
"twilio-mcp-python"
]
}
}
}
3. Restart Claude Desktop for the changes to take effect