From ff829f7826ce3040891b5a18cceca358c9ea5a0c Mon Sep 17 00:00:00 2001 From: zzstoatzz Date: Sat, 30 Nov 2024 19:30:04 -0600 Subject: [PATCH] surge example --- examples/text_me.py | 48 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 examples/text_me.py diff --git a/examples/text_me.py b/examples/text_me.py new file mode 100644 index 000000000..ea5eacc1f --- /dev/null +++ b/examples/text_me.py @@ -0,0 +1,48 @@ +# /// script +# dependencies = ["fastmcp"] + +""" +FastMCP Echo Server +""" + +import httpx +from pydantic_settings import BaseSettings, SettingsConfigDict + +from fastmcp import FastMCP + + +class SurgeSettings(BaseSettings): + model_config: SettingsConfigDict = SettingsConfigDict( + env_prefix="SURGE_", env_file=".env" + ) + + api_key: str + account_id: str + my_phone_number: str + + +# Create server +mcp = FastMCP("Text Me") +surge_settings = SurgeSettings() # type: ignore + + +@mcp.tool() +def text_me(text_content: str) -> str: + """Send a text message to a phone number""" + with httpx.Client() as client: + response = client.post( + "https://api.surgemsg.com/messages", + headers={ + "Authorization": surge_settings.api_key, + "Surge-Account": surge_settings.account_id, + "Content-Type": "application/json", + }, + json={ + "body": text_content, + "conversation": { + "contact": {"phone_number": surge_settings.my_phone_number} + }, + }, + ) + response.raise_for_status() + return response.json()