Spaces:
Running
Running
zzstoatzz commited on
Commit ·
af4d538
1
Parent(s): 3958a11
more
Browse fileswip
link em
- examples/text_me.py +10 -8
examples/text_me.py
CHANGED
|
@@ -1,11 +1,14 @@
|
|
| 1 |
# /// script
|
| 2 |
# dependencies = ["fastmcp"]
|
|
|
|
| 3 |
|
| 4 |
"""
|
| 5 |
FastMCP Echo Server
|
| 6 |
"""
|
| 7 |
|
|
|
|
| 8 |
import httpx
|
|
|
|
| 9 |
from pydantic_settings import BaseSettings, SettingsConfigDict
|
| 10 |
|
| 11 |
from fastmcp import FastMCP
|
|
@@ -18,22 +21,21 @@ class SurgeSettings(BaseSettings):
|
|
| 18 |
|
| 19 |
api_key: str
|
| 20 |
account_id: str
|
| 21 |
-
my_phone_number:
|
|
|
|
|
|
|
| 22 |
my_first_name: str
|
| 23 |
my_last_name: str
|
| 24 |
|
| 25 |
|
| 26 |
# Create server
|
| 27 |
-
mcp = FastMCP("Text
|
| 28 |
surge_settings = SurgeSettings() # type: ignore
|
| 29 |
|
| 30 |
|
| 31 |
-
@mcp.tool(
|
| 32 |
-
name="text_me",
|
| 33 |
-
description="Send a text message to the number set as SURGE_MY_PHONE_NUMBER in the .env file",
|
| 34 |
-
)
|
| 35 |
def text_me(text_content: str) -> str:
|
| 36 |
-
"""Send a text message to a phone number"""
|
| 37 |
with httpx.Client() as client:
|
| 38 |
response = client.post(
|
| 39 |
"https://api.surgemsg.com/messages",
|
|
@@ -54,4 +56,4 @@ def text_me(text_content: str) -> str:
|
|
| 54 |
},
|
| 55 |
)
|
| 56 |
response.raise_for_status()
|
| 57 |
-
return
|
|
|
|
| 1 |
# /// script
|
| 2 |
# dependencies = ["fastmcp"]
|
| 3 |
+
# ///
|
| 4 |
|
| 5 |
"""
|
| 6 |
FastMCP Echo Server
|
| 7 |
"""
|
| 8 |
|
| 9 |
+
from typing import Annotated
|
| 10 |
import httpx
|
| 11 |
+
from pydantic import BeforeValidator
|
| 12 |
from pydantic_settings import BaseSettings, SettingsConfigDict
|
| 13 |
|
| 14 |
from fastmcp import FastMCP
|
|
|
|
| 21 |
|
| 22 |
api_key: str
|
| 23 |
account_id: str
|
| 24 |
+
my_phone_number: Annotated[
|
| 25 |
+
str, BeforeValidator(lambda v: "+" + v if not v.startswith("+") else v)
|
| 26 |
+
]
|
| 27 |
my_first_name: str
|
| 28 |
my_last_name: str
|
| 29 |
|
| 30 |
|
| 31 |
# Create server
|
| 32 |
+
mcp = FastMCP("Text me")
|
| 33 |
surge_settings = SurgeSettings() # type: ignore
|
| 34 |
|
| 35 |
|
| 36 |
+
@mcp.tool(name="textme", description="Send a text message to me")
|
|
|
|
|
|
|
|
|
|
| 37 |
def text_me(text_content: str) -> str:
|
| 38 |
+
"""Send a text message to a phone number via https://surgemsg.com/"""
|
| 39 |
with httpx.Client() as client:
|
| 40 |
response = client.post(
|
| 41 |
"https://api.surgemsg.com/messages",
|
|
|
|
| 56 |
},
|
| 57 |
)
|
| 58 |
response.raise_for_status()
|
| 59 |
+
return f"Message sent: {text_content}"
|