GTFS Realtime MCP Server
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@GTFS Realtime MCP Server when's the next Red Line train from Metro Center to Silver Spring?"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
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-bindingsto 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
stdiomode (for local LLM clients like Claude Desktop),sse(HTTP Server-Sent Events) mode, andstreamable-httpmode.
Related MCP server: PTV Transit MCP Server
Available Tools
The server exposes four primary tools to the LLM:
list_stations_by_line(line_name): Returns all station names for a given rail line (e.g., 'Red', 'Blue').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.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.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
Clone the repository:
git clone <repository-url> cd <repository-dir>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.
Copy the provided template:
cp config.yaml.template config.yamlEdit
config.yamlto 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 stdioTo 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 8000Available Tools
4 toolscheck_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
Scored across 4 tools
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.
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.
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.
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
Related MCP Connectors
Read-only public transit departures, stop search, and city coverage for bus and train users.
Trips, departures, alerts and vehicles for NYC, DC and the SF Bay Area.
Real-time BART departures, trip planning, fares, stations, and advisories.
Plan San Francisco and Bay Area transit trips and check upcoming stop departures. Free, no API keys.
Related MCP Servers
- AlicenseBqualityFmaintenanceEnables AI clients to access Boston's MBTA public transit data, including real-time predictions, schedules, route planning, and service alerts.321Apache 2.0
- AlicenseAqualityDmaintenanceExposes Victoria's public transport (PTV) GTFS timetable data as MCP tools, allowing LLMs to answer natural-language questions about routes, stops, and departure times.4MIT
- AlicenseAqualityCmaintenanceEnables LLM clients to search stops, plan journeys, check live departures, service alerts, nearby locations, and vehicle positions using Transport for NSW open data, with per-request API key authentication.101MIT
- AlicenseAqualityCmaintenanceEnables AI assistants to access real-time and scheduled public transit data, including routes, stops, departures, and service alerts, across multiple US metropolitan areas.5MIT