indian-rail-mcp
indian-rail-mcp
来自官方来源的 Indian Railways 数据,以强类型 TypeScript 库和 MCP 服务器的形式提供。
无需 API 密钥。不依赖第三方数据供应商。没有随时可能消失的 npm 中间商。
NTES — | 列车时刻表、实时运行状态、车厢位置、站间列车查询、实时车站大屏 |
IRCTC — | PNR 状态、逐车厢及铺位级别的余票情况 |
为什么存在
流行的 irctc-connect 包已被弃用。其作者将它改名为 railkit,并转为需要注册和 API 密钥的模式;它原本依赖的免费后端(bookmytrain.vercel.app、easy-rail.onrender.com)现在返回 404 和 500。那个生态系统中仍在运行的东西,都要靠抓取第三方网站,并使用从该网站自身标记中提取的凭据。
这个库直接对接 Indian Railways 实际运营的数据源。
Related MCP server: Indian Railway MCP
安装
npm install indian-rail-mcp需要 Node 20+。唯一的运行时依赖是 cheerio。
库
import {
getTrainInfo,
trackTrain,
searchTrainsBetweenStations,
getLiveStation,
getSeatAvailability,
checkPnrStatus
} from "indian-rail-mcp";
// Full schedule and route
const info = await getTrainInfo("12951");
// -> { trainName: "NDLS TEJAS RAJ", type: "RAJDHANI", runsOn: "Daily",
// classes: ["1A","2A","3A"], route: [ { stationCode: "MMCT", departure: "17:00", ... }, ... ] }
// Where is it right now (defaults to the journey in progress)
const live = await trackTrain("12626");
// -> { journeyDate, summary: "Arrived at BUTI BORI(BTBR) at 13:27 26-Aug",
// stops: [...], coachPosition: [ { position: 0, coach: "ENG", classCode: "ENG" }, ... ] }
// Direct trains between two stations — code or full name
await searchTrainsBetweenStations("CAN", "PAY");
await searchTrainsBetweenStations("NEW DELHI", "MMCT");
// Next couple of hours at a station, with delay and platform
await getLiveStation("NDLS");
// Reservation chart: per-coach vacancy, plus berth detail when a class is given
await getSeatAvailability({ trainNumber: "12951", boardingStation: "MMCT", travelClass: "3A" });车站既接受代码也接受全名——NDLS 和 NEW DELHI 都可以,会根据 NTES 自己的 8,700 个车站目录进行解析。日期接受 DD-MM-YYYY、DD-MMM-YYYY 或 YYYY-MM-DD。
错误
每次失败都会得到一个类型化的 RailError:
类 |
| 含义 |
|
| 车站、车次或日期无效——在本地捕获,且先于任何网络调用 |
|
| NTES 返回了 |
|
| IRCTC 返回了 |
|
| 网络故障或无法解析的响应 |
关于
ERR000: NTES 对格式错误的输入与对真实故障返回同样的通用ERR000页面。因此,这个库在调用 NTES 之前会先对照目录校验车站代码,这样你自己的拼写错误绝不会被报告为“铁路服务中断”。NtesError刻意同时列出两种可能性,而不是断言发生了故障。
MCP 服务器
六个工具:getTrainInfo、trackTrain、searchTrainBetweenStations、getLiveStation、getSeatAvailability、checkPnrStatus。
import { createRailMcpServer } from "indian-rail-mcp/mcp";
const server = createRailMcpServer({ allowPnr: true });
await server.connect(yourTransport);部署到 Vercel
vercel deployvercel.json 将函数固定到 bom1(孟买)——两个上游服务都在印度,其价值远超表面看起来:热请求约 ~124 ms,而冷请求约 ~885 ms;此外,来自印度出口 IP 的印度流量触发 NTES 前端 F5 WAF 的可能性要小得多。
环境变量:
变量 | 用途 |
| 启用 |
| 每个 IP 的请求上限。默认 30。 |
使用 Streamable HTTP 传输,将任意 MCP 客户端指向 https://<your-deployment>/api/mcp。
PNR 与个人数据
checkPnrStatus 返回乘客个人数据——姓名、年龄、性别、车厢和铺位。
它除非已设置并匹配
RAIL_API_KEY,否则处于禁用状态。采用失败关闭策略。本库从不记录、缓存或持久化 PNR 响应。
刻意不提供批量或枚举辅助工具。按设计,一次调用只处理一个 PNR。
如果你公开部署,请保持这种设计。请不要构建 PNR 爬虫。
数据来源与条款
所有数据均为 Indian Railways 的财产,由 Centre for Railway Information Systems (CRIS) 提供。本项目与 Indian Railways、CRIS 或 IRCTC 均无关联,也未获得其背书或支持。
部署前请阅读以下内容:
NTES 条款与条件 允许下载摘录供个人使用,并声明未经事先书面许可,你不得使用“任何软件程序”从该网站系统性地构建数据库,也不得将其页面纳入“任何公共或私人电子检索系统或服务”。他们同时声明,铁路数据“不应被用于商业目的”。
CRIS 可在收到请求后授予该许可:“本网站上展示的资料,在通过邮件向我们取得适当许可后,可免费复制。” 一份可直接发送的请求见
PERMISSION-REQUEST.md。本项目的许可状态:已申请,待批准。
IRCTC 的条款更严格,且 PNR 数据属于个人数据。
数据准确性是尽力而为的,且不提供保证——NTES 自己的免责声明也是如此。不要将其用于任何安全关键的用途;请直接与铁路部门核实。
做一个有公德心的使用者:默认配置会缓存稳定的数据、按 IP 进行限流,并复用同一个上游会话。请不要移除这些设置。
开发
npm install
npm test # parser regression tests against recorded fixtures — no network
npm run smoke # live end-to-end check against NTES and IRCTC
npm run test:mcp # drives the MCP handler locally: handshake, tools, auth, rate limit
npm run fixtures # re-record fixtures when upstream markup changes
npm run buildtest/fixtures/ 中的 fixture 文件是录制的 HTML/JSON。当 CRIS 更改其标记时,npm test 会以具体的断言失败,而不是让这些工具静默返回空结果。
许可证
MIT——参见 LICENSE。该许可证仅适用于本源代码,不适用于底层铁路数据。
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- FlicenseNot gradedqualityBmaintenanceEnables real-time Indian Railways information retrieval, including live train running status, station schedules, and upcoming arrivals/departures.
- FlicenseNot gradedqualityDmaintenanceEnables searching and tracking Indian Railways trains, checking seat availability, live status, delays, and station/train codes.26
- FlicenseNot gradedqualityBmaintenanceProvides transit concierge tools for Indian Railways, including live train status, platform numbers, delay alerts, food options, and cab services, with offline fallback support.
- FlicenseNot gradedqualityDmaintenanceEnables checking railway seat availability, berth types, and pricing for Indian trains through natural language queries.
Related MCP Connectors
iRail MCP — Belgian rail (SNCB/NMBS) real-time via the community iRail API
Real-time BART departures, trip planning, fares, stations, and advisories.
Real-time transit stops, routes, arrivals, vehicle positions, and schedules via OneBusAway APIs.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/mahi-v-v/indian-rail-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server