12306-mcp-plus
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@12306-mcp-plus 查一下明天北京到上海的高铁余票"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
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
Available Tools
8 toolsget-current-dateA
获取当前日期,以上海时区(Asia/Shanghai, UTC+8)为准,返回格式为 "yyyy-MM-dd"。主要用于解析用户提到的相对日期(如“明天”、“下周三”),提供准确的日期输入。
Inputs: no named parameters.
get-interline-ticketsB
查询12306中转余票信息。尚且只支持查询前十条。
Inputs: date (required), toStation (required), fromStation (required), format, +8 more.
get-station-by-telecodeA
通过车站的 station_telecode 查询车站的详细信息,包括名称、拼音、所属城市等。此接口主要用于在已知 telecode 的情况下获取更完整的车站数据,或用于特殊查询及调试目的。一般用户对话流程中较少直接触发。
Inputs: stationTelecode (required).
get-station-code-by-namesA
通过具体的中文车站名查询其 station_code 和车站名。
Inputs: stationNames (required).
get-station-code-of-citysB
通过中文城市名查询代表该城市的 station_code。
Inputs: citys (required).
get-stations-code-in-cityB
通过中文城市名查询该城市 所有 火车站的名称及其对应的 station_code,结果是一个包含多个车站信息的列表。
Inputs: city (required).
get-ticketsB
查询12306余票信息。
Inputs: date (required), toStation (required), fromStation (required), format, +6 more.
get-train-route-stationsA
查询特定列车车次在指定区间内的途径车站、到站时间、出发时间及停留时间等详细经停信息。当用户询问某趟具体列车的经停站时使用此接口。
Inputs: trainCode (required), departDate (required), format.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 8 tools
The four station-lookup tools have overlapping intent: `get-stations-code-in-city` (all stations in a city) and `get-station-code-of-citys` (representative station_code for a city) sound nearly identical and an agent could easily pick the wrong one. Descriptions do differentiate them once read carefully, and `get-station-by-telecode` is explicitly marked as rare/debug, but the boundaries are not immediately clear from the names.
All tools use a consistent kebab-case `get-*` prefix with a noun phrase, which is predictable. Minor blemishes: inconsistent pluralization (`get-stations-code-in-city` vs `get-station-code-of-citys`) and the grammatically odd `citys`.
Eight tools is a well-scoped set for a 12306 ticket-query server, falling squarely in the healthy 3-15 range. Each tool maps to a distinct step in the workflow: date resolution, station resolution, ticket search, transfer search, and route lookup.
The core query workflow (resolve relative date → resolve city/station codes → query remaining tickets → check transfers → inspect train stops) is fully covered for a read-only booking-domain server. Minor gaps exist: no seat price/seat-type detail endpoint, no train-number/type lookup beyond route stations, and station resolution is redundantly covered by four tools while train metadata is thin; booking is presumably out of scope.
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.93ISC
- 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.2MIT
- 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.-
- AlicenseNot gradedqualityCmaintenanceEnables AI agents to query public China Railway 12306 information via MCP, including station lookup, ticket availability, transfer planning, and train route details. It does not support login, booking, or payment.MIT