Skip to main content
Glama
Danii2020

Weather MCP Server

by Danii2020

get_alerts

Fetch real-time weather alerts for a specific state using the Weather MCP Server, ensuring accurate and up-to-date safety notifications.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
stateYes

Implementation Reference

  • Handler function for the 'get_alerts' tool. It makes an API request to the National Weather Service for active alerts in the specified state, processes the response, and formats the alerts using helper functions.
    @mcp.tool() async def get_alerts(state: str) -> str: 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 not 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)
  • Initializes the FastMCP server instance named 'weather', which is used to register tools like get_alerts.
    mcp = FastMCP("weather")
  • weather.py:4-4 (registration)
    Runs the MCP server (with imported mcp instance containing registered tools) using stdio transport.
    mcp.run(transport='stdio')
  • Helper function to make asynchronous HTTP requests to the NWS API, used by get_alerts.
    async def make_nws_request(url: str) -> dict[str, Any] | None: 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 weather alert feature into a human-readable string, used by get_alerts.
    def format_alert(feature: dict) -> str: props = feature["properties"] return f""" Event: {props.get('event', 'Unknown')} Area: {props.get('areaDesc', 'Unknown')} Severity: {props.get('severity', 'Unknown')} Descripton: {props.get('description', 'No description')} Instructions: {props.get('instruction', 'No specific instruction')} """

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/Danii2020/weather-mcp'

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