Skip to main content
Glama
kennyckk

KMB Bus MCP Server

get_all_routes_at_stop

Find all bus routes that serve a specific bus stop. Provide the stop name to see which routes pass through that location.

Instructions

Get all bus routes that pass through a specified bus stop.

Args:
    stop_name: Name of the bus stop

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
stop_nameYes

Implementation Reference

  • The @mcp.tool() decorated handler function implementing get_all_routes_at_stop, which finds stops by name, retrieves route-stop mappings, groups routes by stop, fetches route details, and formats the list of routes serving the stop.
    @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)
  • kmb_mcp.py:311-311 (registration)
    Registration of the get_all_routes_at_stop tool via @mcp.tool() decorator.
    @mcp.tool()
  • Type hints and docstring defining input (stop_name: str) and output (str) schema for the 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
        """

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/kennyckk/mcp_hkbus'

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