get_all_routes_at_stop
Retrieve all bus routes passing through a specific bus stop in Hong Kong using stop_name. Access real-time KMB and Long Win Bus route data for accurate transit planning.
Instructions
Get all bus routes that pass through a specified bus stop.
Args:
stop_name: Name of the bus stop
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| stop_name | Yes |
Implementation Reference
- kmb_mcp.py:311-370 (handler)The core handler function for the 'get_all_routes_at_stop' tool, decorated with @mcp.tool() for registration. It finds stops by name, retrieves route-stop data, filters and groups routes by stop, fetches route details, and formats a readable list of serving routes with directions.@mcp.tool() async def get_all_routes_at_stop(stop_name: str) -> str: """Get all bus routes that pass through a specified bus stop. Args: stop_name: Name of the bus stop """ # Find stops matching the name stops = await find_stops_by_name(stop_name) if not stops: return f"Could not find any stops matching '{stop_name}'" results = [] for stop in stops: stop_id = stop["stop"] stop_name_en = stop["name_en"] # Get all route-stop combinations route_stops = await get_route_stop_list() # Filter for this stop stop_routes = [rs for rs in route_stops if rs["stop"] == stop_id] if not stop_routes: results.append(f"No routes found for stop '{stop_name_en}' ({stop_id})") continue # Group by route for better readability routes_info = {} for rs in stop_routes: route = rs["route"] bound = rs["bound"] service_type = rs["service_type"] key = f"{route}:{service_type}" if key not in routes_info: routes_info[key] = [] routes_info[key].append(bound) # Format results stop_results = [f"Routes serving '{stop_name_en}' ({stop_id}):"] # Get full route information for each route for key, bounds in routes_info.items(): route, service_type = key.split(":") route_data = await get_route_details(route) for r in route_data: if r["service_type"] == service_type and r["bound"] in bounds: origin = r.get("orig_en", "Unknown") dest = r.get("dest_en", "Unknown") direction = "→" if r["bound"] == "O" else "←" stop_results.append(f"- Route {route}: {origin} {direction} {dest}") results.append("\n".join(stop_results)) return "\n\n".join(results)