list_stations
Retrieve a complete list of Caltrain stations to ensure accurate station names for train schedules. Use this tool to resolve 'Station not found' errors in next_trains() queries.
Instructions
List all available Caltrain stations.
This tool is useful when you need to find the exact station names, especially if the next_trains() tool returns a "Station not found" error. Station names are case-insensitive and support some common abbreviations like 'SF' and 'SJ'.
Returns a formatted list of all Caltrain stations that can be used as origin or destination in the next_trains() tool.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/caltrain_mcp/server.py:133-149 (handler)The handler function for the 'list_stations' tool. It is registered via the @mcp.tool() decorator and implements the logic to list all Caltrain stations using GTFS data.@mcp.tool() async def list_stations() -> str: """List all available Caltrain stations. This tool is useful when you need to find the exact station names, especially if the next_trains() tool returns a "Station not found" error. Station names are case-insensitive and support some common abbreviations like 'SF' and 'SJ'. Returns a formatted list of all Caltrain stations that can be used as origin or destination in the next_trains() tool. """ try: stations = gtfs.list_all_stations(gtfs.get_default_data()) stations_list = "\n".join([f"• {station}" for station in stations]) return f"Available Caltrain stations:\n{stations_list}\n\nNote: Station names support common abbreviations like 'SF' for San Francisco and 'SJ' for San Jose." except Exception as e: return f"Error: {str(e)}"
- src/caltrain_mcp/gtfs.py:313-316 (helper)Helper function that extracts and returns the sorted list of all station names from the GTFS data.def list_all_stations(data: GTFSData) -> list[str]: """Get a list of all available Caltrain stations.""" return data.stations["stop_name"].sort_values().tolist()
- src/caltrain_mcp/gtfs.py:96-99 (helper)Cached function to load and provide the default GTFS data used by list_stations.@lru_cache(maxsize=1) def get_default_data() -> GTFSData: """Load GTFS data on first use and cache the result.""" return load_gtfs_data()