Skip to main content
Glama
kennyckk

KMB Bus MCP Server

get_next_bus

Find the next arrival time for a specific KMB bus route at a designated stop in Hong Kong by providing the route number and stop name.

Instructions

Get the next arrival time for a specified bus route at a stop.

Args:
    route: The bus route number (e.g., "1A", "6", "960")
    stop_name: The name of the bus stop

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
routeYes
stop_nameYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function decorated with @mcp.tool(), implementing the core logic for retrieving and formatting the next bus arrival times for a given route and stop name. Includes input schema via type hints and docstring Args.
    @mcp.tool()
    async def get_next_bus(route: str, stop_name: str) -> str:
        """Get the next arrival time for a specified bus route at a stop.
        
        Args:
            route: The bus route number (e.g., "1A", "6", "960")
            stop_name: The name of the bus stop
        """
        # Find the stop ID by 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 ETA data
            eta_data = await get_eta(stop_id, route)
    
            
            if not eta_data:
                results.append(f"No arrival data available for route {route} at stop '{stop_name_en}' ({stop_id})")
                continue
            
            # Filter ETAs for the specified route
            route_etas = [eta for eta in eta_data if eta["route"] == route]
            
            if not route_etas:
                results.append(f"No scheduled arrivals for route {route} at stop '{stop_name_en}' ({stop_id})")
                continue
            
            # Format ETA information
            stop_results = [f"Arrivals for route {route} at '{stop_name_en}' ({stop_id}):"]
            
            for eta in route_etas:
                eta_time = eta.get("eta", None)
                if eta_time :
                    eta_time = eta_time.split("+")[0].replace("T", " ")  # Format the timestamp
                
                dest = eta.get("dest_tc", "") or eta.get("dest_en", "Unknown destination")
                remark = eta.get("rmk_tc", "") or eta.get("rmk_en", "")
                
                if remark:
                    stop_results.append(f"- {eta_time} to {dest} ({remark})")
                else:
                    stop_results.append(f"- {eta_time} to {dest}")
            
            results.append("\n".join(stop_results))
        
        return "\n\n".join(results)
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It describes what the tool does (retrieves arrival time) but lacks critical behavioral details: it doesn't specify if this requires real-time data access, whether results are cached, what happens if the route/stop doesn't exist, or if there are rate limits. For a tool with zero annotation coverage, this leaves significant gaps in understanding its operational behavior.

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

Conciseness5/5

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

The description is appropriately sized and front-loaded: the first sentence states the core purpose clearly, followed by a structured 'Args' section that efficiently documents parameters with examples. Every sentence earns its place without redundancy or fluff, making it easy for an agent to parse quickly.

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 moderate complexity (2 required parameters, no annotations, but with an output schema), the description is minimally adequate. It covers the basic purpose and parameters but lacks behavioral context (e.g., error handling, data freshness). The presence of an output schema means the description doesn't need to explain return values, but it should still address usage guidelines and operational traits to be more complete.

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

Parameters4/5

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

The description adds meaningful semantics beyond the input schema. The schema has 0% description coverage (only titles 'Route' and 'Stop Name'), but the description provides concrete examples for 'route' (e.g., '1A', '6', '960') and clarifies that 'stop_name' is the name of the bus stop. This compensates well for the low schema coverage, though it doesn't detail format constraints (e.g., case sensitivity).

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: 'Get the next arrival time for a specified bus route at a stop.' It includes a specific verb ('Get'), resource ('next arrival time'), and scope ('bus route at a stop'). However, it doesn't explicitly differentiate from sibling tools like 'get_all_routes_at_stop' or 'find_buses_to_destination', 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 list all routes at a stop) or 'find_buses_to_destination' (which might prioritize destination over route). Without any context on usage scenarios or exclusions, the agent must infer based on tool names alone.

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