Skip to main content
Glama
robertn702

OpenWeatherMap MCP Server

get-weather-alerts

Retrieve active weather alerts and warnings for a specified location using OpenWeatherMap MCP Server. Provide city name or coordinates to access real-time weather updates and stay informed about potential hazards.

Instructions

Get active weather alerts and warnings

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
locationYesCity name (e.g., 'New York') or coordinates (e.g., 'lat,lon')

Implementation Reference

  • src/main.ts:450-516 (registration)
    Registration of the 'get-weather-alerts' tool using server.addTool, including inline handler (execute function) that fetches alerts using OpenWeather client, formats as JSON, and handles errors.
    server.addTool({
      name: "get-weather-alerts",
      description: "Get active weather alerts and warnings",
      parameters: getWeatherAlertsSchema,
      execute: async (args, { session, log }) => {
        try {
          log.info("Getting weather alerts", { 
            location: args.location
          });
          
          // Get OpenWeather client
          const client = getOpenWeatherClient(session as SessionData | undefined);
          
          // Configure client for this request
          configureClientForLocation(client, args.location);
          
          // Fetch alerts data
          const alertsData = await client.getAlerts();
          
          log.info("Successfully retrieved weather alerts", { 
            location: args.location,
            alerts_count: alertsData.length
          });
          
          // Format the response
          const formattedAlerts = JSON.stringify({
            location: args.location,
            alerts_count: alertsData.length,
            alerts: alertsData.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,
              severity: alert.tags.includes('severe') || alert.tags.includes('extreme') ? 'High' : 
                       alert.tags.includes('moderate') ? 'Medium' : 'Low'
            }))
          }, null, 2);
          
          return {
            content: [
              {
                type: "text",
                text: formattedAlerts
              }
            ]
          };
        } catch (error) {
          log.error("Failed to get weather alerts", { 
            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 weather alerts: ${error instanceof Error ? error.message : 'Unknown error'}`);
        }
      }
    });
  • The execute handler function for get-weather-alerts: configures OpenWeather client for location, calls client.getAlerts(), formats alerts data into JSON with details like sender, event, times, description, tags, severity, and returns as text content.
    execute: async (args, { session, log }) => {
      try {
        log.info("Getting weather alerts", { 
          location: args.location
        });
        
        // Get OpenWeather client
        const client = getOpenWeatherClient(session as SessionData | undefined);
        
        // Configure client for this request
        configureClientForLocation(client, args.location);
        
        // Fetch alerts data
        const alertsData = await client.getAlerts();
        
        log.info("Successfully retrieved weather alerts", { 
          location: args.location,
          alerts_count: alertsData.length
        });
        
        // Format the response
        const formattedAlerts = JSON.stringify({
          location: args.location,
          alerts_count: alertsData.length,
          alerts: alertsData.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,
            severity: alert.tags.includes('severe') || alert.tags.includes('extreme') ? 'High' : 
                     alert.tags.includes('moderate') ? 'Medium' : 'Low'
          }))
        }, null, 2);
        
        return {
          content: [
            {
              type: "text",
              text: formattedAlerts
            }
          ]
        };
      } catch (error) {
        log.error("Failed to get weather alerts", { 
          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 weather alerts: ${error instanceof Error ? error.message : 'Unknown error'}`);
      }
    }
  • Zod validation schema defining the input parameter 'location' (string: city name or coordinates) for the get-weather-alerts tool.
    export const getWeatherAlertsSchema = z.object({
      location: z.string().describe("City name (e.g., 'New York') or coordinates (e.g., 'lat,lon')"),
    });
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. 'Get active weather alerts and warnings' implies a read-only operation, but doesn't specify whether this requires authentication, has rate limits, returns real-time or historical data, or what format the alerts come in. For a tool with zero annotation coverage, this leaves significant behavioral questions unanswered.

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 extremely concise at just five words, front-loading the essential purpose with zero wasted language. Every word earns its place: 'Get' (action), 'active' (temporal scope), 'weather alerts and warnings' (resource). This is a model of efficient tool description.

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 alert tool with no annotations and no output schema, the description is insufficiently complete. It doesn't indicate what types of alerts are returned (severe thunderstorm, flood, tornado), whether alerts are filtered by severity, what geographic scope applies, or what the response format looks like. Given the complexity of weather alert systems and the lack of structured metadata, more contextual information would be valuable.

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 the single 'location' parameter fully documented in the schema. The description adds no additional parameter information beyond what's already in the schema. This meets the baseline expectation when schema coverage is complete, but doesn't provide extra context about how location affects alert retrieval.

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 verb ('Get') and resource ('active weather alerts and warnings'), making the purpose immediately understandable. It doesn't explicitly differentiate from siblings like 'get-current-weather' or 'get-weather-forecast', but the focus on 'alerts and warnings' provides some implicit distinction from general weather data tools.

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 alternatives. With siblings like 'get-current-weather' and 'get-weather-forecast' available, there's no indication whether this tool should be used for emergency situations, severe weather only, or as a complement to other weather tools. The user must infer usage from the tool name alone.

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