Skip to main content
Glama
robobobby

mcp-swedish-weather

by robobobby

weather_forecast

Get hourly weather forecasts for Swedish locations using SMHI data. Specify a city or coordinates to receive detailed meteorological predictions for up to 72 hours ahead.

Instructions

Get hourly weather forecast for a location in Sweden using SMHI.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
locationYesSwedish city name or lat,lon coordinates
hoursNoHours ahead (default 24, max 72)

Implementation Reference

  • Main handler function for weather_forecast tool that processes location and hours parameters, fetches forecast data from SMHI API, formats hourly forecast entries with temperature, conditions, wind, and precipitation data
    async ({ location, hours }) => {
      try {
        const loc = await getLocation(location);
        const data = await fetchForecast(loc.lat, loc.lon);
        const maxHours = hours || 24;
        const now = Date.now();
        const cutoff = now + maxHours * 3600000;
        const lines = [`## ${loc.name} — ${maxHours}h Forecast\n`];
        for (const entry of data.timeSeries) {
          const t = new Date(entry.validTime);
          if (t.getTime() > cutoff) break;
          if (t.getTime() < now - 3600000) continue;
          const time = t.toLocaleString("sv-SE", { timeZone: "Europe/Stockholm", weekday: "short", day: "numeric", month: "short", hour: "2-digit", minute: "2-digit" });
          const p = entry.parameters;
          const precip = getParam(p, "pmean");
          lines.push(`**${time}:** ${getParam(p, "t")}°C, ${WSYMB2[getParam(p, "Wsymb2")] || ""}, wind ${getParam(p, "ws")} m/s${precip > 0 ? `, ${precip} mm/h` : ""}`);
        }
        lines.push(`\n*SMHI Open Data*`);
        return { content: [{ type: "text", text: lines.join("\n") }] };
      } catch (err) {
        return { content: [{ type: "text", text: `Error: ${err.message}` }], isError: true };
      }
    }
  • src/index.js:141-171 (registration)
    Tool registration with MCP server defining the weather_forecast tool name, description, input schema with location string and optional hours number, and the handler function
    server.tool(
      "weather_forecast",
      "Get hourly weather forecast for a location in Sweden using SMHI.",
      {
        location: z.string().describe("Swedish city name or lat,lon coordinates"),
        hours: z.number().min(1).max(72).optional().describe("Hours ahead (default 24, max 72)"),
      },
      async ({ location, hours }) => {
        try {
          const loc = await getLocation(location);
          const data = await fetchForecast(loc.lat, loc.lon);
          const maxHours = hours || 24;
          const now = Date.now();
          const cutoff = now + maxHours * 3600000;
          const lines = [`## ${loc.name} — ${maxHours}h Forecast\n`];
          for (const entry of data.timeSeries) {
            const t = new Date(entry.validTime);
            if (t.getTime() > cutoff) break;
            if (t.getTime() < now - 3600000) continue;
            const time = t.toLocaleString("sv-SE", { timeZone: "Europe/Stockholm", weekday: "short", day: "numeric", month: "short", hour: "2-digit", minute: "2-digit" });
            const p = entry.parameters;
            const precip = getParam(p, "pmean");
            lines.push(`**${time}:** ${getParam(p, "t")}°C, ${WSYMB2[getParam(p, "Wsymb2")] || ""}, wind ${getParam(p, "ws")} m/s${precip > 0 ? `, ${precip} mm/h` : ""}`);
          }
          lines.push(`\n*SMHI Open Data*`);
          return { content: [{ type: "text", text: lines.join("\n") }] };
        } catch (err) {
          return { content: [{ type: "text", text: `Error: ${err.message}` }], isError: true };
        }
      }
    );
  • Input validation schema using zod for weather_forecast tool parameters, defining location as required string and hours as optional number between 1-72
    {
      location: z.string().describe("Swedish city name or lat,lon coordinates"),
      hours: z.number().min(1).max(72).optional().describe("Hours ahead (default 24, max 72)"),
    },
  • Helper function that fetches weather forecast data from SMHI API for given latitude and longitude coordinates, returning JSON data
    async function fetchForecast(lat, lon) {
      const url = `${BASE_URL}/lon/${lon.toFixed(6)}/lat/${lat.toFixed(6)}/data.json`;
      const res = await fetch(url, { headers: { "User-Agent": USER_AGENT } });
      if (!res.ok) throw new Error(`SMHI API error (${res.status}): ${await res.text()}`);
      return res.json();
    }
  • Helper function that resolves location input by first checking against known Swedish cities, then geocoding if needed, throwing error if location cannot be found in Sweden
    async function getLocation(input) {
      const loc = resolveLocation(input);
      if (loc) return loc;
      const geo = await geocode(input);
      if (geo) return geo;
      throw new Error(`Could not find location "${input}" in Sweden. Try a city name or lat,lon coordinates.`);
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It specifies the data source (SMHI) and geographic limitation (Sweden), which adds useful context. However, it doesn't mention rate limits, authentication requirements, error conditions, or what the response format looks like.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that communicates the essential information with zero wasted words. It's appropriately sized for a simple tool with good schema documentation and gets straight to the point.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a relatively simple weather forecast tool with 2 parameters and 100% schema coverage, the description provides adequate context about scope and data source. However, with no output schema and no annotations, it could benefit from mentioning what the forecast data includes (temperature, precipitation, etc.) or the response format.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already fully documents both parameters. The description doesn't add any parameter-specific information beyond what's in the schema descriptions. The baseline score of 3 is appropriate when the schema does all the parameter documentation work.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Get'), resource ('hourly weather forecast'), and scope ('for a location in Sweden using SMHI'). It distinguishes from the sibling tool 'current_weather' by specifying it provides forecast data rather than current conditions.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context about when to use this tool (for hourly forecasts in Sweden via SMHI), but doesn't explicitly state when NOT to use it or mention alternatives beyond the implied sibling tool. The geographic and data source constraints are helpful guidance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/robobobby/mcp-swedish-weather'

If you have feedback or need assistance with the MCP directory API, please join our Discord server