Skip to main content
Glama
mirodn

mcp-server-public-transport

uk_live_departures

Retrieve real-time train departure information for UK stations using CRS codes to plan journeys and check schedules.

Instructions

Get live departure information for a UK train station using its CRS code (e.g., 'PAD' for London Paddington, 'MAN' for Manchester Piccadilly). Uses the TransportAPI station timetables endpoint with live data.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
station_codeYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The main handler function implementing the tool logic: validates CRS station code, loads API credentials, constructs TransportAPI request for live departures, and returns the JSON response.
    async def uk_live_departures(station_code: str) -> Dict[str, Any]:
        """
        Retrieve live departures for a UK train station.
    
        Args:
            station_code (str): 3-letter CRS code (e.g., 'PAD', 'MAN', 'EDI').
    
        Returns:
            Dict[str, Any]: JSON response containing departure details.
        """
        # Validate station code
        code = station_code.strip().upper() if station_code else ""
        if len(code) != 3:
            raise ValueError("Station code must be exactly 3 characters (CRS code).")
    
        # Load credentials from environment variables
        app_id = os.getenv("UK_TRANSPORT_APP_ID")
        api_key = os.getenv("UK_TRANSPORT_API_KEY")
        if not app_id or not api_key:
            raise TransportAPIError(
                "UK Transport API credentials are not configured. "
                "Set both UK_TRANSPORT_APP_ID and UK_TRANSPORT_API_KEY."
            )
    
        # Prepare API request
        url = f"{UK_BASE_URL}/train/station_timetables/{code}.json"
        params = {
            "app_id": app_id,
            "app_key": api_key,
            "live": "true"
        }
    
        # Execute API request
        try:
            logger.info(f"🇬🇧 Fetching live departures for UK station: {code}")
            response = await fetch_json(url, params)
            return response
        except TransportAPIError as e:
            logger.error(f"UK live departures fetch failed: {e}", exc_info=True)
            raise
  • Tool schema definition via @mcp.tool decorator, specifying name, description, and input parameter (station_code: str).
    @mcp.tool(
        name="uk_live_departures",
        description=(
            "Get live departure information for a UK train station using its CRS code "
            "(e.g., 'PAD' for London Paddington, 'MAN' for Manchester Piccadilly). "
            "Uses the TransportAPI station timetables endpoint with live data."
        ),
    )
  • tools/uk.py:67-67 (registration)
    Local registration: register_uk_tools function returns a list containing the uk_live_departures tool for further registration.
    return [uk_live_departures]
  • server.py:57-57 (registration)
    Global registration: Calls register_uk_tools(mcp) in the MCP server initialization to register the UK tools with the FastMCP server instance.
    uk_tools = register_uk_tools(mcp)
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It discloses the data source ('TransportAPI station timetables endpoint with live data'), which adds context, but lacks details on rate limits, error handling, or response format, leaving behavioral gaps.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is front-loaded with the core purpose, followed by parameter guidance and implementation detail in two efficient sentences, with no redundant information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given 1 parameter, no annotations, and an output schema (which handles return values), the description is mostly complete for a simple lookup tool. It covers purpose and parameter use but lacks behavioral details like error cases.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It explains the parameter 'station_code' as a CRS code with examples ('PAD', 'MAN'), adding meaning beyond the schema's generic 'Station Code' title, though it could detail format constraints.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Get live departure information'), resource ('for a UK train station'), and key constraint ('using its CRS code'), with examples provided. It distinguishes from siblings by specifying UK focus and live data, unlike generic departure tools.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It explicitly states when to use this tool (for UK train stations with CRS codes and live data), but does not mention when not to use it or name specific alternatives among the sibling tools, which include other departure-related tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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