logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

twilio-whatsapp-gateway-mcp

Enables programmatic dispatch of WhatsApp communications utilizing the Twilio API via a specialized FastMCP service interface. Features robust handling for secure credential configuration and includes an auxiliary script for direct API validation.

Author

twilio-whatsapp-gateway-mcp logo

wubbyweb

No License

Quick Info

GitHub GitHub Stars 1
NPM Weekly Downloads 0
Tools 1
Last Updated 2026-02-19

Tags

whatsapptwilioapisend whatsapptwilio apiwhatsapp messages

Twilio WhatsApp FastMCP Gateway Service 💬

This repository furnishes a streamlined FastMCP server module designed to facilitate the transmission of WhatsApp messages leveraging the Twilio Application Programming Interface.

Core Capabilities

  • 📲 Executes WhatsApp message transmission via the Twilio infrastructure.
  • 🤖 Exposes a callable tool named send_whatsapp accessible to FastMCP consumers (e.g., autonomous AI agents).
  • 🔒 Securely loads operational parameters and credentials from an isolated .env file.
  • 🧪 Provides a supplementary execution file (/home/rj/Code/mcp-generated/twilio_test.py) for immediate, non-server-mediated Twilio API verification.

Implementation Guide

  1. Acquire Source Files: Clone the repository or download the necessary components into the designated directory: /home/rj/Code/mcp-generated/.

  2. Establish Virtual Environment (Highly Recommended) 🌱 bash cd /home/rj/Code/mcp-generated/ python -m venv venv source venv/bin/activate # Use venv\Scripts\activate on Windows platforms

  3. Install Required Packages: Dependencies are itemized within /home/rj/Code/mcp-generated/whatsapp_server.py. Installation via pip is straightforward: bash 📦 pip install twilio python-dotenv pydantic-settings fastmcp

    Alternatively, leverage the FastMCP framework's integrated installation utility: bash fastmcp install /home/rj/Code/mcp-generated/whatsapp_server.py

  4. Configure Environmental Secrets:

    • Obtain credentials by registering for a Twilio account if one is not currently held.
    • Retrieve your unique Account SID and Auth Token from the Twilio management Console.
    • Set up either the WhatsApp Sandbox or provision a dedicated Twilio number supporting WhatsApp.
    • In the project's root location (/home/rj/Code/mcp-generated/), generate a configuration file named .env.
    • Populate the .env file with your Twilio access details: 🔑 dotenv # /home/rj/Code/mcp-generated/.env TWILIO_ACCOUNT_SID=ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxx TWILIO_AUTH_TOKEN=your_auth_token_here TWILIO_WHATSAPP_NUMBER=+14155238886 # Specify your Twilio-assigned WhatsApp identity

    • Crucial Step: Substitute the placeholder values with your legitimate credentials. The TWILIO_WHATSAPP_NUMBER must adhere to E.164 format (starting with a plus sign and country code). The server logic will auto-correct a missing leading plus sign if present in the .env. ❗

    • Trial Account Caveat: When operating under a Twilio trial subscription, the TWILIO_WHATSAPP_NUMBER must typically be the Sandbox identifier (+14155238886). Furthermore, all destination (to_number) phone numbers must be explicitly enrolled in your Twilio Sandbox via the console for message delivery to succeed. Delivering to non-enrolled numbers necessitates upgrading the Twilio account status.

Operational Instructions

1. Launching the FastMCP Service Endpoint

To expose the send_whatsapp functionality for remote procedure calls (e.g., consumption by an AI system integrated via FastMCP):

bash ▶️ python /home/rj/Code/mcp-generated/whatsapp_server.py

The service will initialize, logging the configured Twilio identity number, and await incoming requests (defaulting to stdio transport, though FastMCP supports alternatives). A client process can then invoke the send_whatsapp operation, supplying to_number (which must include the whatsapp: prefix, e.g., whatsapp:+15551234567) and the message content.

Illustrative Client Invocation (Conceptual Format):

A remote consumer (e.g., an AI 🤖) would structure its communication resembling this (format dependent on the underlying transport layer):

{ "tool_name": "send_whatsapp", "arguments": { "to_number": "whatsapp:+15551234567", "message": "Hello from the FastMCP server!" } }

