get_forecast
Retrieve detailed weather forecasts for 1-14 days with daily summaries, hourly breakdowns, current conditions, astronomy data, and optional alerts and air quality information for any location worldwide.
Instructions
Get weather forecast for 1 to 14 days. Returns daily summaries (max/min/avg temp, rain chance, UV, wind) and hourly breakdowns. Also returns current conditions, astronomy data (sunrise/sunset/moon phase), and optionally weather alerts and air quality.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| q | Yes | Location query — city name, lat/lon, zip, postcode, IATA, or IP. | |
| days | No | Number of forecast days (1–14). Default: 3. | |
| alerts | No | Include government weather alerts. Default: no. | |
| aqi | No | Include air quality data. Default: no. |
Implementation Reference
- src/index.ts:286-295 (handler)The handler for 'get_forecast' extracts arguments from the request and calls 'weatherRequest'.
case "get_forecast": { const { q, days = 3, alerts = "no", aqi = "no" } = args as { q: string; days?: number; alerts?: string; aqi?: string; }; result = await weatherRequest("/forecast.json", { q, days, alerts, aqi }); break; } - src/index.ts:80-95 (schema)Registration of the 'get_forecast' tool with its description and input schema.
name: "get_forecast", description: "Get weather forecast for 1 to 14 days. Returns daily summaries (max/min/avg temp, rain chance, UV, wind) and hourly breakdowns. Also returns current conditions, astronomy data (sunrise/sunset/moon phase), and optionally weather alerts and air quality.", inputSchema: { type: "object", properties: { q: { type: "string", description: "Location query — city name, lat/lon, zip, postcode, IATA, or IP.", }, days: { type: "number", description: "Number of forecast days (1–14). Default: 3.", }, alerts: { type: "string", - src/index.ts:22-38 (helper)The 'weatherRequest' helper function that executes the actual API call for all weather tools.
async function weatherRequest( endpoint: string, params: Record<string, string | number> ): Promise<unknown> { const searchParams = new URLSearchParams({ key: API_KEY! }); for (const [k, v] of Object.entries(params)) { searchParams.set(k, String(v)); } const url = `${BASE_URL}${endpoint}?${searchParams.toString()}`; const res = await fetch(url); const data = await res.json(); if (!res.ok) { const err = data as { error?: { code: number; message: string } }; throw new McpError( ErrorCode.InternalError, `WeatherAPI error ${err.error?.code}: ${err.error?.message ?? res.statusText}` );