search_stops_tool
Find bus stops by name or ID to get location details for CATA bus routes in State College, PA.
Instructions
Search for stops by name or ID.
Args: query: Search query string to match against stop names, IDs, or descriptions
Returns: List of matching stops with their ID, name, latitude, and longitude
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes |
Implementation Reference
- src/catabus_mcp/server.py:99-112 (handler)The main handler function for the 'search_stops_tool' MCP tool. It is registered via the @mcp.tool decorator, ensures GTFS data is initialized, and calls the search_stops helper function.@mcp.tool async def search_stops_tool(query: str) -> list[dict[str, Any]]: """Search for stops by name or ID. Args: query: Search query string to match against stop names, IDs, or descriptions Returns: List of matching stops with their ID, name, latitude, and longitude """ await ensure_initialized() if not gtfs_data or not gtfs_data.stops: return [] return await search_stops(gtfs_data, query)
- Core helper function that implements the stop search logic: performs case-insensitive substring matching on stop_id, stop_name, stop_code, and stop_desc, collects matching stops, and sorts them by name.async def search_stops(gtfs_data: GTFSData, query: str) -> list[dict[str, Any]]: """ Search for stops by name or ID. Args: gtfs_data: The GTFS static data. query: Search query string. Returns: List of matching stops with id, name, latitude, and longitude. """ query_lower = query.lower() results = [] for stop_id, stop in gtfs_data.stops.items(): # Search in stop ID, name, code, and description if ( query_lower in stop.stop_id.lower() or query_lower in stop.stop_name.lower() or (stop.stop_code and query_lower in stop.stop_code.lower()) or (stop.stop_desc and query_lower in stop.stop_desc.lower()) ): results.append( { "stop_id": stop.stop_id, "name": stop.stop_name, "lat": stop.stop_lat, "lon": stop.stop_lon, } ) # Sort by name for consistency (use empty string for None) results.sort(key=lambda x: str(x.get("name") or "")) return results
- src/catabus_mcp/server.py:100-100 (schema)Type signature of the tool handler defining input (query: str) and output (list[dict[str, Any]]) schema.async def search_stops_tool(query: str) -> list[dict[str, Any]]: