mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-23 22:14:18 +02:00
surge example
This commit is contained in:
parent
ce8e4d7fba
commit
ff829f7826
1 changed files with 48 additions and 0 deletions
48
examples/text_me.py
Normal file
48
examples/text_me.py
Normal file
|
|
@ -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()
|
||||
Loading…
Add table
Add a link
Reference in a new issue