12306-mcp
This server provides MCP tools for querying 12306 train information, including tickets, stations, and routes.
Get the current date in Asia/Shanghai for resolving relative dates like "tomorrow".
Look up all stations in a city, city station codes, station codes by station names, and station details by telecode.
Query ticket availability and fares with optional filters (train type, time window, sorting, result limit) and text/csv/json output.
Query transfer/interline ticket plans, optionally specifying a middle station, with filtering, sorting, and text/json output.
Query detailed route information for a specific train, including stops, arrival/departure times, and dwell times.
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 Find high-speed trains from Beijing to Shanghai tomorrow"
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 车票查询工具
12306-MCP 是基于 Model Context Protocol(MCP)的 12306 车票信息查询服务。它把 12306 的余票、车次、车站与中转查询封装成标准 MCP 工具,供支持 MCP 的 AI 客户端(Cursor、Cherry Studio、通义灵码、Claude 等)通过 Stdio 或 SSE / Streamable HTTP 远程调用。
功能
查询指定日期两地之间的 12306 车票余票与票价
查询车次的具体经停站、到发时刻与历时
城市 / 站名 / 站码(telecode)互查
中转方案查询
输出格式支持 text / csv / json
内置工具:
工具 | 说明 |
| 获取上海时区(Asia/Shanghai)当前日期 |
| 查询某城市下的全部车站 |
| 批量查询城市对应站码 |
| 站名查询站码与车站信息 |
| 站码反查车站详情 |
| 查询车票余票、票价并可过滤/排序 |
| 查询中转车票方案 |
| 查询车次经停站信息 |
Related MCP server: 12306-MCP
本地使用(Stdio)
环境要求:Node.js 18 及以上。
npm ci
npm start在 MCP 客户端配置:
{
"mcpServers": {
"12306-mcp": {
"command": "node",
"args": ["/绝对路径/build/index.js"]
}
}
}也可以直接运行已发布的 npm 包:
{
"mcpServers": {
"12306-mcp": {
"command": "npx",
"args": ["-y", "12306-mcp"]
}
}
}远程使用(SSE / Streamable HTTP)
本地启动 HTTP 服务:
npm run start:http默认监听 0.0.0.0:8080(可通过 --host、--port 或环境变量 HOST、PORT 修改):
Streamable HTTP:
POST /mcpSSE:
GET /sse,消息回传POST /message
部署到魔搭(ModelScope)MCP 广场时,推荐选择 Stdio/npx 托管方式,平台会自动生成独立的 SSE 地址,无需自己维护 HTTP 服务。创建页面各项填法、可直接复制的“服务介绍”、以及三种部署方式的配置 JSON,见 魔搭部署指南。
Docker
docker build -t 12306-mcp .
# HTTP/SSE 模式
docker run -d -p 8080:8080 12306-mcp
# Stdio 模式
docker run --rm -it 12306-mcp node build/index.js注意事项
本服务无需注册 12306 账号,也无需 API Key。
服务进程启动时需要访问
kyfw.12306.cn等 12306 站点拉取车站表与查询路径;请确保运行环境(尤其云实例)能访问 12306。12306 接口存在限流与反爬策略,仅供学习与研究使用,请勿高频滥用。
参考
License
MIT
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 station lookup tools heavily overlap: get-stations-code-in-city and get-station-code-of-citys both map a city to station codes, differing only by 'all stations' vs 'representative station'. get-station-code-by-names and get-station-by-telecode add further lookup variants, making it easy for an agent to select the wrong one.
All tools use a get- prefix, which provides some consistency, but the station-related names are not parallel: get-stations-code-in-city, get-station-code-of-citys, get-station-code-by-names, and get-station-by-telecode follow inconsistent patterns. The 'citys' typo further reduces naming quality.
Eight tools is a reasonable size for a train travel assistant. However, four of those tools are dedicated to station-code lookup, which inflates the count and makes the surface feel slightly heavier than necessary.
Core workflows are covered: getting the current date, resolving station codes, querying direct tickets, querying transfer tickets, and retrieving train route stops. Minor gaps exist such as no explicit ticket price or train status tool, but agents can likely complete common travel queries.
Maintenance
Related MCP Connectors
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.
TravelMind: 8 MCP tools for travel (12306 trains, flights, hotels, geocode, planning, policy).
Flight search MCP server providing search, pagination, and itinerary details for AI assistants.
Related MCP Servers
- 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.13,273 npm2MIT
- AlicenseBqualityDmaintenance12306 ticket purchase search server based on Model Context Protocol (MCP). It provides a simple API interface, allowing large models to search for 12306 ticket purchasing information through the interface.81Apache 2.0
- 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