Skip to main content
Glama
robobobby

mcp-norwegian-weather

by robobobby

current_weather

Get current weather conditions for any location in Norway, including cities and coordinates, using MET Norway data.

Instructions

Get current weather for a location in Norway using MET Norway (yr.no).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
locationYesNorwegian city name or lat,lon coordinates

Implementation Reference

  • src/index.js:108-136 (registration)
    Tool registration: The current_weather tool is registered with the MCP server using server.tool() with its name, description, input schema, and handler function.
    server.tool(
      "current_weather",
      "Get current weather for a location in Norway using MET Norway (yr.no).",
      { location: z.string().describe("Norwegian city name or lat,lon coordinates") },
      async ({ location }) => {
        try {
          const loc = await getLocation(location);
          const data = await fetchForecast(loc.lat, loc.lon);
          const now = data.properties.timeseries[0];
          const inst = now.data.instant.details;
          const symbol = now.data.next_1_hours?.summary?.symbol_code || now.data.next_6_hours?.summary?.symbol_code || "";
          const precip1h = now.data.next_1_hours?.details?.precipitation_amount;
          const lines = [
            `## ${loc.name} — Current Weather`,
            `**Conditions:** ${symbolToText(symbol)}`,
            `**Temperature:** ${inst.air_temperature}°C`,
            `**Humidity:** ${inst.relative_humidity}%`,
            `**Wind:** ${inst.wind_speed} m/s from ${inst.wind_from_direction}° (gusts ${inst.wind_speed_of_gust ?? "N/A"} m/s)`,
            `**Pressure:** ${inst.air_pressure_at_sea_level} hPa`,
            `**Cloud cover:** ${inst.cloud_area_fraction}%`,
            precip1h != null ? `**Precipitation (next hour):** ${precip1h} mm` : null,
            `\n*MET Norway Locationforecast 2.0 — ${now.time}*`,
          ].filter(Boolean);
          return { content: [{ type: "text", text: lines.join("\n") }] };
        } catch (err) {
          return { content: [{ type: "text", text: `Error: ${err.message}` }], isError: true };
        }
      }
    );
  • Tool handler implementation: The async function that executes the tool logic - resolves location, fetches forecast from MET Norway API, extracts current weather data, and formats it into a readable markdown response.
    async ({ location }) => {
      try {
        const loc = await getLocation(location);
        const data = await fetchForecast(loc.lat, loc.lon);
        const now = data.properties.timeseries[0];
        const inst = now.data.instant.details;
        const symbol = now.data.next_1_hours?.summary?.symbol_code || now.data.next_6_hours?.summary?.symbol_code || "";
        const precip1h = now.data.next_1_hours?.details?.precipitation_amount;
        const lines = [
          `## ${loc.name} — Current Weather`,
          `**Conditions:** ${symbolToText(symbol)}`,
          `**Temperature:** ${inst.air_temperature}°C`,
          `**Humidity:** ${inst.relative_humidity}%`,
          `**Wind:** ${inst.wind_speed} m/s from ${inst.wind_from_direction}° (gusts ${inst.wind_speed_of_gust ?? "N/A"} m/s)`,
          `**Pressure:** ${inst.air_pressure_at_sea_level} hPa`,
          `**Cloud cover:** ${inst.cloud_area_fraction}%`,
          precip1h != null ? `**Precipitation (next hour):** ${precip1h} mm` : null,
          `\n*MET Norway Locationforecast 2.0 — ${now.time}*`,
        ].filter(Boolean);
        return { content: [{ type: "text", text: lines.join("\n") }] };
      } catch (err) {
        return { content: [{ type: "text", text: `Error: ${err.message}` }], isError: true };
      }
    }
  • Input schema: Zod schema defining the location parameter as a required string describing Norwegian city name or lat,lon coordinates.
    { location: z.string().describe("Norwegian city name or lat,lon coordinates") },
  • Helper function getLocation: Resolves user input to a location by checking known Norwegian cities or using geocoding API, throws error if location not found.
    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 Norway. Try a city name or lat,lon coordinates.`);
    }
  • Helper function fetchForecast: Fetches weather forecast data from MET Norway Locationforecast 2.0 API for given latitude and longitude.
    async function fetchForecast(lat, lon) {
      const url = `${BASE_URL}/complete?lat=${lat.toFixed(4)}&lon=${lon.toFixed(4)}`;
      const res = await fetch(url, { headers: { "User-Agent": USER_AGENT } });
      if (!res.ok) throw new Error(`MET Norway API error (${res.status}): ${await res.text()}`);
      return res.json();
    }
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-norwegian-weather'

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