Skip to main content
Glama
12306-mcp
by Joooook

12306-mcp

A 12306 ticket search server based on the Model Context Protocol (MCP). The server provides a simple API interface that allows users to search for 12306 tickets.

基于 Model Context Protocol (MCP) 的12306购票搜索服务器。提供了简单的API接口,允许大模型利用接口搜索12306购票信息。

如需Skill -> https://github.com/Joooook/12306-skill

🚩Features

功能描述

状态

查询12306购票信息

✅ 已完成

过滤列车信息

✅ 已完成

过站查询

✅ 已完成

中转查询

✅ 已完成

其余接口,欢迎提feature

🚧 计划内

Related MCP server: 12306 Train Ticket Search MCP Server

⚙️Installation

git clone https://github.com/Joooook/12306-mcp.git
npm i

▶️Quick Start

CLI-stdio

npx -y 12306-mcp

CLI-http

npx -y 12306-mcp --port [端口号]

Runtime requirements

The server requires Node.js 18 or newer. The npm run debug command uses MCP Inspector 2.0.0, which requires Node.js 22.19.0 or newer.

MCP sever configuration

{
    "mcpServers": {
        "12306-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "12306-mcp"
            ]
        }
    }
}

Docker-stdio

docker build . -t 12306-mcp
docker run --rm -it 12306-mcp npx 12306-mcp

Docker-http

docker build . -t 12306-mcp
docker run -p [your_port]:8080 -d 12306-mcp npx 12306-mcp --port 8080

📚Documentation

👉️Reference

💭Murmurs

本项目仅用于学习,欢迎催更。

🎫Badges

☕️Donate

请我喝杯奶茶吧。

Available Tools

8 tools
get-current-dateA

获取当前日期,以上海时区(Asia/Shanghai, UTC+8)为准,返回格式为 "yyyy-MM-dd"。主要用于解析用户提到的相对日期(如“明天”、“下周三”),提供准确的日期输入。

NameRequiredDescriptionDefault

No parameters

get-interline-ticketsB

查询12306中转余票信息。尚且只支持查询前十条。

NameRequiredDescriptionDefault
dateYes查询日期,格式为 "yyyy-MM-dd"。如果用户提供的是相对日期(如“明天”),请务必先调用 `get-current-date` 接口获取当前日期,并计算出目标日期。
formatNo返回结果格式,默认为text,建议使用text。可选标志:[text, json]text
showWZNo是否显示无座车,默认不显示无座车。
sortFlagNo排序方式,默认为空,即不排序。仅支持单一标识。可选标志:[startTime(出发时间从早到晚), arriveTime(抵达时间从早到晚), duration(历时从短到长)]
toStationYes到达地的中文名或站点的 `station_code`(可通过 `get-station-code-by-names` 或 `get-station-code-of-citys` 接口查询得到)
limitedNumNo返回的中转余票数量限制,默认为10。
fromStationYes出发地的中文名或站点的 `station_code`(可通过 `get-station-code-by-names` 或 `get-station-code-of-citys` 接口查询得到)
sortReverseNo是否逆向排序结果,默认为false。仅在设置了sortFlag时生效。
middleStationNo中转地的中文或站点的 `station_code`(可通过 `get-station-code-by-names` 或 `get-station-code-of-citys` 接口查询得到)。该参数可选。
latestStartTimeNo最迟出发时间(0-24),默认为24。
trainFilterFlagsNo车次筛选条件,默认为空。从以下标志中选取多个条件组合[G(高铁/城际),D(动车),Z(直达特快),T(特快),K(快速),O(其他),F(复兴号),S(智能动车组)]
earliestStartTimeNo最早出发时间(0-24),默认为0。
get-station-by-telecodeA

通过车站的 station_telecode 查询车站的详细信息,包括名称、拼音、所属城市等。此接口主要用于在已知 telecode 的情况下获取更完整的车站数据,或用于特殊查询及调试目的。一般用户对话流程中较少直接触发。

NameRequiredDescriptionDefault
stationTelecodeYes车站的 `station_telecode` (3位字母编码)
get-station-code-by-namesA

通过具体的中文车站名查询其 station_code 和车站名。

NameRequiredDescriptionDefault
stationNamesYes具体的中文车站名称,例如:"北京南", "上海虹桥"。若要查询多个站点,请用|分割,比如"北京南|上海虹桥"。
get-station-code-of-citysB

通过中文城市名查询代表该城市的 station_code。

NameRequiredDescriptionDefault
citysYes要查询的城市,比如"北京"。若要查询多个城市,请用|分割,比如"北京|上海"。
get-stations-code-in-cityB

通过中文城市名查询该城市 所有 火车站的名称及其对应的 station_code,结果是一个包含多个车站信息的列表。

NameRequiredDescriptionDefault
cityYes中文城市名称,例如:"北京", "上海"
get-ticketsB

