vehicle_positions_tool
Track live bus positions on specific routes to monitor real-time vehicle locations, coordinates, bearing, and speed for CATA transportation services.
Instructions
Get current positions of vehicles on a specific route.
Args: route_id: The route ID to filter by (e.g., "BL" for Blue Loop)
Returns: List of vehicle positions with ID, coordinates, bearing, and speed
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| route_id | Yes |
Implementation Reference
- src/catabus_mcp/server.py:132-144 (handler)MCP tool handler and registration for vehicle_positions_tool. Includes input schema via type hints and docstring, ensures data initialization, and calls the core vehicle_positions helper function.@mcp.tool async def vehicle_positions_tool(route_id: str) -> list[dict[str, Any]]: """Get current positions of vehicles on a specific route. Args: route_id: The route ID to filter by (e.g., "BL" for Blue Loop) Returns: List of vehicle positions with ID, coordinates, bearing, and speed """ await ensure_initialized() return await vehicle_positions(realtime_poller.data, route_id)
- Core helper function implementing the vehicle positions logic: filters realtime vehicle data by route_id and formats output with vehicle_id, lat, lon, bearing, and speed.async def vehicle_positions(realtime_data: RealtimeData, route_id: str) -> list[dict[str, Any]]: """ Get current positions of vehicles on a specific route. Args: realtime_data: The GTFS realtime data. route_id: The route ID to filter by. Returns: List of vehicle positions with ID, coordinates, bearing, and speed. """ vehicles = [] for vehicle_id, position in realtime_data.vehicle_positions.items(): # Filter by route if specified if position.route_id == route_id: vehicles.append( { "vehicle_id": vehicle_id, "lat": position.latitude, "lon": position.longitude, "bearing": position.bearing, "speed_mps": position.speed, } ) return vehicles