ch_get_departures
Retrieve real-time departure information for Swiss train stations using a locally hosted server. Input station name, limit results, and specify datetime for accurate schedules.
Instructions
Get departure board for a Swiss train station with real-time information.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| datetime | No | ||
| limit | No | ||
| station | Yes |
Input Schema (JSON Schema)
{
"properties": {
"datetime": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Datetime"
},
"limit": {
"anyOf": [
{
"type": "integer"
},
{
"type": "null"
}
],
"default": 10,
"title": "Limit"
},
"station": {
"title": "Station",
"type": "string"
}
},
"required": [
"station"
],
"type": "object"
}
Implementation Reference
- tools/ch.py:90-111 (handler)The main handler function implementing the ch_get_departures tool. Fetches real-time train departures from a specified Swiss station using the transport.opendata.ch API.async def ch_get_departures( station: str, limit: Optional[int] = 10, datetime: Optional[str] = None ) -> Dict[str, Any]: """Get departures from a Swiss train station.""" station_clean = validate_station_name(station) params = { "station": station_clean, "limit": limit or 10 } if datetime: params["datetime"] = datetime try: logger.info(f"Getting departures for: {station}") return await fetch_json(f"{CH_BASE_URL}/stationboard", params) except TransportAPIError as e: logger.error(f"CH departures fetch failed: {e}") raise
- tools/ch.py:86-89 (registration)Registers the ch_get_departures tool with the MCP server via the @mcp.tool decorator, defining its name and description.@mcp.tool( name="ch_get_departures", description="Get departure board for a Swiss train station with real-time information." )
- tools/ch.py:139-144 (registration)The register_ch_tools function returns a list of Swiss transport tools including ch_get_departures, which are registered when this function is called.return [ ch_search_connections, ch_search_stations, ch_get_departures, ch_nearby_stations ]
- tools/ch.py:90-94 (schema)Input schema defined by function parameters: station (required str), limit (optional int, default 10), datetime (optional str). Output is Dict[str, Any].async def ch_get_departures( station: str, limit: Optional[int] = 10, datetime: Optional[str] = None ) -> Dict[str, Any]: