PTV Transit MCP Server

PTV Transit MCP Server

Exposes Victoria's public transport (PTV) GTFS timetable data as MCP tools, allowing LLMs to answer natural-language questions about routes, stops, and departure times.

Category
访问服务器

README

PTV Transit MCP Server

demo

An MCP server that exposes Victoria's public transport (PTV) GTFS timetable data — trains, trams, and buses — so an LLM (Claude Desktop, Cursor, etc.) can answer natural-language questions about routes, stops, and departure times.

Data at a glance: 1,069 routes · 31,971 stops · 333,875 trips · 12.6 million scheduled stop times, across 8 transport modes (metro train, metro tram, metro bus, regional train, regional bus, regional coach, night bus, SkyBus).

Why this project

Data source: Transport Victoria's GTFS Schedule dataset, published by the Victorian Department of Transport and Planning. It contains static timetable information for all metropolitan and regional trains, buses (including coach), and trams in Victoria, refreshed on a weekly (or as-needed) basis.

This project turns that raw GTFS export into a queryable SQLite database and wraps it in an MCP server with:

  • Tools for structured lookups (stop search, route listing, next departures)
  • A guarded raw-SQL tool for open-ended questions, restricted to read-only SELECT statements with a hard file-level read-only guarantee underneath
  • A schema resource so the model can write informed queries without guessing column names
  • A prompt template for trip planning

Setup (Windows, using uv)

  1. Install uv if you don't have it:

    powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
    
  2. Clone this repo and install dependencies:

    git clone https://github.com/MananshuMandaliya/ptv-mcp-server.git
    cd ptv-mcp-server
    uv sync
    
  3. Download the GTFS data: Go to the GTFS Schedule dataset page, download the current GTFS.zip, and save it as:

    data/gtfs.zip
    
  4. Build the database:

    uv run python scripts/build_database.py
    

    This creates data/ptv.db. It can take a couple of minutes — stop_times alone typically runs into the millions of rows across all modes.

  5. Test it with the MCP Inspector:

    uv run mcp dev src/ptv_mcp/server.py
    

    This opens an interactive UI in your browser where you can call each tool directly and see the raw responses.

  6. Install into Claude Desktop:

    uv run mcp install src/ptv_mcp/server.py
    

    Restart Claude Desktop, and you should see this server's tools available in a new conversation.

Example queries once connected

  • "What time is the next train from Oakleigh station?"
  • "List all tram routes."
  • "How many stops does the Frankston line have?" (via the raw SQL tool)

example query screenshot

Project structure

ptv-mcp-server/
├── pyproject.toml
├── scripts/build_database.py   # GTFS.zip -> SQLite
└── src/ptv_mcp/server.py       # the MCP server

Design decisions

Why SQLite instead of a hosted database? Zero setup for anyone reviewing this project — clone, build, run. No credentials, no hosting cost, no server to keep alive. GTFS is also a natural fit for SQLite: it's a static, read-heavy dataset that's rebuilt from source on a schedule rather than written to at runtime.

Why a nested-zip loader? Victoria's GTFS.zip isn't structured as one folder per mode with plain .txt files — each branch folder (train, tram, bus, etc.) contains its own nested google_transit.zip. The first version of the loader assumed flat .txt files and silently loaded zero rows. Rather than guessing at a fix, I wrote a small diagnostic script to print the actual zip structure, confirmed the nested-zip pattern, then rewrote the loader to open each nested zip in memory (io.BytesIO) rather than extracting to disk.

Why guard run_sql_query at two layers? The tool needs to let the model run arbitrary read-only SQL for questions the structured tools don't anticipate, but "arbitrary SQL from an LLM" is a real risk surface. So there are two independent layers: the SQLite connection itself is opened via a read-only URI (file:...?mode=ro), which SQLite enforces at the file-handle level regardless of what the query says, and a regex guard rejects anything that isn't a single SELECT statement before it's even executed. Either layer alone would probably be enough; both together means one bug in the regex doesn't turn into a write.

Why index stop_id, trip_id, route_id, and service_id? stop_times has 12.6 million rows. Without indexes, get_next_departures was a full table scan on every call. With them, lookups return in well under a second even on this dataset size.

Notes / limitations

  • This serves the static schedule, not live GPS positions or real-time delays (Transport Victoria separately publishes a GTFS-Realtime feed for that — a natural extension of this project).
  • The GTFS export contains a rolling window of timetable data from its export date, so data/gtfs.zip should be re-downloaded periodically to stay current.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选