Skip to main content
Glama
GTFS Realtime MCP Server

GTFS Realtime MCP Server

by bribroder

GTFS Realtime MCP Server

A Model Context Protocol (MCP) server written in Python that allows Large Language Models to query GTFS Static and Realtime transit data, complete with an intelligent in-memory transit routing integration for location-aware transit lookups.

This MCP server provides intelligent tools to list transit stations by line, check upcoming train arrivals (filtering for trains heading toward a destination), and read service alerts affecting specific lines or stations.

Features

  • Standard MCP Interface: Exposes tools natively to Claude or other MCP-compatible clients.

  • GTFS Static: Parses GTFS static zips into memory on startup (handling stops, routes, trips, stop_times) to resolve human-readable station names to GTFS IDs.

  • GTFS Realtime: Uses gtfs-realtime-bindings to parse Protocol Buffer feeds for Trip Updates and Alerts.

  • In-Memory Connection Scan Algorithm (CSA): Takes GPS coordinates (origin/destination), resolves them to GTFS stops via Haversine distance, and queries an embedded Connection Scan Algorithm routing engine directly against the GTFS timetables to identify the optimal path and filter realtime train data correctly based on line/direction constraints.

  • Multiple Transport Modes: Supports standard MCP stdio mode (for local LLM clients like Claude Desktop), sse (HTTP Server-Sent Events) mode, and streamable-http mode.

Related MCP server: PTV Transit MCP Server

Available Tools

The server exposes four primary tools to the LLM:

  1. list_stations_by_line(line_name): Returns all station names for a given rail line (e.g., 'Red', 'Blue').

  2. get_next_train(...): Given origin and destination station names or GPS coordinates (latitude/longitude), it resolves the best stations (falling back to Haversine distance), runs an optimal transit search, and returns the next 5 upcoming train arrivals. It automatically filters out trains that are not heading in the direction of the destination.

  3. plan_trip(...): Plan a scheduled transit trip in the future. Pass origin and destination station names along with a natural-language date/time (like "tomorrow at 8am"). It parses GTFS regular schedules (calendar.txt) and holiday exceptions (calendar_dates.txt) to route and output the top 3 optimal multi-leg itineraries using either "depart_at" or "arrive_by" logic.

  4. check_service_alerts(...): Takes a rail line name or station name and checks the GTFS Realtime Alerts feed to see if any service disruptions apply.

Prerequisites

  • Python 3.12+

  • uv (Recommended for dependency management)

  • A GTFS Realtime transit provider (API keys and endpoints)

Installation

  1. Clone the repository:

    git clone <repository-url>
    cd <repository-dir>
  2. Sync dependencies using uv:

    uv sync

Configuration

The server requires a config.yaml file in the root directory to know where to fetch GTFS data from.

  1. Copy the provided template:

    cp config.yaml.template config.yaml
  2. Edit config.yaml to include your provider's specific endpoints and API key. For example, for WMATA:

    gtfs_api_key: "YOUR_WMATA_API_KEY"
    gtfs_api_url: "https://api.wmata.com/gtfs"
    gtfs_static_url: "https://api.wmata.com/gtfs/rail-gtfs-static.zip"
    gtfs_vp_url: "https://api.wmata.com/gtfs/rail-gtfsrt-vehiclepositions.pb"
    gtfs_tu_url: "https://api.wmata.com/gtfs/rail-gtfsrt-tripupdates.pb"
    gtfs_alerts_url: "https://api.wmata.com/gtfs/rail-gtfsrt-alerts.pb"

Note: The server uses the HTTP header api_key: <YOUR_KEY> when making requests. If your provider requires a different header format (like Authorization: Bearer <KEY>), you may need to adjust src/gtfs_mcp/static_data.py and src/gtfs_mcp/realtime.py accordingly.

Usage

You can run the server directly using uv run.

STDIO Mode (Local MCP Clients)

This is the standard mode for desktop clients like Claude Desktop.

uv run gtfs-mcp --transport stdio

To configure this for Claude Desktop, add the following to your claude_desktop_config.json:

{
  "mcpServers": {
    "gtfs-mcp": {
      "command": "uv",
      "args": [
        "run",
        "gtfs-mcp",
        "--transport",
        "stdio"
      ],
      "cwd": "/path/to/this/repository"
    }
  }
}

SSE / Streamable HTTP Mode (HTTP / Remote)

Run the server exposing HTTP Server-Sent Events or Streamable HTTP on a specific port:

uv run gtfs-mcp --transport sse --host 0.0.0.0 --port 8000
# OR
uv run gtfs-mcp --transport streamable-http --host 0.0.0.0 --port 8000

Available Tools

4 tools
check_service_alertsB

Check if a service alert could affect the journey. You can specify a rail line name (e.g. 'Red') or a station name.

Inputs: line_name, station_name. Returns: result

get_next_trainB

Find out when the next train bound for a destination will arrive at the origin station. You can provide either station names OR gps coordinates (lat/lon) for origin and destination.

Inputs: dest_lat, dest_lon, origin_lat, origin_lon, +2 more. Returns: result

list_stations_by_lineA

List all station names for a given rail line (e.g. 'Red', 'Blue', 'Silver', 'Green', 'Yellow', 'Orange').

Inputs: line_name (required). Returns: result

plan_tripA

Plan a transit trip in the future using the scheduled GTFS timetable.

  • origin_station_name: e.g. "Metro Center"

  • dest_station_name: e.g. "Shady Grove"

  • date_time_str: Human-readable date and time (e.g. "tomorrow at 8am", "2024-05-15 10:00")

  • query_type: 'depart_at' (leave after this time) or 'arrive_by' (reach destination before this time)

Inputs: date_time_str (required), dest_station_name (required), origin_station_name (required), query_type. Returns: result

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.6/5.0

    Scored across 4 tools

    Disambiguation4/5

    The four tools have mostly distinct purposes: station listing, real-time next-train lookup, future trip planning, and service-alert checking. get_next_train and plan_trip could be confused at first, but the descriptions clearly separate real-time versus scheduled future planning.

    Naming Consistency5/5

    All tool names use consistent snake_case verb_noun-style naming: list_stations_by_line, get_next_train, plan_trip, and check_service_alerts. The pattern is predictable and readable throughout.

    Tool Count4/5

    Four tools is a focused, reasonable set for a GTFS realtime transit server. It is slightly thin but not inappropriate, since each tool maps to a clear rider-facing capability.

    Completeness4/5

    The surface covers core transit workflows: discovering stations by line, checking next trains, planning future trips, and checking service alerts. Minor gaps remain, such as station search/autocomplete or richer alert details, but agents can work around them.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers