12306-mcp-plus
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
12306-mcp-plus
🚄 让 AI 助手(Claude / Cursor / Codex 等)查询 12306 火车票的 MCP 服务器 —— 12306-mcp 的持续维护 fork 版。
Forked from Joooook/12306-mcp(MIT License,原作者 joooook)。 原项目自 2026-07 起停更,本仓库在其基础上修复了一批安全、正确性与协议问题。
✨ 相比原版修复了什么(v0.4.0)
问题 | 严重性 | 状态 |
默认监听 | 🔴 安全 | ✅ 默认改绑 |
未找到的站名原样回显,存在 XSS / 原型链污染风险(#74) | 🟠 安全 | ✅ 仅回显合法中文站名 + |
直达/中转查询混入同城其他站(#72) | 🔴 正确性 | ✅ 按实际起终点/中转站过滤后再排序截断 |
跨午夜车次日期算错一天、中转第二段日期自相矛盾(#72) | 🔴 正确性 | ✅ 乘车日使用查询日期;中转按"出发→到达→等待→出发"推算 |
总历时格式化为 "05:5" 而非 "05:05"(#72) | 🟡 展示 | ✅ 分钟补零 |
🔴 协议 | ✅ 懒加载 + 后台预热,请求加 15s 超时快速失败 |
Related MCP server: 12306 Train Ticket Search MCP Server
🚀 快速开始
要求:Node.js ≥ 18。
本地运行(stdio,无需参数)
git clone <你的仓库地址>
cd 12306-mcp-plus
npm install
npm run build
node build/index.jsHTTP 模式(默认只监听本机)
node build/index.js --port 8080 # 仅 127.0.0.1,安全
node build/index.js --host 0.0.0.0 --port 8080 # 暴露全部网卡,务必置于带鉴权的反向代理之后Docker
容器内必须显式使用 --host 0.0.0.0 才能被宿主机访问;建议把端口只映射到宿主机回环地址:
docker build -t 12306-mcp-plus .
docker run -p 127.0.0.1:8080:8080 12306-mcp-plus node build/index.js --host 0.0.0.0 --port 8080🔌 接入你的 AI 客户端
以 Claude Desktop 为例(claude_desktop_config.json):
{
"mcpServers": {
"12306": {
"command": "node",
"args": ["/绝对路径/12306-mcp-plus/build/index.js"]
}
}
}🧰 可用工具
get-current-date当前日期(上海时区)get-station-code-by-names车站名 → 车站代码get-station-code-of-citys城市名 → 代表站代码get-stations-code-in-city城市内全部车站get-tickets直达余票查询(支持车次/时间/历时筛选与排序)get-interline-tickets中转余票查询get-train-route-stations列车经停站查询stations资源:全部站点数据
🛡️ 安全说明
该服务没有内置鉴权,请勿直接暴露到公网;需要远程访问时请置于带鉴权的反向代理(如 Caddy/Basic Auth)之后。
默认只监听
127.0.0.1;使用--host 0.0.0.0时会打印警告。只查不买:本工具不提供、也请勿基于它实现自动下单/抢票功能,请遵守 12306 相关规定并保护账号安全。
🧪 测试
npm test测试覆盖日期推算工具(含 #72 报告中的真实车次跨午夜用例:G65→G4791、G805→G1939)。
⚠️ 免责声明
本项目调用的 12306 接口为非官方公开接口,随时可能变更或加风控,不保证持续可用。
与 12306 官方无任何关系,仅供学习交流使用。
📄 License
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
TravelMind: 8 MCP tools for travel (12306 trains, flights, hotels, geocode, planning, policy).
MCP server for China Railway 12306 ticket availability: schedules and seats by Chinese station name.
MCP server for China Railway 12306 ticket availability: schedules and seats by Chinese station name.
Mycel unified MCP gateway: China realtime data and 20 tool modules. API key required.
Related MCP Servers
- AlicenseAqualityDmaintenanceProvides tools to query flight and train information including flight searches, train tickets, weather forecasts, and transfer options between different transportation modes.951 npm3ISC
- AlicenseNot gradedqualityDmaintenanceEnables searching for train tickets on China's 12306 railway system, including ticket availability queries, train filtering, station stopover information, and transfer route planning.9,691 npm2MIT
- FlicenseNot gradedqualityDmaintenanceEnables real-time flight and train ticket queries, dynamic trip tracking, and knowledge-based Q&A about rail and aviation policies.-
- FlicenseNot gradedqualityDmaintenanceEnables querying train and high-speed rail schedules, durations, and seat availability between Chinese stations using 12306 data, with automatic fallback to simulated data when the API is rate-limited.-