sar-train-mcp

sar-train-mcp

Provides access to Saudi passenger rail schedules and fares, including Haramain High-Speed Railway and intercity East/North lines, enabling natural language queries for train times and prices.

Category
访问服务器

README

sar-train-mcp

CI PyPI License: MIT Python 3.10+ MCP server

An MCP server for Saudi passenger rail (SAR) — the Haramain High-Speed Railway (HHR) and the intercity East/North lines. Ask an MCP-capable assistant for train times and fares in plain language.

Demo: asking for the cheapest Riyadh→Dammam train and its fares

It uses two backends, matched to how each network exposes its data (the same split the flagship unofficial-API tools use — scrape the open part, use a real browser for the protected part):

Backend Network How Data
HTTP Haramain (HHR) Public HTML timetable (sar.hhr.sa), plain GET, no auth/CAPTCHA Schedules
Headless browser Intercity East/North Renders the public booking results page (tickets.sar.com.sa) and scrapes it Schedules + fares

Why the split: HHR serves an open timetable, so a plain HTTP GET works. The intercity booking API is JWT-authed with an encrypted request/response body — rather than reverse-engineer that anti-scraping layer, we render the public results page in headless Chromium (the browser mints the token and does the crypto natively) and read what any visitor sees, including fares.

Tools

Tool Purpose
list_stations() Haramain stations + ids
search_trains(from, to, date) Haramain schedules (Makkah⇄Madinah). No fares — HHR gates fares behind a reCAPTCHA.
list_intercity_stations() Intercity stations + codes (East + North)
search_intercity(from, to, date) Intercity trains with Economy + Business fares (~5–10 s, headless browser).

date is YYYY-MM-DD. Stations accept names, aliases, or codes/ids ("Makkah", "Jeddah", "Riyadh", "Dammam", "RYD", 5, …).

Example prompts

Once registered, ask your assistant things like:

  • "What Haramain trains run Makkah → Madinah on 2026-06-30, and which are direct?"
  • "Cheapest Riyadh → Dammam train next Sunday — and the business-class price?"
  • "List the SAR intercity stations."

Example output

Example output: Riyadh→Dammam with fares, and Makkah→Madinah schedule

search_intercity("Riyadh", "Dammam", "2026-07-12") — schedules with fares:

{
  "from": "Riyadh", "to": "Dammam", "date": "2026-07-12",
  "count": 7, "currency": "SAR", "source": "tickets.sar.com.sa",
  "trains": [
    { "train": "Train 4", "departure": "05:09", "arrival": "09:19",
      "from_code": "RYD", "to_code": "DMM", "duration": "4h10m",
      "stops": 2, "economy_sar": 135, "business_sar": 240 },
    { "train": "Train 6", "departure": "07:13", "arrival": "11:22",
      "duration": "4h09m", "stops": 2, "economy_sar": 135, "business_sar": 240 }
    // … 5 more
  ]
}
Train Depart Arrive Duration Stops Economy Business
Train 4 05:09 09:19 4h10m 2 SAR 135 SAR 240
Train 6 07:13 11:22 4h09m 2 SAR 135 SAR 240

search_trains("Makkah", "Madinah", "2026-06-30") — Haramain schedules (no fares):

{
  "from": "Makkah", "to": "Madinah", "date": "2026-06-30",
  "count": 22, "source": "sar.hhr.sa/timetable",
  "trains": [
    { "departure": "2026-06-30T06:00", "arrival": "2026-06-30T08:25",
      "duration": "2h25m", "stops": 2,
      "intermediate_stops": ["Al-Sulimaniyah (Jeddah)", "KAEC"] },
    { "departure": "2026-06-30T13:20", "arrival": "2026-06-30T15:35",
      "duration": "2h15m", "stops": 0, "intermediate_stops": [] }  // direct
  ]
}

Coverage

  • Haramain (HHR): Makkah · Jeddah (Al-Sulimaniyah / Airport) · KAEC · Madinah — schedules ✅, fares ❌ (reCAPTCHA)
  • East line: Riyadh (RYD) · Abqaiq (ABQ) · Hufuf (HAF) · Dammam (DMM) — schedules ✅, fares ✅
  • North line: Riyadh · Majmaah · Qassim · Hail · Al-Jouf · Qurayyat — supported, but SAR currently lists no bookable service (returns []; populates when service resumes)

Install

Requires Python ≥ 3.10 and uv (or pip).

git clone https://github.com/RazakGhazal/sar-train-mcp.git
cd sar-train-mcp

# install the CLI/MCP entry point (+ Playwright for the intercity backend)
uv tool install . --with playwright

# one-time: download the headless Chromium used for intercity fares (~150 MB)
"$(uv tool dir)/sar-train-mcp/bin/playwright" install chromium

Then register it with your MCP client. For Claude Code:

claude mcp add sar-train -- "$(command -v sar-train-mcp)"

For Claude Desktop, add to claude_desktop_config.json:

{
  "mcpServers": {
    "sar-train": { "command": "sar-train-mcp" }
  }
}

Notes & limitations

  • HHR TLS quirk: sar.hhr.sa negotiates a weak DH group + legacy signature; the HTTP client uses an ssl context at SECLEVEL=0 (certificate validation stays on).
  • Intercity needs Chromium (Playwright) and takes ~5–10 s/query vs. HHR's instant HTTP.
  • HHR fares are not available — SAR puts a reCAPTCHA on the Haramain fare/booking step, which this project does not attempt to bypass. HHR is schedules-only; use the official site to see HHR prices.
  • Scrapers are tied to the sites' current structure; if SAR redesigns, the parsers (server.py / intercity.py) may need updating.

Development

pip install -e ".[test]"
pytest              # parser fixtures + resolvers + tool registration

Parser tests run against frozen real responses in tests/fixtures/. If SAR redesigns a page, refresh the fixture and update the expected values — a failing test is the signal that a scraper needs attention.

Disclaimer

Unofficial and not affiliated with, endorsed by, or connected to Saudi Arabia Railways (SAR), the Haramain High-Speed Railway, or the Saudi Public Transport Authority. It reads publicly available schedule/fare pages for personal, informational use, at low request volumes. It does not bypass CAPTCHAs or other access controls. Always confirm times and prices and complete bookings on the official channels (sar.com.sa, sar.hhr.sa). Provided "as is" without warranty; see LICENSE.

License

MIT © Abdulrazzak Ghazal

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选