Skip to main content
Glama

weather-get_hourly

Retrieve hourly weather forecasts for the next 12 hours to plan activities and prepare for changing conditions. Specify location and temperature units (metric/imperial) for accurate predictions.

Instructions

Get hourly weather forecast for the next 12 hours

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
locationYesThe city or location for which to retrieve the weather forecast.
unitsNoTemperature unit system (metric for Celsius, imperial for Fahrenheit). Default is metric.

Implementation Reference

  • Core execution logic for the 'weather-get_hourly' tool: validates inputs, queries AccuWeather API for location and hourly forecast, formats output, handles errors.
    export async function handler(
      args: { [x: string]: any },
      extra: RequestHandlerExtra<any, any>
    ): Promise<{ content: TextContent[] }> {
      // Validate args using the Zod schema
      let validatedArgs: z.infer<typeof inputSchema>;
      try {
        validatedArgs = inputSchema.parse(args);
      } catch (error) {
        if (error instanceof z.ZodError) {
          const errorMessages = error.errors
            .map((e) => `${e.path.join('.')}: ${e.message}`)
            .join(', ');
          return { content: [{ type: 'text', text: `Invalid input: ${errorMessages}` }] };
        }
        return { content: [{ type: 'text', text: 'An unexpected error occurred during input validation.' }] };
      }
    
      const { location, units = "metric" } = validatedArgs;
      const apiKey = process.env.ACCUWEATHER_API_KEY;
      if (!apiKey) {
        return { content: [{ type: 'text', text: 'Error: AccuWeather API key not configured' }] };
      }
    
      try {
        // Step 1: Get location key
        const locationUrl = `https://dataservice.accuweather.com/locations/v1/cities/search?apikey=${apiKey}&q=${encodeURIComponent(location)}`;
        const locationResp = await axios.get(locationUrl);
    
        if (!locationResp.data || locationResp.data.length === 0) {
          return { content: [{ type: 'text', text: `No location found for: ${location}` }] };
        }
    
        const locationKey = locationResp.data[0].Key;
    
        // Step 2: Get forecast with location key
        const forecastUrl = `https://dataservice.accuweather.com/forecasts/v1/hourly/12hour/${locationKey}?apikey=${apiKey}&metric=${units === "metric" ? "true" : "false"}`;
        const forecastResp = await axios.get(forecastUrl);
        const data = forecastResp.data;
    
        if (!data || !Array.isArray(data) || data.length === 0) {
          return {
            content: [{ type: 'text', text: `No weather data available for location: ${location}` }]
          };
        }
    
        const unitSymbol = units === "metric" ? "C" : "F";
        const content: TextContent[] = data.map((hour: any) => ({
          type: 'text',
          text: `${hour.DateTime}: ${hour.Temperature.Value}°${unitSymbol}, ${hour.IconPhrase}`,
        }));
    
        return { content };
      } catch (error) {
        console.error("WeatherTool handler error:", error);
        let errorMessage = "An error occurred while fetching weather data.";
    
        if (axios.isAxiosError(error)) {
          if (error.response?.status === 401) {
            errorMessage = "Invalid AccuWeather API key. Please check your credentials.";
          } else if (error.response?.status === 404) {
            errorMessage = `Location not found: ${location}`;
          } else if (error.response) {
            errorMessage = `AccuWeather API error (${error.response.status}): ${error.response.data?.Message || error.message}`;
          } else if (error.request) {
            errorMessage = "Network error: Unable to connect to AccuWeather API.";
          }
        }
    
        return { content: [{ type: 'text', text: errorMessage }] };
      }
    }
  • src/index.ts:10-28 (registration)
    Defines the Tool metadata for 'weather-get_hourly', including name, description, and input schema.
    const hourlyWeatherTool: Tool = {
      name: "weather-get_hourly",
      description: "Get hourly weather forecast for the next 12 hours",
      inputSchema: {
        type: "object",
        properties: {
          location: {
            type: "string",
            description: "The city or location for which to retrieve the weather forecast."
          },
          units: {
            type: "string",
            description: "Temperature unit system (metric for Celsius, imperial for Fahrenheit). Default is metric.",
            enum: ["metric", "imperial"]
          }
        },
        required: ["location"]
      }
    };
  • src/index.ts:69-71 (registration)
    Registers the available tools, including 'weather-get_hourly', in response to ListTools requests.
    server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools: [hourlyWeatherTool, dailyWeatherTool],
    }));
  • src/index.ts:83-85 (registration)
    Dispatches CallTool requests to the appropriate handler based on tool name 'weather-get_hourly'.
    if (request.params.name === "weather-get_hourly") {
      return await hourlyHandler(args, {} as RequestHandlerExtra<any, any>);
    } else if (request.params.name === "weather-get_daily") {
  • Zod schema for input validation used within the handler.
    export const inputShape = {
      location: z.string().min(1, "Location must be at least 1 character"),
      units: z.enum(["imperial", "metric"]).default("metric").optional().describe("Temperature unit system")
    };
    
    export const inputSchema = z.object(inputShape).describe("Get hourly weather forecast");
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It states the tool's function but omits critical behavioral details such as rate limits, authentication requirements, error handling, or response format (e.g., JSON structure, timestamps). For a tool with no annotations, this leaves significant gaps in understanding how it behaves operationally.

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 without unnecessary words. Every part ('Get hourly weather forecast for the next 12 hours') contributes directly to understanding the tool's function, making it highly concise and well-structured for quick comprehension.

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 low complexity (2 parameters, no output schema, no annotations), the description covers the basic purpose adequately. However, it lacks details on behavioral aspects (e.g., rate limits, auth) and output format, which are important for a tool with no annotations. It's minimally viable but has clear gaps in providing a complete operational context.

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 schema description coverage is 100%, with both parameters ('location' and 'units') well-documented in the schema. The description adds no additional parameter semantics beyond what the schema provides (e.g., it doesn't clarify location formats or unit defaults further). Baseline score of 3 is appropriate as the schema handles parameter documentation adequately.

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 hourly weather forecast') and resource ('weather'), with precise temporal scope ('for the next 12 hours'). It distinguishes from the sibling tool 'weather-get_daily' by specifying hourly vs daily forecasts, making the purpose unambiguous and differentiated.

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

Usage Guidelines3/5

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

The description implies usage context through 'hourly' and 'next 12 hours', suggesting it's for short-term forecasts. However, it lacks explicit guidance on when to use this tool versus the sibling 'weather-get_daily' (e.g., for daily vs hourly needs) or any prerequisites/exclusions, leaving usage decisions partially inferred rather than clearly stated.

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/TimLukaHorstmann/mcp-weather'

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