Skip to main content
Glama
mirodn

mcp-server-public-transport

ch_nearby_stations

Find Swiss train stations near your location using coordinates. Input latitude and longitude to discover stations within a specified distance for public transport planning.

Instructions

Find nearby Swiss train stations based on coordinates (latitude, longitude).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
latitudeYes
longitudeYes
distanceNo

Implementation Reference

  • The main handler function implementing the ch_nearby_stations tool. It accepts latitude, longitude, and optional distance parameters, queries the Swiss transport API (/locations endpoint) for nearby stations, and handles errors.
    async def ch_nearby_stations(
        latitude: float,
        longitude: float,
        distance: Optional[int] = 1000
    ) -> Dict[str, Any]:
        """Find nearby stations by coordinates."""
        params = {
            "x": longitude,
            "y": latitude,
            "type": "station"
        }
    
        if distance:
            params["distance"] = distance
    
        try:
            logger.info(f"Finding stations near provided coordinates")
            return await fetch_json(f"{CH_BASE_URL}/locations", params)
        except TransportAPIError as e:
            logger.error(f"CH nearby stations search failed: {e}")
            raise
  • tools/ch.py:113-116 (registration)
    Registers the ch_nearby_stations tool with the MCP server using the @mcp.tool decorator, defining its name and description. The tool is also included in the return list of register_ch_tools.
    @mcp.tool(
        name="ch_nearby_stations",
        description="Find nearby Swiss train stations based on coordinates (latitude, longitude)."
    )
  • Function signature defining the input schema (parameters with types) and output type for the tool.
    async def ch_nearby_stations(
        latitude: float,
        longitude: float,
        distance: Optional[int] = 1000
    ) -> Dict[str, Any]:

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mirodn/mcp-server-public-transport'

If you have feedback or need assistance with the MCP directory API, please join our Discord server