summaryrefslogtreecommitdiff
path: root/scripts/weather_server.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/weather_server.py')
-rw-r--r--scripts/weather_server.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/scripts/weather_server.py b/scripts/weather_server.py
new file mode 100644
index 0000000..13a3bf6
--- /dev/null
+++ b/scripts/weather_server.py
@@ -0,0 +1,40 @@
+"""Test MCP server simulating a weather service.
+
+Usage:
+ python scripts/weather_server.py # stdio transport
+ python scripts/weather_server.py streamable-http # HTTP transport
+"""
+
+from mcp.server.fastmcp import FastMCP
+
+mcp = FastMCP("weather")
+
+_FORECASTS: dict[str, str] = {
+ "tokyo": "sunny, 28C",
+ "osaka": "cloudy, 26C",
+ "sapporo": "rain, 18C",
+ "new york": "sunny, 22C",
+ "london": "rain, 15C",
+}
+
+
+@mcp.tool()
+def get_weather(city: str) -> str:
+ """Return a simple weather forecast for a city."""
+ key = city.strip().lower()
+ return _FORECASTS.get(key, f"no forecast available for {city}")
+
+
+@mcp.tool()
+def list_cities() -> list[str]:
+ """Return the list of cities with available forecasts."""
+ return list(_FORECASTS.keys())
+
+
+if __name__ == "__main__":
+ import sys
+
+ transport = sys.argv[1] if len(sys.argv) > 1 else "stdio"
+ port = int(sys.argv[2]) if len(sys.argv) > 2 else 9000
+ mcp.settings.port = port
+ mcp.run(transport=transport)