-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweather_mcp_server.py
More file actions
62 lines (50 loc) · 1.7 KB
/
Copy pathweather_mcp_server.py
File metadata and controls
62 lines (50 loc) · 1.7 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python3
"""Minimal MCP-compatible weather server backed by ZCP."""
from __future__ import annotations
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
SRC = ROOT / "src"
if str(SRC) not in sys.path:
sys.path.insert(0, str(SRC))
from zcp import FastZCP
from zcp.mcp_stdio import run_mcp_stdio_server_sync
app = FastZCP("Weather MCP Compatibility Server", version="0.1.0")
@app.tool(
name="weather.get_current",
description="Get the current weather for a city.",
input_schema={
"type": "object",
"properties": {
"city": {"type": "string"},
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
},
"required": ["city"],
"additionalProperties": False,
},
output_schema={
"type": "object",
"properties": {
"city": {"type": "string"},
"unit": {"type": "string"},
"temperature": {"type": "integer"},
"condition": {"type": "string"},
},
"required": ["city", "unit", "temperature", "condition"],
"additionalProperties": False,
},
output_mode="scalar",
inline_ok=True,
)
def get_current_weather(city: str, unit: str = "celsius") -> dict[str, object]:
base = {
"hangzhou": {"temperature": 24, "condition": "Cloudy"},
"beijing": {"temperature": 18, "condition": "Sunny"},
"shanghai": {"temperature": 22, "condition": "Rainy"},
}
payload = base.get(city.strip().lower(), {"temperature": 20, "condition": "Unknown"})
return {"city": city, "unit": unit, **payload}
def main() -> None:
run_mcp_stdio_server_sync(app)
if __name__ == "__main__":
main()