The server will process the instruction, interface with the Twilio infrastructure, and return a status confirmation or an error report.

2. Executing the Verification Routine

The dedicated script located at /home/rj/Code/mcp-generated/twilio_test.py permits direct testing of message transmission using your established Twilio credentials, bypassing the main FastMCP server architecture. 🛠️

  • Configuration Adjustment: Verify that the to= parameter within /home/rj/Code/mcp-generated/twilio_test.py points to a WhatsApp contact enrolled in your Twilio Sandbox (if Sandbox is active) or any legitimate WhatsApp recipient (if using a dedicated number). The from_ identifier should align with your Sandbox number (whatsapp:+14155238886) or your dedicated Twilio WhatsApp identity.
  • Script Invocation: bash ▶️ python /home/rj/Code/mcp-generated/twilio_test.py

    This command initiates a transmission attempt using a pre-defined test payload ("Is this working?") from the configured source identity to the specified destination. WIKIPEDIA: XMLHttpRequest (XHR) is an Application Programming Interface (API) realized as a JavaScript object. Its primary functions involve dispatching HTTP requests from a user agent (web browser) toward an origin server. This capability allows browser-based applications to initiate server communications subsequent to page rendering, facilitating asynchronous data retrieval. XMLHttpRequest forms the foundational technology underpinning Ajax programming paradigms. Before its widespread adoption, client-server interaction relied predominantly on traditional hyperlink navigation and HTML form submissions, frequently resulting in full page reloads.

== Historical Context == The foundational concept for XMLHttpRequest originated in the year 2000, conceived by the development team behind Microsoft Outlook. This concept was subsequently integrated into the Internet Explorer 5 browser release (1999). However, the initial implementation did not employ the standardized XMLHttpRequest identifier. Instead, developers utilized COM object instantiation identifiers like ActiveXObject("Msxml2.XMLHTTP") and ActiveXObject("Microsoft.XMLHTTP"). As of the release of Internet Explorer 7 (2006), universal support for the XMLHttpRequest constructor became standard across all major browser engines. Today, the XMLHttpRequest identifier is recognized as the established convention across dominant browser platforms, including Mozilla's Gecko engine (2002), Apple's Safari 1.2 (2004), and Opera 8.0 (2005).

=== Standardization Efforts === The World Wide Web Consortium (W3C) published the first formal specification, a Working Draft, for the XMLHttpRequest object on April 5, 2006. On February 25, 2008, the W3C advanced this to the Level 2 specification Working Draft. Level 2 introduced enhancements such as progress monitoring methods, support for cross-site invocation (CORS), and mechanisms for handling raw byte streams. By the close of 2011, the Level 2 feature set was merged back into the primary specification document. Development stewardship transitioned to the WHATWG initiative at the conclusion of 2012, which now maintains the living document utilizing the Web IDL specification language.

== Operational Procedure == Typically, executing an HTTP request using XMLHttpRequest necessitates adherence to several sequential programming stages.

  1. Instantiation: Create an XMLHttpRequest object instance by invoking its constructor function:
  2. Configuration: Invoke the open() method to define the request method (GET, POST, etc.), specify the target Uniform Resource Identifier (URI), and determine whether the operation should be synchronous or asynchronous:
  3. Asynchronous Listener Setup: For asynchronous operations, attach an event handler function designed to execute when the request's state transition events are fired:
  4. Transmission: Begin the actual network transmission by calling the send() method, optionally passing request body data:
  5. Response Handling: Monitor state changes via the established event listener. Upon successful reception of data from the server, the payload is typically accessible via the responseText property. When the object completes all processing stages, its state transitions to 4 (the 'done' state). Beyond these fundamental steps, XMLHttpRequest provides extensive control mechanisms for request preparation and response interpretation. Custom HTTP headers can be programmatically affixed to tailor server behavior. Data payloads can be uploaded during the send() call. Server responses can be natively parsed from JSON format into native JavaScript objects or processed incrementally as data streams arrive, avoiding latency associated with waiting for the complete transmission. Requests can be terminated prematurely or configured with a timeout threshold after which they automatically fail.

See Also

`