Skip to main content
Glama
robertn702

OpenWeatherMap MCP Server

get-onecall-weather

Retrieve current weather and 7-day forecast data by providing latitude, longitude, and unit preferences. Exclude specific data types to customize the response.

Instructions

Get comprehensive weather data (current + 7-day forecast)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
excludeNoParts of weather data to exclude from the response
latitudeYesLatitude coordinate
longitudeYesLongitude coordinate
unitsNoTemperature units: metric (Celsius), imperial (Fahrenheit), or standard (Kelvin)

Implementation Reference

  • The complete handler and registration for the 'get-onecall-weather' tool. It uses coordinates to fetch comprehensive OneCall weather data (current, minutely, hourly, daily forecasts, and alerts) via the OpenWeather client, formats it into a structured JSON response.
    server.addTool({
      name: "get-onecall-weather",
      description: "Get comprehensive weather data (current + 7-day forecast)",
      parameters: getOneCallWeatherSchema,
      execute: async (args, { session, log }) => {
        try {
          log.info("Getting OneCall weather data", { 
            latitude: args.latitude,
            longitude: args.longitude 
          });
          
          // Get OpenWeather client
          const client = getOpenWeatherClient(session as SessionData | undefined);
          
          // Set coordinates for OneCall API
          client.setLocationByCoordinates(args.latitude, args.longitude);
          
          // Set units if provided
          if (args.units) {
            client.setUnits(args.units);
          }
          
          // Fetch comprehensive weather data
          const weatherData = await client.getEverything();
          
          log.info("Successfully retrieved OneCall weather data", { 
            latitude: args.latitude,
            longitude: args.longitude,
            has_current: !!weatherData.current,
            daily_count: weatherData.daily?.length || 0,
            hourly_count: weatherData.hourly?.length || 0
          });
          
          // Format the comprehensive response
          const formattedData = {
            location: {
              latitude: args.latitude,
              longitude: args.longitude,
              timezone: weatherData.timezone,
              timezone_offset: weatherData.timezoneOffset
            },
            current: weatherData.current ? {
              datetime: weatherData.current.dt.toISOString(),
              temperature: weatherData.current.weather.temp.cur,
              feels_like: weatherData.current.weather.feelsLike.cur,
              pressure: weatherData.current.weather.pressure,
              humidity: weatherData.current.weather.humidity,
              dew_point: weatherData.current.weather.dewPoint,
              uv_index: weatherData.current.weather.uvi,
              clouds: weatherData.current.weather.clouds,
              visibility: weatherData.current.weather.visibility,
              wind: {
                speed: weatherData.current.weather.wind.speed,
                direction: weatherData.current.weather.wind.deg,
                gust: weatherData.current.weather.wind.gust
              },
              weather: {
                main: weatherData.current.weather.main,
                description: weatherData.current.weather.description,
                icon: weatherData.current.weather.icon
              },
              rain: weatherData.current.weather.rain,
              snow: weatherData.current.weather.snow
            } : null,
            minutely: weatherData.minutely?.slice(0, 60).map((minute, index) => ({
              minute_offset: index + 1,
              time: minute.dt.toISOString(),
              precipitation: minute.weather.rain
            })) || [],
            hourly: weatherData.hourly?.slice(0, 48).map(hour => ({
              datetime: hour.dt.toISOString(),
              temperature: hour.weather.temp.cur,
              feels_like: hour.weather.feelsLike.cur,
              pressure: hour.weather.pressure,
              humidity: hour.weather.humidity,
              dew_point: hour.weather.dewPoint,
              uv_index: hour.weather.uvi,
              clouds: hour.weather.clouds,
              visibility: hour.weather.visibility,
              wind: {
                speed: hour.weather.wind.speed,
                direction: hour.weather.wind.deg,
                gust: hour.weather.wind.gust
              },
              weather: {
                main: hour.weather.main,
                description: hour.weather.description,
                icon: hour.weather.icon
              },
              precipitation_probability: hour.weather.pop,
              rain: hour.weather.rain,
              snow: hour.weather.snow
            })) || [],
            daily: weatherData.daily?.slice(0, 7).map(day => ({
              date: day.dt.toISOString().split('T')[0],
              temperature: {
                min: day.weather.temp.min,
                max: day.weather.temp.max,
                morning: day.weather.temp.morn,
                day: day.weather.temp.day,
                evening: day.weather.temp.eve,
                night: day.weather.temp.night
              },
              feels_like: {
                morning: day.weather.feelsLike.morn,
                day: day.weather.feelsLike.day,
                evening: day.weather.feelsLike.eve,
                night: day.weather.feelsLike.night
              },
              pressure: day.weather.pressure,
              humidity: day.weather.humidity,
              dew_point: day.weather.dewPoint,
              wind: {
                speed: day.weather.wind.speed,
                direction: day.weather.wind.deg,
                gust: day.weather.wind.gust
              },
              weather: {
                main: day.weather.main,
                description: day.weather.description,
                icon: day.weather.icon
              },
              clouds: day.weather.clouds,
              precipitation_probability: day.weather.pop,
              rain: day.weather.rain,
              snow: day.weather.snow,
              uv_index: day.weather.uvi,
              moon_phase: day.astronomical.moonPhase,
              sunrise: day.astronomical.sunrise.toISOString(),
              sunset: day.astronomical.sunset.toISOString()
            })) || [],
            alerts: weatherData.alerts?.map(alert => ({
              sender: alert.sender_name,
              event: alert.event,
              start_time: new Date(alert.start * 1000).toISOString(),
              end_time: new Date(alert.end * 1000).toISOString(),
              description: alert.description,
              tags: alert.tags
            })) || []
          };
          
          return {
            content: [
              {
                type: "text",
                text: JSON.stringify(formattedData, null, 2)
              }
            ]
          };
        } catch (error) {
          log.error("Failed to get OneCall weather", { 
            error: error instanceof Error ? error.message : 'Unknown error' 
          });
          
          // Provide helpful error messages
          if (error instanceof Error) {
            if (error.message.includes('Invalid coordinates')) {
              throw new Error(`Invalid coordinates: latitude must be between -90 and 90, longitude must be between -180 and 180.`);
            }
            if (error.message.includes('Invalid API key')) {
              throw new Error('Invalid OpenWeatherMap API key. Please check your configuration.');
            }
          }
          
          throw new Error(`Failed to get OneCall weather: ${error instanceof Error ? error.message : 'Unknown error'}`);
        }
      }
    });
  • Zod schema defining the input parameters for the get-onecall-weather tool: required latitude and longitude, optional units and exclude options.
    export const getOneCallWeatherSchema = z.object({
      latitude: z.number().min(-90).max(90).describe("Latitude coordinate"),
      longitude: z.number().min(-180).max(180).describe("Longitude coordinate"),
      units: unitsSchema,
      exclude: oneCallExcludeSchema,
    });
  • src/main.ts:700-703 (registration)
    Registration of the 'get-onecall-weather' tool using FastMCP server.addTool, specifying name, description, input schema, and execute handler.
    server.addTool({
      name: "get-onecall-weather",
      description: "Get comprehensive weather data (current + 7-day forecast)",
      parameters: getOneCallWeatherSchema,
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 mentions 'comprehensive weather data' but doesn't describe what that includes beyond 'current + 7-day forecast', nor does it mention rate limits, authentication needs, error conditions, or response format. For a weather API tool with no annotation coverage, this is inadequate.

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 core purpose without waste. It's appropriately sized and front-loaded with the essential information.

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

Completeness2/5

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

For a weather data tool with 4 parameters, no annotations, and no output schema, the description is insufficient. It doesn't explain what 'comprehensive' means beyond mentioning current and 7-day forecast, nor does it help the agent understand when to choose this tool over its many specialized siblings. The description should provide more context about the tool's scope and differentiation.

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 all 4 parameters. The description adds no parameter information beyond what's in the schema. The baseline score of 3 is appropriate when the schema does all the heavy lifting for parameter documentation.

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 tool's purpose: 'Get comprehensive weather data (current + 7-day forecast)'. It specifies both the verb ('Get') and the resource ('weather data') with scope details. However, it doesn't explicitly distinguish this comprehensive tool from its many siblings that provide specific weather components (current, hourly, daily, etc.), which would require a 5.

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?

The description provides no guidance on when to use this tool versus its many siblings. With tools like get-current-weather, get-daily-forecast, get-hourly-forecast, and get-weather-forecast available, the agent receives no help in choosing between comprehensive data (this tool) versus specific components (siblings).

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