weather
Get current conditions for any city. Enter a city name to receive temperature, humidity, wind speed, and more.
Instructions
Return current weather for a city using wttr.in.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| city | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- server.py:80-96 (handler)The weather tool handler function. Decorated with @mcp.tool(), it takes a city name, fetches current weather from wttr.in API, and returns a JSON summary with temperature, humidity, wind speed, etc.
def weather(city: str) -> str: """Return current weather for a city using wttr.in.""" response = httpx.get(f"https://wttr.in/{city}", params={"format": "j1"}, timeout=20) response.raise_for_status() data: dict[str, Any] = response.json() current = data["current_condition"][0] summary = { "city": city, "temp_c": current.get("temp_C"), "temp_f": current.get("temp_F"), "feels_like_c": current.get("FeelsLikeC"), "description": current.get("weatherDesc", [{}])[0].get("value"), "humidity": current.get("humidity"), "wind_kmph": current.get("windspeedKmph"), } return json.dumps(summary, indent=2) - server.py:79-79 (registration)The @mcp.tool() decorator registers the weather function as a tool with the FastMCP server.
@mcp.tool() - server.py:80-80 (schema)The input schema is implicit via the function signature: 'city: str'. The output schema is the JSON structure defined inside the function with keys like city, temp_c, temp_f, feels_like_c, description, humidity, wind_kmph.
def weather(city: str) -> str: