Skip to main content
Glama

weather-get_daily

Retrieve daily weather forecasts for any location, with options for 1 to 15 days ahead and temperature units in Celsius or Fahrenheit.

Instructions

Get daily weather forecast for up to 15 days

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
locationYesThe city or location for which to retrieve the weather forecast.
daysNoNumber of days to forecast (1, 5, 10, or 15). Default is 5.
unitsNoTemperature unit system (metric for Celsius, imperial for Fahrenheit). Default is metric.

Implementation Reference

  • Main handler function for 'weather-get_daily' tool. Validates input with Zod, fetches location key and daily forecast from AccuWeather API, handles errors, and formats forecast data into text content array.
    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, days = 5, 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;
    
        // Get valid forecast period (AccuWeather supports 1, 5, 10, or 15 days)
        let forecastDays = 5; // default
        if (days === 1) forecastDays = 1;
        else if (days <= 5) forecastDays = 5;
        else if (days <= 10) forecastDays = 10;
        else forecastDays = 15;
    
        // Step 2: Get forecast with location key
        const forecastUrl = `https://dataservice.accuweather.com/forecasts/v1/daily/${forecastDays}day/${locationKey}?apikey=${apiKey}&metric=${units === "metric" ? "true" : "false"}`;
        const forecastResp = await axios.get(forecastUrl);
        const data = forecastResp.data;
    
        if (!data || !data.DailyForecasts || !Array.isArray(data.DailyForecasts) || data.DailyForecasts.length === 0) {
          return {
            content: [{ type: 'text', text: `No daily forecast data available for location: ${location}` }]
          };
        }
    
        const degreeSymbol = "°";
        const unitSymbol = units === "metric" ? "C" : "F";
    
        const content: TextContent[] = data.DailyForecasts.map((day: any) => {
          const date = new Date(day.Date);
          const formattedDate = date.toLocaleDateString('en-US', { 
            weekday: 'long', 
            year: 'numeric', 
            month: 'short', 
            day: 'numeric' 
          });
          
          return {
            type: 'text',
            text: `${formattedDate}: ${day.Temperature.Minimum.Value}${degreeSymbol}${unitSymbol} to ${day.Temperature.Maximum.Value}${degreeSymbol}${unitSymbol}, Day: ${day.Day.IconPhrase}, Night: ${day.Night.IconPhrase}${day.Day.HasPrecipitation || day.Night.HasPrecipitation ? ' (Precipitation expected)' : ''}`
          };
        });
    
        return { content };
      } catch (error) {
        console.error("WeatherDailyTool 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 }] };
      }
    }
  • JSON schema definition for the tool's input parameters, used for registration and validation.
    export const inputJsonSchema = {
      type: "object",
      description: "Parameters for the daily weather-forecast tool",
      properties: {
        location: {
          type: "string",
          description: "The location to fetch the daily forecast for",
        },
        days: {
          type: "number",
          description: "Number of days to forecast (1, 5, 10, or 15). Default is 5.",
          enum: [1, 5, 10, 15]
        },
        units: {
          type: "string",
          description: "Temperature unit system (metric for Celsius, imperial for Fahrenheit). Default is metric.",
          enum: ["metric", "imperial"]
        }
      },
      required: ["location"],
      additionalProperties: false,
    };
  • Zod schema for runtime input validation within the handler.
    export const inputShape = {
      location: z.string().min(1, "Location must be at least 1 character"),
      days: z.number().int().min(1).max(15).default(5).optional().describe("Number of days for forecast (1-15)"),
      units: z.enum(["imperial", "metric"]).default("metric").optional().describe("Temperature unit system")
    };
    
    export const inputSchema = z.object(inputShape).describe("Get daily weather forecast");
  • src/index.ts:31-54 (registration)
    Tool definition object including name, description, and input schema, used for registration.
    const dailyWeatherTool: Tool = {
      name: "weather-get_daily",
      description: "Get daily weather forecast for up to 15 days",
      inputSchema: {
        type: "object",
        properties: {
          location: {
            type: "string",
            description: "The city or location for which to retrieve the weather forecast."
          },
          days: {
            type: "number",
            description: "Number of days to forecast (1, 5, 10, or 15). Default is 5.",
            enum: [1, 5, 10, 15]
          },
          units: {
            type: "string",
            description: "Temperature unit system (metric for Celsius, imperial for Fahrenheit). Default is metric.",
            enum: ["metric", "imperial"]
          }
        },
        required: ["location"]
      }
    };
  • src/index.ts:83-86 (registration)
    Dispatch logic in CallToolRequestSchema handler that routes to the dailyHandler when tool name matches.
    if (request.params.name === "weather-get_hourly") {
      return await hourlyHandler(args, {} as RequestHandlerExtra<any, any>);
    } else if (request.params.name === "weather-get_daily") {
      return await dailyHandler(args, {} as RequestHandlerExtra<any, any>);

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

A3.8/5.0
Behavior3/5

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

There are no annotations, so the description carries the behavioral transparency burden. It communicates a read-only forecast lookup via 'Get' and adds the 15-day maximum, but it does not disclose response shape, potential errors, timezone behavior, or whether any authentication is needed. For a simple read operation this is acceptable but not thorough.

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 sentence with no wasted words. It front-loads the verb and resource and immediately gives the key constraint of 15 days.

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 simple weather lookup with three fully documented parameters, the description is largely complete and an agent can invoke the tool correctly. The only notable gap is that there is no output schema and the description does not hint at the shape of the returned forecast payload.

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%: location, days, and units are all clearly documented in the input schema. The description adds no additional parameter meaning, which is acceptable because the structured schema already handles the documentation fully.

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 explicitly states the action ('Get'), the resource ('daily weather forecast'), and the scope ('up to 15 days'). This clearly distinguishes it from the sibling tool weather-get_hourly without requiring any additional inference.

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 word 'daily' and the tool name imply that this is for day-level forecasts rather than hourly ones, which is useful context. However, the description does not explicitly state when to use this tool versus weather-get_hourly or provide any exclusion criteria.

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

Deploy Server

Other Tools