Skip to main content
Glama
gravityfalls404

WeatherMCP

get_alerts

Retrieve timely weather alerts for any US state by entering its two-letter code, ensuring immediate updates on severe weather conditions.

Instructions

Get weather alerts for a US state.

Args: state: Two-letter US state code (e.g. CA, NY)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
stateYes

Implementation Reference

  • The main handler function for the 'get_alerts' tool, decorated with @mcp.tool() for registration. It fetches weather alerts for a given US state using the NWS API, formats them, and returns as a string.
    @mcp.tool() async def get_alerts(state: str) -> str: """Get weather alerts for a US state. Args: state: Two-letter US state code (e.g. CA, NY) """ url = f"{NWS_API_BASE}/alerts/active/area/{state}" data = await make_nws_request(url) if not data or "features" not in data: return "Unable to fetch alerts or no alerts found." if not data["features"]: return "No active alerts for this state." alerts = [format_alert(feature) for feature in data["features"]] return "\n---\n".join(alerts)
  • Helper function to format individual alert features into readable strings, used by get_alerts.
    def format_alert(feature: dict) -> str: """Format an alert feature into a readable string.""" props = feature["properties"] return f""" Event: {props.get('event', 'Unknown')} Area: {props.get('areaDesc', 'Unknown')} Severity: {props.get('severity', 'Unknown')} Description: {props.get('description', 'No description available')} Instructions: {props.get('instruction', 'No specific instructions provided')} """
  • Helper function to make HTTP requests to the NWS API, used by get_alerts for fetching data.
    async def make_nws_request(url: str) -> dict[str, Any] | None: """Make a request to the NWS API with proper error handling.""" headers = { "User-Agent": USER_AGENT, "Accept": "application/geo+json" } async with httpx.AsyncClient() as client: try: response = await client.get(url, headers=headers, timeout=30.0) response.raise_for_status() return response.json() except Exception: return None
  • weather.py:40-40 (registration)
    The @mcp.tool() decorator registers the get_alerts function as a tool in the FastMCP server.
    @mcp.tool()
  • Docstring defining the input schema: state as two-letter US state code.
    """Get weather alerts for a US state. Args: state: Two-letter US state code (e.g. CA, NY) """

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/gravityfalls404/WeatherMCP'

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