1b74b06753
Cut comment and docstring volume roughly in half across src, tests, examples, and docs_src: removed comments that restate the adjacent code, leftover development narration, section banners, and self-evident Args/Returns blocks, and compressed the remaining docstrings to a Google-style summary line plus only the detail that earns its place. Kept (and tightened) the load-bearing content: Raises sections, deprecation and version-availability notes, spec/RFC/issue references, why-comments for non-obvious decisions, and all coverage pragmas. The generated mcp_types.v* wire modules are untouched.
58 lines
1.8 KiB
Python
58 lines
1.8 KiB
Python
# /// script
|
|
# dependencies = []
|
|
# ///
|
|
|
|
"""MCPServer that sends a text message to a phone number via https://surgemsg.com/.
|
|
|
|
Requires a `.env` file with SURGE_API_KEY, SURGE_ACCOUNT_ID, SURGE_MY_PHONE_NUMBER,
|
|
SURGE_MY_FIRST_NAME, and SURGE_MY_LAST_NAME — visit https://surgemsg.com/ to obtain them.
|
|
"""
|
|
|
|
from typing import Annotated
|
|
|
|
import httpx
|
|
from pydantic import BeforeValidator
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
|
|
from mcp.server.mcpserver import MCPServer
|
|
|
|
|
|
class SurgeSettings(BaseSettings):
|
|
model_config: SettingsConfigDict = SettingsConfigDict(env_prefix="SURGE_", env_file=".env")
|
|
|
|
api_key: str
|
|
account_id: str
|
|
my_phone_number: Annotated[str, BeforeValidator(lambda v: "+" + v if not v.startswith("+") else v)]
|
|
my_first_name: str
|
|
my_last_name: str
|
|
|
|
|
|
mcp = MCPServer("Text me")
|
|
surge_settings = SurgeSettings() # type: ignore
|
|
|
|
|
|
@mcp.tool(name="textme", description="Send a text message to me")
|
|
def text_me(text_content: str) -> str:
|
|
"""Send a text message to a phone number via https://surgemsg.com/"""
|
|
with httpx.Client() as client:
|
|
response = client.post(
|
|
"https://api.surgemsg.com/messages",
|
|
headers={
|
|
"Authorization": f"Bearer {surge_settings.api_key}",
|
|
"Surge-Account": surge_settings.account_id,
|
|
"Content-Type": "application/json",
|
|
},
|
|
json={
|
|
"body": text_content,
|
|
"conversation": {
|
|
"contact": {
|
|
"first_name": surge_settings.my_first_name,
|
|
"last_name": surge_settings.my_last_name,
|
|
"phone_number": surge_settings.my_phone_number,
|
|
}
|
|
},
|
|
},
|
|
)
|
|
response.raise_for_status()
|
|
return f"Message sent: {text_content}"
|