get_forecast
Get calibrated forecast data for NYC, Chicago, Denver, Miami, or LA to support weather prediction market analysis.
Instructions
Get raw calibrated forecast context for one supported city.
Args: city: One of nyc, chicago, denver, miami, la.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| city | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/weather_edge_mcp/mcp_server.py:56-67 (handler)MCP tool handler that accepts a city string, fetches the NWS forecast via fetch_nws_forecast, and formats the result using format_forecast.
@mcp.tool() def get_forecast(city: str) -> str: """Get raw calibrated forecast context for one supported city. Args: city: One of nyc, chicago, denver, miami, la. """ cfg = get_city(city) forecast = _run(fetch_nws_forecast(cfg.key)) if not forecast: return "Forecast unavailable" return format_forecast(cfg.key, forecast) - src/weather_edge_mcp/mcp_server.py:56-57 (registration)The @mcp.tool() decorator registers get_forecast as an MCP tool on the FastMCP instance.
@mcp.tool() def get_forecast(city: str) -> str: - src/weather_edge_mcp/core.py:274-284 (helper)Helper that formats the raw forecast data (with bias adjustment) into a human-readable string.
def format_forecast(city_key: str, forecast: dict[str, Any]) -> str: cfg = CITIES[city_key] adjusted = forecast["high_f"] + cfg.forecast_bias return ( f"# Forecast — {cfg.label}\n\n" f"Raw NWS high: {forecast['high_f']}°F\n" f"Bias-adjusted high: {adjusted:.1f}°F\n" f"Sigma: {cfg.sigma}°F\n" f"Forecast: {forecast['forecast']}\n" f"Date: {forecast['date']}" ) - src/weather_edge_mcp/core.py:90-112 (helper)Async helper that fetches the NWS point forecast grid data for a city and returns the first daytime period's high temperature, date, and short forecast.
async def fetch_nws_forecast(city_key: str) -> dict[str, Any] | None: cached = get_cached(f"nws_{city_key}") if cached: return cached cfg = CITIES[city_key] url = f"{NWS_BASE}/gridpoints/{cfg.nws_office}/{cfg.nws_grid_x},{cfg.nws_grid_y}/forecast" async with httpx.AsyncClient(timeout=10) as client: try: resp = await client.get(url, headers={"User-Agent": "weather-edge-mcp"}) if resp.status_code != 200: return None for period in resp.json().get("properties", {}).get("periods", []): if period["isDaytime"]: result = { "high_f": period["temperature"], "date": period["startTime"][:10], "forecast": period["shortForecast"], } set_cached(f"nws_{city_key}", result) return result except Exception: return None return None - src/weather_edge_mcp/core.py:48-52 (schema)Validates the city input string against the supported CITIES dictionary and returns the CityConfig.
def get_city(city: str) -> CityConfig: key = city.lower().strip() if key not in CITIES: raise ValueError(f"Unknown city '{city}'. Valid: {', '.join(CITIES.keys())}") return CITIES[key]