查询12306余票信息。

NameRequiredDescriptionDefault
dateYes查询日期,格式为 "yyyy-MM-dd"。如果用户提供的是相对日期(如“明天”),请务必先调用 `get-current-date` 接口获取当前日期,并计算出目标日期。
formatNo返回结果格式,默认为text,建议使用text与csv。可选标志:[text, csv, json]text
sortFlagNo排序方式,默认为空,即不排序。仅支持单一标识。可选标志:[startTime(出发时间从早到晚), arriveTime(抵达时间从早到晚), duration(历时从短到长)]
toStationYes到达地的中文名或站点的 `station_code`(可通过 `get-station-code-by-names` 或 `get-station-code-of-citys` 接口查询得到)
limitedNumNo返回的余票数量限制,默认为0,即不限制。
fromStationYes出发地的中文名或站点的 `station_code`(可通过 `get-station-code-by-names` 或 `get-station-code-of-citys` 接口查询得到)
sortReverseNo是否逆向排序结果,默认为false。仅在设置了sortFlag时生效。
latestStartTimeNo最迟出发时间(0-24),默认为24。
trainFilterFlagsNo车次筛选条件,默认为空,即不筛选。支持多个标志同时筛选。例如用户说“高铁票”,则应使用 "G"。可选标志:[G(高铁/城际),D(动车),Z(直达特快),T(特快),K(快速),O(其他),F(复兴号),S(智能动车组)]
earliestStartTimeNo最早出发时间(0-24),默认为0。
get-train-route-stationsA

查询特定列车车次在指定区间内的途径车站、到站时间、出发时间及停留时间等详细经停信息。当用户询问某趟具体列车的经停站时使用此接口。

