server.py•1.12 kB
#!/usr/bin/env python3
import os
from fastmcp import FastMCP
from dotenv import load_dotenv
from smartthings import get_client_from_env
load_dotenv()
mcp = FastMCP("TV Control MCP Server")
@mcp.tool(description="Turn on the TV via SmartThings")
def tv_turn_on() -> dict:
client = get_client_from_env()
return client.turn_on()
@mcp.tool(description="Turn off the TV via SmartThings")
def tv_turn_off() -> dict:
client = get_client_from_env()
return client.turn_off()
@mcp.tool(description="Set the TV volume (0-100) via SmartThings")
def tv_set_volume(level: int) -> dict:
client = get_client_from_env()
return client.set_volume(level)
@mcp.tool(description="Set the TV input source (e.g., hdmi1) via SmartThings")
def tv_set_input(source: str) -> dict:
client = get_client_from_env()
return client.set_input(source)
if __name__ == "__main__":
port = int(os.environ.get("PORT", 8000))
host = "0.0.0.0"
print(f"Starting FastMCP server on {host}:{port}")
mcp.run(
transport="http",
host=host,
port=port,
stateless_http=True
)