uktrains
MCP server for UK train journeys that resolves station names, builds journey intents, and generates pre-filled booking links, with optional fare-aware ranking.
README
uktrains
An agent-first UK train journey CLI and stdio MCP server. It's built for a personal LLM agent to search journeys, compare fares, and hand the human a pre-filled booking link — the tool never takes payment and never claims a booking was made. Fulfilment means one thing: a correct, pre-filled retailer checkout link the human taps to pay.
JSON is the default output everywhere (CLI and MCP alike); pass --pretty
on the CLI for a human-readable table.
What it does today
- Resolves UK station names/aliases to CRS codes, including group stations ("Manchester", "London").
- Builds a journey intent from
--from/--toplus--depart-afteror--arrive-by(and the return-leg equivalents), and produces a pre-filled National Rail Enquiries journey planner booking link — the only live provider today (see "Capability tiers" below for the dormant Trainline provider). A return leg witharrive-byis flagged with a note: NRE's URL can't pre-fill that constraint on the return leg, so it's pre-filled as depart-after and the caller should verify the return train actually arrives by the deadline on the retail page. - At Tier 1, fetches BR Fares flow-level fares (railcard-aware), sorted by
price (the
cheapest/fastest/balancedrankBymodes are accepted today but don't change ordering yet — journey-level ranking arrives with Tier 2), including return-vs-two-singles comparison. doctorreports which tier is active and validates configured keys.setupwalks an agent (or a human) through the two optional signups.
live (CLI) and live_status (MCP) exist as structured stubs today — they
return a TIER_UNAVAILABLE error with a setup pointer rather than pretending
to have live data. Live departures/delays and richer in-tool journey planning
land in a later plan (Tier 2).
Capability tiers
No free API combines journey planning with fares, and Darwin live data requires a Rail Data Marketplace account with human approval — so the tool degrades gracefully instead of demanding setup upfront.
| Tier | Requires | Unlocks |
|---|---|---|
| 0 | Nothing (bundled station data) | Station resolution, journey intent construction, a pre-filled National Rail Enquiries booking link. The core "get me a train" flow works the moment you build it — the human sees times and fares on the retail page. |
| 1 | BR Fares API key (free, non-commercial, ~minutes to register, 100 calls/day) | In-tool fare quotes with railcard discounts — rank cheapest vs. fastest, compare return vs. two singles, before handing over a link. The parser is validated against docs-authored fixtures; run npx tsx scripts/record-brfares.ts <orig> <dest> <key> with your first real key to re-record a live response and confirm the shape still matches — if the live API's shape has drifted, fares present as UPSTREAM_DOWN rather than silently misparsing. |
| 2 | RDM account + "LDBWS – Public" subscription (free, 1–3 day approval) | Live departures, delays, platforms, cancellations; real in-tool journey planning with a realtime overlay. Not implemented yet — arrives in the next plan. |
Run uktrains doctor at any time to see the active tier and exactly what's
missing to reach the next one.
National Rail Enquiries is the sole live booking-link provider today.
The code also carries a Trainline provider, but it's dormant: a Trainline
link needs a verified station-ID mapping (URN) for BOTH the origin and
destination, and data/trainline-urns.json currently has exactly one
verified entry (KGX) — so no station pair can produce a Trainline link yet.
The code path and its fixture-backed tests stay in place for when more URNs
get recorded; until then, expect NRE-only links.
Install
For agents
If you are an LLM agent: read AGENTS.md — it is written for you and covers install, MCP registration, setup shepherding, and how to present options to your human.
git clone https://github.com/aaryan-gulia/uktrains.git
cd uktrains
npm install
npm run build
The built CLI is at dist/cli/index.js and runnable directly:
node dist/cli/index.js search --from KGX --to YRK --depart-after 2031-08-01T09:00:00+01:00
Or invoke it via npx once linked/published, or point an MCP client at the
built entry point (below) — no global install required.
For humans
Same steps, then optionally npm link (or install globally once published)
so the uktrains command is on PATH.
Requires Node.js 20+.
MCP client config
If uktrains is on PATH (e.g. via npm link):
{
"command": "uktrains",
"args": ["mcp"]
}
From a source checkout, without installing globally:
{
"command": "node",
"args": ["/absolute/path/to/uktrains/dist/cli/index.js", "mcp"]
}
The server exposes four tools: search_journeys, get_booking_link,
live_status (Tier 2 stub), and lookup_station. Tool descriptions are
normative — they tell the calling agent, for example, that arriveBy is a
station arrival time and that the agent is responsible for adding transit
and buffer time to the actual appointment.
CLI examples
# Search a journey (JSON by default; --pretty for a human-readable table)
uktrains search --from KGX --to YRK --depart-after 2031-08-01T09:00:00+01:00 --pretty
# Same, but restrict fares to a railcard and rank by cheapest
uktrains search --from "London" --to "Manchester" \
--depart-after 2031-08-01T09:00:00+01:00 \
--railcard 16-25 --rank-by cheapest
# Booking links only, no fare lookup
uktrains link --from KGX --to YRK --depart-after 2031-08-01T09:00:00+01:00
# Resolve a station name or CRS code
uktrains stations york
# Agent-drivable setup: machine-readable next steps for both signups
uktrains setup --json
# Store a key once the human has completed a signup
uktrains setup --set brfares=<key>
# Check active tier and validate configured keys
uktrains doctor
All time flags (--depart-after, --arrive-by, --return-depart-after,
--return-arrive-by) take ISO-8601 timestamps and require an explicit
timezone offset (e.g. 2031-08-01T09:00:00+01:00 or Z). Offset-less
times are rejected with a structured INVALID_INPUT error — silently
guessing a timezone produces silently wrong booking links.
Setup walkthrough
uktrains setup --json (the default) prints machine-readable steps so an
agent can shepherd the human through both signups in the background, while
Tier 0 already delivers working booking links:
- BR Fares (Tier 1) — open
https://www.brfares.com/api/login.html, register a free non-commercial account, obtain an API key, then runuktrains setup --set brfares=<key>. - Rail Data Marketplace (Tier 2, live data — not yet consumed by this
build) — open
https://raildata.org.uk, create an individual account (approval typically takes 1–3 working days), subscribe to the free "LDBWS – Public" product, then runuktrains setup --set rdm=<key>.
Config is stored at ~/.config/uktrains/config.json and holds only
rail-domain state: API keys, railcards, and ranking preferences. No home
station, no calendar integration — the calling agent already knows that.
Attribution and licensing notes
- Output carries "Powered by National Rail Enquiries" per NRE's OGL terms.
- Each user brings their own API keys. RDM and BR Fares agreements are per-account — this tool never shares keys or redistributes upstream data.
- The BR Fares free tier is registered for non-commercial use only.
- Fares are flow-level (origin→destination, railcard-adjusted), not per-train, and are stamped indicative and time-stamped at quote time. Advance fares are additionally flagged subject to availability, since Advance quota lives in the closed National Reservation Service that no open source exposes. Re-search before presenting a fare older than ~15 minutes.
- The tool never takes payment and never states or implies that a booking was completed — only that a booking link was produced.
Further reading
- Design spec:
docs/superpowers/specs/2026-07-31-uktrains-design.md - Implementation plan:
docs/superpowers/plans/2026-07-31-uktrains-core-tier0-1.md - Agent guide:
AGENTS.md
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。