find_stop_by_name
Search for Hong Kong KMB bus stops using a full or partial stop name to find relevant stop details quickly and accurately.
Instructions
Find bus stops matching a name or partial name.
Args:
stop_name: Full or partial name of the bus stop to search for
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| stop_name | Yes |
Implementation Reference
- kmb_mcp.py:281-309 (handler)MCP tool handler for 'find_stop_by_name'. It uses the helper to find matching stops and formats a user-friendly string response with stop details including ID, names, and coordinates.@mcp.tool() async def find_stop_by_name(stop_name: str) -> str: """Find bus stops matching a name or partial name. Args: stop_name: Full or partial name of the bus stop to search for """ stops = await find_stops_by_name(stop_name) if not stops: return f"Could not find any stops matching '{stop_name}'" results = [f"Found {len(stops)} stops matching '{stop_name}':"] for i, stop in enumerate(stops, 1): stop_id = stop["stop"] name_en = stop["name_en"] name_tc = stop.get("name_tc", "") lat = stop.get("lat", 0) lng = stop.get("long", 0) if name_tc: results.append(f"{i}. {name_en} ({name_tc})") else: results.append(f"{i}. {name_en}") results.append(f" ID: {stop_id}") results.append(f" Location: {lat}, {lng}") return "\n".join(results)
- utils/handle.py:140-156 (helper)Core helper function implementing the stop name search logic by fetching the full stop list and filtering matches case-insensitively in English or Chinese names.async def find_stops_by_name( name: str, *, get_stop_list_func: Callable[[], Awaitable[List]], ) -> List: stops = await get_stop_list_func() matching_stops: List[Dict[str, Any]] = [] for stop in stops: if ( name.lower() in stop["name_en"].lower() or (stop.get("name_tc") and name.lower() in stop["name_tc"].lower()) ): matching_stops.append(stop) return matching_stops
- kmb_mcp.py:122-128 (helper)Wrapper helper in main file that delegates to the shared utils helper, maintaining compatibility for tests.async def find_stops_by_name(name: str) -> List: """Delegate to shared implementation; keep signature for tests.""" return await handle_utils.find_stops_by_name( name, get_stop_list_func=get_stop_list, )
- kmb_mcp.py:281-281 (registration)The @mcp.tool() decorator registers the find_stop_by_name function as an MCP tool.@mcp.tool()
- kmb_mcp.py:283-287 (schema)Tool schema defined in the docstring, specifying the input parameter 'stop_name: str' and purpose."""Find bus stops matching a name or partial name. Args: stop_name: Full or partial name of the bus stop to search for """