Skip to main content
Glama
trip_alerts.py1.46 kB
"""MCP tool for getting service alerts.""" from typing import Any, Dict, List, Optional from ..ingest.realtime_poll import RealtimeData async def trip_alerts(realtime_data: RealtimeData, route_id: Optional[str] = None) -> List[Dict[str, Any]]: """ Get current service alerts. Args: realtime_data: The GTFS realtime data. route_id: Optional route ID to filter alerts (if None, returns all). Returns: List of alerts with route ID, header, description, and severity. """ alerts = [] for alert in realtime_data.alerts: # Check if this alert is relevant to the requested route if route_id: relevant = False for entity in alert.informed_entities: if entity.get("route_id") == route_id: relevant = True break if not relevant: continue # Get affected route IDs affected_routes = [] for entity in alert.informed_entities: if "route_id" in entity: affected_routes.append(entity["route_id"]) alerts.append({ "route_id": affected_routes[0] if len(affected_routes) == 1 else None, "affected_routes": affected_routes, "header": alert.header, "description": alert.description, "severity": alert.severity, }) return alerts

Implementation Reference

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/Pranav-Karra-3301/catabus-mcp'

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