Skip to main content
Glama

Twilio WhatsApp FastMCP Server

by wubbyweb
whatsapp_server.cpython-312.pyc4.08 kB
� �h� � ��ddlZddlmZddlmZmZddlmZmZddl m Z ddl m Z ddlmZGd�d e�Z e�Zed dgd���Ze ej.ej0�Zej5�deeed��fdeeed��fdefd��Zedk(r.ed�edej<���ej?�yy#e$r%Zed e���ed �ed �YdZ[��dZ[wwxYw)�N)� Annotated)�BeforeValidator�Field)� BaseSettings�SettingsConfigDict)�Client)�TwilioRestException)�FastMCPc��eZdZUedd��Zedd��Zeed<edd��Z eed <edd ��Z e ee d ��fed <y )�Settings�TWILIO_z.env)� env_prefix�env_file.zTwilio Account SID�� description� account_sidzTwilio Auth Token� auth_tokenz0Your Twilio WhatsApp number (e.g., +14155238886)c�V�t|�jd�sd|��St|�S)N�+)�str� startswith)�vs �./home/rj/Code/mcp-generated/whatsapp_server.py�<lambda>zSettings.<lambda>s(��c�!�f�6G�6G��6L��1�#�w��RU�VW�RX���whatsapp_numberN) �__name__� __module__� __qualname__r� model_configrrr�__annotations__rrrr�rrr r s_��%��V�L�L��S�.B�C�K��C��C�-@�A�J��A� �c�Q�R��Y� �_�X� Y�Y��Srr zError loading settings: znPlease ensure you have a .env file with TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN, and TWILIO_WHATSAPP_NUMBER set.�zWhatsApp Messengerz,Use the send_whatsapp tool to send messages.)�twilioz python-dotenvzpydantic-settings)� instructions� dependencies� to_numberz@Recipient's WhatsApp number in E.164 format (e.g., +15551234567)r�messagezThe message content to send�returnc���|jd�r|nd|��}tjjd�rtjndtj��} tjj |||��}d|�d|j ��}t|�|S#t$r"}d|�d|��}td|���|cYd}~Sd}~wt$r}d |��}td|���|cYd}~Sd}~wwxYw) z� Sends a WhatsApp message to the specified recipient number using Twilio. The recipient number MUST be in E.164 format, including the 'whatsapp:' prefix (e.g., 'whatsapp:+15551234567'). z whatsapp:)�from_�body�toz&WhatsApp message sent successfully to z. SID: z#Failed to send WhatsApp message to z: zERROR: NzAn unexpected error occurred: ) r�settingsr� twilio_client�messages�create�sid�printr � Exception)r'r(� formatted_to�formatted_from�message_instance� confirmation�e� error_messages r� send_whatsappr;.s��!*� 4� 4�[� A�9��S\�R]�G^�L�19�1I�1I�1T�1T�U`�1a�X�-�-�ir�s{�tL�tL�sM�hN�N��(�1�1�8�8� ���9� �� @� �{�'�Rb�Rf�Rf�Qg�h� � �l����� ��=�i�[��1�#�N� � �� ��'�(���� ��8���<� � �� ��'�(���� �s1�AB� C.�&C�=C.� C.�C)�#C.�)C.�__main__zStarting WhatsApp MCP Server...zUsing Twilio Number: ) �os�typingr�pydanticrr�pydantic_settingsrr� twilio.restr� TwilioClient�twilio.base.exceptionsr �fastmcpr r r.r4r9r3�exit�mcprrr/�toolrr;rr�runr"rr�<module>rIs.�� ��+�>�.�6�� S�|� S� ��z�H���?�A� ���X�1�1�8�3F�3F�G� �����"�� � �\�]� ^��"� �s�E�.K�L�L� M� "�  � "� �"�J �z�� � +�-� � !�(�":�":�!;� <�=��G�G�I���s� � � $�Q�C� (�)� � z�{���G�G�� �s�C�C=�C8�8C=

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/wubbyweb/mcp-generated'

If you have feedback or need assistance with the MCP directory API, please join our Discord server