vehicle_positions_tool
Retrieve real-time vehicle positions for a specific bus route, providing ID, coordinates, bearing, and speed data for tracking current locations.
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:136-148 (handler)Handler function for vehicle_positions_tool, registered via @mcp.tool decorator. Ensures data initialization and calls the vehicle_positions helper.@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 that filters vehicle positions from realtime data by route_id and returns formatted list of positions.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