Skip to main content
Glama

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')"), });

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