NameRequiredDescriptionDefault
formatNo返回结果格式,默认为text,建议使用text。可选标志:[text, json]text
trainCodeYes要查询的车次 `train_code`,例如"G1033"。
departDateYes列车出发的日期 (格式: yyyy-MM-dd)。如果用户提供的是相对日期,请务必先调用 `get-current-date` 解析。

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 2 tool updatesv0.2.1
    • Changedget-interline-tickets3 fields changed
      • changedInput schema / properties / fromStation / description
        Previous value: -"出发地的 `station_code` 。必须是通过 `get-station-code-by-names` 或 `get-station-code-of-citys` 接口查询得到的编码,严禁直接使用中文地名。"New value: +"出发地的中文名或站点的 `station_code`(可通过 `get-station-code-by-names` 或 `get-station-code-of-citys` 接口查询得到)"
      • changedInput schema / properties / middleStation / description
        Previous value: -"中转地的 `station_code` ,可选。必须是通过 `get-station-code-by-names` 或 `get-station-code-of-citys` 接口查询得到的编码,严禁直接使用中文地名。"New value: +"中转地的中文或站点的 `station_code`(可通过 `get-station-code-by-names` 或 `get-station-code-of-citys` 接口查询得到)。该参数可选。"
      • changedInput schema / properties / toStation / description
        Previous value: -"出发地的 `station_code` 。必须是通过 `get-station-code-by-names` 或 `get-station-code-of-citys` 接口查询得到的编码,严禁直接使用中文地名。"New value: +"到达地的中文名或站点的 `station_code`(可通过 `get-station-code-by-names` 或 `get-station-code-of-citys` 接口查询得到)"
    • Changedget-tickets2 fields changed
      • changedInput schema / properties / fromStation / description
        Previous value: -"出发地的 `station_code` 。必须是通过 `get-station-code-by-names` 或 `get-station-code-of-citys` 接口查询得到的编码,严禁直接使用中文地名。"New value: +"出发地的中文名或站点的 `station_code`(可通过 `get-station-code-by-names` 或 `get-station-code-of-citys` 接口查询得到)"
      • changedInput schema / properties / toStation / description
        Previous value: -"到达地的 `station_code` 。必须是通过 `get-station-code-by-names` 或 `get-station-code-of-citys` 接口查询得到的编码,严禁直接使用中文地名。"New value: +"到达地的中文名或站点的 `station_code`(可通过 `get-station-code-by-names` 或 `get-station-code-of-citys` 接口查询得到)"
  2. 4 tool updatesv1.0.0
    • Changedget-current-date1 field changed
      • removedInput schema / additionalProperties
        Removed value: -false
    • Changedget-interline-tickets3 fields changed
      • addedInput schema / properties / earliestStartTime
        Added value: +{
        +  "default": 0,
        +  "description": "最早出发时间(0-24),默认为0。",
        +  "maximum": 24,
        +  "minimum": 0,
        +  "type": "number"
        +}
      • addedInput schema / properties / format
        Added value: +{
        +  "default": "text",
        +  "description": "返回结果格式,默认为text,建议使用text。可选标志:[text, json]",
        +  "pattern": "^(text|json)$",
        +  "type": "string"
        +}
      • addedInput schema / properties / latestStartTime
        Added value: +{
        +  "default": 24,
        +  "description": "最迟出发时间(0-24),默认为24。",
        +  "maximum": 24,
        +  "minimum": 0,
        +  "type": "number"
        +}
    • Changedget-tickets3 fields changed
      • addedInput schema / properties / earliestStartTime
        Added value: +{
        +  "default": 0,
        +  "description": "最早出发时间(0-24),默认为0。",
        +  "maximum": 24,
        +  "minimum": 0,
        +  "type": "number"
        +}
      • addedInput schema / properties / format
        Added value: +{
        +  "default": "text",
        +  "description": "返回结果格式,默认为text,建议使用text与csv。可选标志:[text, csv, json]",
        +  "pattern": "^(text|csv|json)$",
        +  "type": "string"
        +}
      • addedInput schema / properties / latestStartTime
        Added value: +{
        +  "default": 24,
        +  "description": "最迟出发时间(0-24),默认为24。",
        +  "maximum": 24,
        +  "minimum": 0,
        +  "type": "number"
        +}
    • Changedget-train-route-stations7 fields changed
      • changedInput schema / properties / departDate / description
        Previous value: -"列车从 `fromStationTelecode` 指定的车站出发的日期 (格式: yyyy-MM-dd)。如果用户提供的是相对日期,请务必先调用 `get-current-date` 解析。"New value: +"列车出发的日期 (格式: yyyy-MM-dd)。如果用户提供的是相对日期,请务必先调用 `get-current-date` 解析。"
      • addedInput schema / properties / format
        Added value: +{
        +  "default": "text",
        +  "description": "返回结果格式,默认为text,建议使用text。可选标志:[text, json]",
        +  "pattern": "^(text|json)$",
        +  "type": "string"
        +}
      • removedInput schema / properties / fromStationTelecode
        Removed value: -{
        -  "description": "该列车行程的**出发站**的 `station_telecode` (3位字母编码`)。通常来自 `get-tickets` 结果中的 `telecode` 字段,或者通过 `get-station-code-by-names` 得到。",
        -  "type": "string"
        -}
      • removedInput schema / properties / toStationTelecode
        Removed value: -{
        -  "description": "该列车行程的**到达站**的 `station_telecode` (3位字母编码)。通常来自 `get-tickets` 结果中的 `telecode` 字段,或者通过 `get-station-code-by-names` 得到。",
        -  "type": "string"
        -}
      • addedInput schema / properties / trainCode
        Added value: +{
        +  "description": "要查询的车次 `train_code`,例如\"G1033\"。",
        +  "type": "string"
        +}
      • removedInput schema / properties / trainNo
        Removed value: -{
        -  "description": "要查询的实际车次编号 `train_no`,例如 \"240000G10336\",而非\"G1033\"。此编号通常可以从 `get-tickets` 的查询结果中获取,或者由用户直接提供。",
        -  "type": "string"
        -}
      • changedInput schema / required
        Previous value: -[
        -  "trainNo",
        -  "fromStationTelecode",
        -  "toStationTelecode",
        -  "departDate"
        -]New value: +[
        +  "trainCode",
        +  "departDate"
        +]
  3. 8 tool updates
    • First observedget-current-date
    • First observedget-interline-tickets
    • First observedget-station-by-telecode
    • First observedget-station-code-by-names
    • First observedget-station-code-of-citys
    • First observedget-stations-code-in-city
    • First observedget-tickets
    • First observedget-train-route-stations

TDQS

A3.5/5.0

Scored across 8 tools

Disambiguation4/5

Most tools have distinct purposes (date, tickets, interline tickets, station queries by different criteria, train route). However, get-station-code-by-names and get-station-code-of-citys could be confused as both involve station codes, but descriptions clarify the input type.

Naming Consistency3/5

All tools follow get-<resource>-<detail> pattern with snake_case, but there are inconsistencies: 'citys' is a typo, and some use singular 'station' while others use plural 'stations' (e.g., get-stations-code-in-city vs get-station-code-by-names).

Tool Count4/5

8 tools cover core query needs for a train information server (date, tickets, stations, routes). Not excessive or insufficient, though a tool for train number details might be expected.

Completeness4/5

Covers essential queries: date, tickets, interline tickets, station codes by multiple methods, station details, and train routes. Missing price or order-related queries, but the scope is focused on info retrieval.

Maintenance

ActivityInactive
ResponsivenessMixed handling

Related MCP Connectors

Related MCP Servers

  • A
    license
    A
    quality
    D
    maintenance
    A Model Context Protocol server that allows large language models to search for and analyze Chinese railway (12306) tickets through a simple API interface.
    8
    15,543 npm
    19
    MIT
  • A
    license
    B
    quality
    D
    maintenance
    12306 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.
    8
    1
    Apache 2.0