se_current_weather
Get current weather data for Swedish locations using SMHI, including temperature, wind, precipitation, and humidity.
Instructions
Get current weather for a location in Sweden using SMHI (Swedish Meteorological and Hydrological Institute). Includes temperature, wind, precipitation, humidity.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| location | Yes | Swedish city name (e.g. 'Stockholm', 'Malmö', 'Gothenburg', 'Kiruna') or lat,lon coordinates |
Implementation Reference
- src/servers/swedish-weather.js:113-155 (handler)The handler function that executes the logic for 'se_current_weather' by fetching location data and forecasting weather from SMHI.
async ({ location }) => { try { const loc = await getLocation(location); const data = await fetchForecast(loc.lat, loc.lon); const ts = data.timeSeries; if (!ts?.length) throw new Error("No forecast data"); // Find the entry closest to now const now = Date.now(); let closest = ts[0]; let minDiff = Math.abs(new Date(ts[0].validTime).getTime() - now); for (const entry of ts.slice(1, 10)) { const diff = Math.abs(new Date(entry.validTime).getTime() - now); if (diff < minDiff) { closest = entry; minDiff = diff; } } const p = closest.parameters; const temp = getParam(p, "t"); const wind = getParam(p, "ws"); const gust = getParam(p, "gust"); const windDir = getParam(p, "wd"); const humidity = getParam(p, "r"); const pressure = getParam(p, "msl"); const cloud = getParam(p, "tcc_mean"); const wsymb = getParam(p, "Wsymb2"); const precip = getParam(p, "pmean"); const lines = [ `## ${loc.name} — Current Weather`, `**Conditions:** ${WSYMB2[wsymb] || `Code ${wsymb}`}`, `**Temperature:** ${temp}°C`, `**Humidity:** ${humidity}%`, `**Wind:** ${wind} m/s from ${windDir}° (gusts ${gust} m/s)`, `**Pressure:** ${pressure} hPa`, `**Cloud cover:** ${cloud != null ? Math.round(cloud * 12.5) + "%" : "N/A"}`, precip != null ? `**Precipitation:** ${precip} mm/h` : null, `\n*SMHI — ${closest.validTime}*`, ].filter(Boolean); return { content: [{ type: "text", text: lines.join("\n") }] }; } catch (err) { return { content: [{ type: "text", text: `Error: ${err.message}` }], isError: true }; } - src/servers/swedish-weather.js:107-112 (registration)The registration of the 'se_current_weather' tool along with its schema and description.
server.tool( "se_current_weather", "Get current weather for a location in Sweden using SMHI (Swedish Meteorological and Hydrological Institute). Includes temperature, wind, precipitation, humidity.", { location: z.string().describe("Swedish city name (e.g. 'Stockholm', 'Malmö', 'Gothenburg', 'Kiruna') or lat,lon coordinates"), },