Skip to main content
Glama
robertn702

OpenWeatherMap MCP Server

get-hourly-forecast

Retrieve hourly weather forecasts for up to 48 hours using city names or coordinates. Specify units (Celsius, Fahrenheit, Kelvin) and desired forecast duration for precise planning.

Instructions

Get hourly weather forecast for up to 48 hours

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
hoursNoNumber of hours to forecast (1-48, default: 48)
locationYesCity name (e.g., 'New York') or coordinates (e.g., 'lat,lon')
unitsNoTemperature units: metric (Celsius), imperial (Fahrenheit), or standard (Kelvin)

Implementation Reference

  • Primary handler and registration: defines the tool with name, description, input schema, and execute function that orchestrates client resolution, location config, API call to getHourlyForecast, formatting, and error handling.
    server.addTool({
      name: "get-hourly-forecast",
      description: "Get hourly weather forecast for up to 48 hours",
      parameters: getHourlyForecastSchema,
      execute: async (args, { session, log }) => {
        try {
          log.info("Getting hourly weather forecast", { 
            location: args.location,
            hours: args.hours 
          });
          
          // Get OpenWeather client
          const client = getOpenWeatherClient(session as SessionData | undefined);
          
          // Configure client for this request
          configureClientForLocation(client, args.location, args.units);
          
          // Fetch hourly forecast data
          const requestedHours = args.hours || 48;
          const hourlyData = await client.getHourlyForecast(requestedHours);
          
          log.info("Successfully retrieved hourly weather forecast", { 
            location: args.location,
            entries: hourlyData.length
          });
          
          // Format the response
          const formattedForecast = formatHourlyForecast(
            hourlyData, 
            `${hourlyData[0]?.lat?.toFixed(4)}, ${hourlyData[0]?.lon?.toFixed(4)}` || args.location,
            args.units
          );
          
          return {
            content: [
              {
                type: "text",
                text: formattedForecast
              }
            ]
          };
        } catch (error) {
          log.error("Failed to get hourly weather forecast", { 
            error: error instanceof Error ? error.message : 'Unknown error' 
          });
          
          // Provide helpful error messages
          if (error instanceof Error) {
            if (error.message.includes('city not found')) {
              throw new Error(`Location "${args.location}" not found. Please check the spelling or try using coordinates.`);
            }
            if (error.message.includes('Invalid API key')) {
              throw new Error('Invalid OpenWeatherMap API key. Please check your configuration.');
            }
          }
          
          throw new Error(`Failed to get hourly weather forecast: ${error instanceof Error ? error.message : 'Unknown error'}`);
        }
      }
    });
  • Input schema using Zod: requires location string, optional units (metric/imperial/standard), optional hours (1-48).
    export const getHourlyForecastSchema = z.object({
      location: z.string().describe("City name (e.g., 'New York') or coordinates (e.g., 'lat,lon')"),
      units: unitsSchema,
      hours: z.number().min(1).max(48).optional().describe("Number of hours to forecast (1-48, default: 48)"),
    });
  • Supporting helper: formats raw hourly forecast data into a structured JSON object with formatted temperature, wind, visibility, etc., for the tool response.
    export function formatHourlyForecast(hourlyData: any[], location: string, units: Units = "metric"): string {
      const forecastData = {
        location,
        hourly_forecast: hourlyData.map((hour, index) => ({
          hour: index + 1,
          datetime: formatDateTime(hour.dtRaw || hour.dt),
          temperature: {
            current: Math.round(hour.weather?.temp?.cur || hour.temp),
            feels_like: Math.round(hour.weather?.feelsLike?.cur || hour.feels_like),
            units: getTemperatureUnit(units)
          },
          conditions: hour.weather?.description || hour.description,
          humidity: hour.weather?.humidity || hour.humidity,
          wind: {
            speed: Number((hour.weather?.wind?.speed || hour.wind_speed || 0).toFixed(1)),
            direction: getWindDirection(hour.weather?.wind?.deg || hour.wind_deg || 0),
            units: units === "imperial" ? "mph" : "m/s"
          },
          pressure: hour.weather?.pressure || hour.pressure,
          visibility: (hour.weather?.visibility || hour.visibility) ? {
            value: units === "imperial" ? Number(((hour.weather?.visibility || hour.visibility) / 1609.34).toFixed(1)) : Number(((hour.weather?.visibility || hour.visibility) / 1000).toFixed(1)),
            units: units === "imperial" ? "mi" : "km"
          } : null,
          uvi: hour.weather?.uvi,
          clouds: hour.weather?.clouds,
          pop: hour.weather?.pop ? Math.round(hour.weather.pop * 100) : null,
          timestamp: hour.dtRaw || hour.dt
        }))
      };
      
      return JSON.stringify(forecastData);
    }
Behavior2/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 mentions the 48-hour limit, which is useful, but doesn't cover other important aspects like rate limits, authentication needs, error handling, or what the output format looks like (e.g., JSON structure, timestamps). For a tool with no annotations, this leaves significant gaps in understanding how it behaves.

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 front-loads the core purpose ('Get hourly weather forecast') and includes the key constraint ('for up to 48 hours'). There is no wasted text, and it's appropriately sized for the tool's complexity.

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

Completeness3/5

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

Given the tool's moderate complexity (3 parameters, no output schema, no annotations), the description is minimally adequate. It covers the basic purpose and scope but lacks details on usage guidelines, behavioral traits, and output format. With no output schema, the description should ideally hint at what data is returned, but it doesn't, leaving the agent uncertain about the response structure.

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?

The input schema has 100% description coverage, with clear documentation for all three parameters (hours, location, units). The description adds no additional parameter information beyond what's in the schema, so it meets the baseline of 3 where the schema does the heavy lifting. However, it doesn't compensate for any gaps since there are none.

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

Purpose4/5

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

The description clearly states the action ('Get') and resource ('hourly weather forecast') with a specific scope ('for up to 48 hours'). It distinguishes from siblings like 'get-daily-forecast' by specifying 'hourly' but doesn't explicitly differentiate from 'get-minutely-forecast' or 'get-weather-forecast' which might overlap.

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

Usage Guidelines2/5

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

No guidance is provided on when to use this tool versus alternatives like 'get-daily-forecast' or 'get-current-weather'. The description mentions the 48-hour limit but doesn't explain if this is the best tool for short-term vs. long-term forecasts or how it relates to other forecast tools in the sibling list.

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

Related 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/robertn702/mcp-openweathermap'

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