ch_search_stations
Search for Swiss train stations by name or location using a locally hosted interface for European public transport data. Query stations with precise input parameters.
Instructions
Search for Swiss train stations by name or location.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | ||
| type | No | station |
Implementation Reference
- tools/ch.py:67-85 (handler)The core handler function for the 'ch_search_stations' tool. It validates the search query, constructs API parameters, fetches station data from the Swiss transport API (transport.opendata.ch/locations), logs the operation, and handles TransportAPIError exceptions.query: str, type: Optional[str] = "station" ) -> Dict[str, Any]: """Search for Swiss stations by name.""" if not query or not query.strip(): raise ValueError("Search query cannot be empty") params = { "query": query.strip(), "type": type or "station" } try: logger.info(f"Searching stations: {query}") return await fetch_json(f"{CH_BASE_URL}/locations", params) except TransportAPIError as e: logger.error(f"CH station search failed: {e}") raise
- tools/ch.py:63-66 (registration)The @mcp.tool decorator registers the ch_search_stations function as an MCP tool, specifying its name and description used for tool discovery and invocation.name="ch_search_stations", description="Search for Swiss train stations by name or location." ) async def ch_search_stations(
- tools/ch.py:139-144 (registration)The register_ch_tools function returns a list of registered tool functions, including ch_search_stations, which is consumed by the main server to confirm registration.return [ ch_search_connections, ch_search_stations, ch_get_departures, ch_nearby_stations ]
- server.py:50-52 (registration)In the main server startup, register_ch_tools(mcp) is called to dynamically define and register the Swiss transport tools, including ch_search_stations, with the FastMCP server instance.ch_tools = register_ch_tools(mcp) be_tools = register_be_tools(mcp) no_tools = register_no_tools(mcp)
- tools/ch.py:64-70 (schema)Implicit schema from function signature: required 'query' (str), optional 'type' (str, default 'station'), returns Dict[str, Any]. Description provides usage context.description="Search for Swiss train stations by name or location." ) async def ch_search_stations( query: str, type: Optional[str] = "station" ) -> Dict[str, Any]: """Search for Swiss stations by name."""