get_station_number
Retrieve station identification numbers by providing station names for Nagoya's bus system, enabling accurate transit data queries and route planning.
Instructions
Get station number for a given station name.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| station_name | Yes |
Implementation Reference
- nagoya_bus_mcp/mcp/tools.py:56-94 (handler)The main tool handler function that executes the logic to find a station number by name using exact match or fuzzy matching with difflib. It uses cached station names from the bus client.async def get_station_number( ctx: Context, station_name: str ) -> StationNumberResponse | None: """Get station number for a given station name.""" client = ctx.request_context.lifespan_context.bus_client log.info("Getting station number for %s", station_name) station_names = await _get_station_names(client) # First try exact match station_number = station_names.get(station_name) if station_number is not None: return StationNumberResponse( success=True, station_name=station_name, station_number=station_number ) # If no exact match, try fuzzy matching log.info("No exact match found for %s, trying fuzzy matching", station_name) closest_matches = difflib.get_close_matches( station_name, station_names.keys(), n=1, cutoff=0.6 ) if closest_matches: closest_station = closest_matches[0] closest_station_number = station_names[closest_station] log.info( "Found closest match: %s (station number: %s)", closest_station, closest_station_number, ) return StationNumberResponse( success=True, station_name=closest_station, station_number=closest_station_number, ) log.info("No fuzzy match found for %s", station_name) return StationNumberResponse(success=False)
- nagoya_bus_mcp/mcp/tools.py:15-19 (schema)Pydantic model defining the response schema for the get_station_number tool, including success flag and optional station details.class StationNumberResponse(BaseModel): success: bool station_name: str | None = None station_number: int | None = None
- nagoya_bus_mcp/mcp/server.py:38-40 (registration)Registration of the get_station_number tool (and get_timetable) on the FastMCP server instance.mcp_server: FastMCP = FastMCP("Nagoya Bus MCP", version=version, lifespan=lifespan) mcp_server.tool(get_station_number) mcp_server.tool(get_timetable)
- nagoya_bus_mcp/mcp/tools.py:40-45 (helper)Helper function to fetch and cache station names by number from the client, used by get_station_number.async def _get_station_names(client: Client) -> dict[str, int]: global _cached_station_names # noqa: PLW0603 if _cached_station_names is None: _cached_station_names = (await client.get_station_names()).root return _cached_station_names
- nagoya_bus_mcp/mcp/tools.py:47-54 (helper)Helper function to fetch and cache station numbers by name (inverse of station names), shared with other tools.async def _get_station_numbers(client: Client) -> dict[int, str]: global _cached_station_numbers # noqa: PLW0603 if _cached_station_numbers is None: _cached_station_numbers = { num: name for name, num in (await _get_station_names(client)).items() } return _cached_station_numbers