Skip to main content
Glama
agentventure

Weather MCP Server

by agentventure

get_alerts

Retrieve active weather alerts for any US state using the National Weather Service API to monitor severe conditions and stay informed.

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

  • Main handler function for the 'get_alerts' tool. Registered via @mcp.tool() decorator. Takes a US state code, fetches active alerts from NWS API, handles errors, formats output using helper functions.
    @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 make HTTP requests to NWS API with headers, timeout, and error handling. Used by get_alerts.
    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
  • Helper function to format a single alert feature into a human-readable string. Used in get_alerts for each alert.
    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')} """
  • weather.py:37-37 (registration)
    Registration of the get_alerts tool via the FastMCP @tool decorator.
    @mcp.tool()
  • Input schema defined in the tool's docstring: parameter '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) """
Install Server

Other 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/agentventure/mcp_server_python_getting_started'

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