Skip to main content
Glama
kennyckk

KMB Bus MCP Server

get_route_stops_info

Retrieve all bus stops along a specified KMB bus route to plan journeys and understand route coverage.

Instructions

Get all stops along a specified bus route.

Args:
    route: The bus route number (e.g., "1A", "6", "960")

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
routeYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler function for the 'get_route_stops_info' MCP tool. It orchestrates fetching route details, route stops, and individual stop details for all directions of the given route, then formats and returns a string list of stops.
    @mcp.tool()
    async def get_route_stops_info(route: str) -> str:
        """Get all stops along a specified bus route.
        
        Args:
            route: The bus route number (e.g., "1A", "6", "960")
        """
        # Get all directions for this route
        route_details = await get_route_details(route)
        
        if not route_details:
            return f"Could not find information for route {route}"
        
        results = []
        
        for direction_info in route_details:
            direction = direction_info["bound"]
            service_type = direction_info["service_type"]
            origin = direction_info.get("orig_en", "Unknown")
            destination = direction_info.get("dest_en", "Unknown")
            
            direction_text = "Inbound" if direction == "I" else "Outbound"
            results.append(f"Route {route} {direction_text} from {origin} to {destination}:")
            
            # Get stops for this direction
            stops_data = await get_route_stops(route, direction, service_type)
            
            if not stops_data:
                results.append("  No stop information available")
                continue
            
            # Sort stops by sequence
            stops_data.sort(key=lambda x: x.get("seq", 0))
            
            # Get full stop details for each stop
            stop_details = []
            for stop_data in stops_data:
                stop_id = stop_data["stop"]
                stop_info = await get_stop_details(stop_id)
                
                if "data" in stop_info:
                    stop_details.append({
                        "seq": stop_data.get("seq", 0),
                        "stop_id": stop_id,
                        "name": stop_info["data"].get("name_en", "Unknown"),
                        "lat": stop_info["data"].get("lat", 0),
                        "long": stop_info["data"].get("long", 0)
                    })
            
            # Add stop information to results
            for i, stop in enumerate(stop_details, 1):
                results.append(f"  {i}. {stop['name']} (ID: {stop['stop_id']})")
        
        return "\n\n".join(results)
  • Core helper function that fetches the list of stops for a specific route, direction, and service type by calling the route-stop API endpoint.
    async def get_route_stops(
        route: str,
        direction: str,
        service_type: str,
        *,
        fetch_api_func: Callable[[str], Awaitable[Dict]],
        route_stop_url: str,
    ) -> List:
        direction_full = "inbound" if direction == "I" else "outbound"
        url = f"{route_stop_url}/{route}/{direction_full}/{service_type}"
        response = await fetch_api_func(url)
        if "data" in response:
            return response["data"]
        return []
  • Helper function to retrieve detailed information for a specific stop ID by querying the stop API endpoint.
    async def get_stop_details(
        stop_id: str,
        *,
        fetch_api_func: Callable[[str], Awaitable[Dict]],
        stop_url: str,
    ) -> Dict:
        url = f"{stop_url}/{stop_id}"
        return await fetch_api_func(url)
  • Helper function to get route details, including all directions if none specified, used to determine directions and service types for the route.
    async def get_route_details(
        route: str,
        direction: Optional[str],
        service_type: str,
        *,
        get_route_list_func: Callable[[], Awaitable[List]],
        fetch_api_func: Callable[[str], Awaitable[Dict]],
        route_url: str,
    ) -> Any:
        if direction is None:
            routes = await get_route_list_func()
            route_data = [r for r in routes if r["route"] == route]
            return route_data
    
        url = f"{route_url}/{route}/{direction}/{service_type}"
        return await fetch_api_func(url)
  • kmb_mcp.py:226-226 (registration)
    The @mcp.tool() decorator registers the get_route_stops_info function as an MCP tool.
    @mcp.tool()
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It only states what the tool does ('Get all stops') without mentioning any behavioral traits such as whether it's read-only, potential rate limits, error handling, or what the output contains. This is inadequate for a tool with no annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded, with the core purpose stated clearly in the first sentence. The parameter explanation is concise and directly relevant. It could be slightly improved by integrating the parameter details more seamlessly, but it avoids unnecessary verbosity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's low complexity (1 parameter) and the presence of an output schema, the description is minimally adequate. However, it lacks context about behavioral aspects (e.g., read-only nature, error cases) and doesn't leverage sibling tool names to guide usage, leaving gaps in completeness despite the output schema handling return values.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds significant value beyond the input schema, which has 0% description coverage. It explains the 'route' parameter as 'The bus route number' and provides concrete examples (e.g., '1A', '6', '960'), clarifying the expected format and semantics that the schema alone does not cover.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with a specific verb ('Get') and resource ('all stops along a specified bus route'), making it immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'get_all_routes_at_stop' or 'find_stop_by_name', which prevents a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools like 'get_all_routes_at_stop' (which might provide overlapping information) or clarify scenarios where this tool is preferred, leaving the agent to infer usage context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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