-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
36 lines (27 loc) · 1.01 KB
/
server.py
File metadata and controls
36 lines (27 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""
MCP Server Scaffold
-----------------------------------------
"Registering a server" = creating a FastMCP instance and decorating
functions as tools/resources. When mcp.run() executes, the server
announces these tools to any MCP client (Inspector, Claude Desktop, etc.)
over JSON-RPC (stdio). Clients can discover and call them immediately.
"""
import os
from fastmcp import FastMCP
from utils.weather_utils import get_weather, get_coordinates
# ---- register the server ----
mcp = FastMCP("WorkshopServer")
@mcp.tool()
def ping() -> dict:
"""Basic liveness check - returns OK status"""
return {"ok": True, "message": "Server is running"}
@mcp.tool()
def weather(city: str) -> dict:
"""Get current weather for a city using Open-Meteo API"""
coords = get_coordinates(city)
if "error" in coords:
return coords
return get_weather(coords["latitude"], coords["longitude"])
if __name__ == "__main__":
# This starts the JSON-RPC stdio loop and *registers* all decorated tools.
mcp.run()