from fastmcp import FastMCP
import httpx
mcp = FastMCP("ISS Position Tracker")
@mcp.tool(description="Get ISS location with coordinates and altitude")
async def get_iss_location() -> str:
async with httpx.AsyncClient() as client:
response = await client.get("https://api.wheretheiss.at/v1/satellites/25544")
response.raise_for_status() # FastMCP catches exceptions automatically
data = response.json()
lat, lon = data["latitude"], data["longitude"]
lat_dir = "N" if lat >= 0 else "S"
lon_dir = "E" if lon >= 0 else "W"
return (
f"The ISS is currently at {abs(lat):.2f}° {lat_dir}, {abs(lon):.2f}° {lon_dir}, "
f"flying at {data['altitude']:.2f} km and traveling at {data['velocity']:.2f} km/h."
)
if __name__ == "__main__":
mcp.run(transport="http", host="0.0.0.0", port=8000, stateless_http=True)