get_current_weather
Retrieve current weather data including temperature, wind, humidity, pressure, UV index, visibility, and conditions for any location. Optionally includes air quality information.
Instructions
Get real-time current weather for any location. Returns temperature, wind speed and direction, humidity, pressure, UV index, visibility, feels-like temperature, and weather condition. Optionally includes air quality (AQI) data.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| q | Yes | Location query. Accepts: city name (London), lat/lon (51.5,-0.1), US zip (10001), UK postcode (SW1), IATA airport code (iata:LHR), IP address, or auto:ip for caller's location. | |
| aqi | No | Include air quality data (CO, NO2, O3, SO2, PM2.5, PM10). Default: no. |
Implementation Reference
- src/index.ts:281-285 (handler)Handler logic for the get_current_weather tool.
case "get_current_weather": { const { q, aqi = "no" } = args as { q: string; aqi?: string }; result = await weatherRequest("/current.json", { q, aqi }); break; } - src/index.ts:58-77 (schema)Schema registration for get_current_weather.
{ name: "get_current_weather", description: "Get real-time current weather for any location. Returns temperature, wind speed and direction, humidity, pressure, UV index, visibility, feels-like temperature, and weather condition. Optionally includes air quality (AQI) data.", inputSchema: { type: "object", properties: { q: { type: "string", description: "Location query. Accepts: city name (London), lat/lon (51.5,-0.1), US zip (10001), UK postcode (SW1), IATA airport code (iata:LHR), IP address, or auto:ip for caller's location.", }, aqi: { type: "string", enum: ["yes", "no"], description: "Include air quality data (CO, NO2, O3, SO2, PM2.5, PM10). Default: no.", }, }, required: ["q"], }, - src/index.ts:22-41 (helper)Helper function used by tools to perform API requests.
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}` ); } return data; }