-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_zcp_mcp_stdio_server.py
More file actions
76 lines (59 loc) · 2.18 KB
/
Copy pathrun_zcp_mcp_stdio_server.py
File metadata and controls
76 lines (59 loc) · 2.18 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python3
"""Official minimal MCP-compatible stdio server for 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, PromptArgument
from zcp.mcp_stdio import run_mcp_stdio_server_sync
app = FastZCP("ZCP MCP Compatibility Server")
@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"},
"humidity": {"type": "integer"},
},
"required": ["city", "unit", "temperature", "condition", "humidity"],
},
output_mode="scalar",
inline_ok=True,
)
def get_weather(city: str, unit: str = "celsius", ctx=None) -> dict[str, object]:
return {"city": city, "unit": unit, "temperature": 24, "condition": "Cloudy", "humidity": 67}
@app.resource("weather://cities", name="Cities", mime_type="application/json")
def cities():
return ["Hangzhou", "Beijing", "Shanghai"]
@app.resource_template("weather://city/{name}", name="City Weather", mime_type="application/json")
def city_weather(uri: str):
return {"uri": uri, "temperature": 24}
@app.prompt(
name="weather.summary",
description="Weather summary prompt.",
arguments=[PromptArgument(name="city", required=True)],
)
def weather_prompt(city: str):
return [{"role": "user", "content": f"Summarize weather for {city}"}]
@app.completion("weather.summary")
def complete_city(request):
cities = ["Hangzhou", "Beijing", "Shanghai"]
return [item for item in cities if item.lower().startswith(request.value.lower())]
if __name__ == "__main__":
run_mcp_stdio_server_sync(app)