
Mcp Server 12306
io.github.drfccvPublished by GitHub account drfccvv0.3.1Updated Oct 24, 2026
An MCP server that provides 12306 ticket query
Overview
A local MCP server that lets an assistant query China Railway 12306 train tickets, prices, stations, transfers and stop schedules.
- What you can do
- Query remaining tickets, train numbers, seat classes and departure times for a route and date, with optional filtering by train number and real-time fares per seat class for each train, plus official transfer itineraries with full paths and waiting times, and all stop stations and arrival/departure times for a given train, and look up the official unique number for a train code, and search the national station list by Chinese name, pinyin, initials or three-letter code, and get the current time in any time zone and relative date calculations to help pick a travel date.
- When to use it
- Useful when an assistant should help plan rail travel in China: checking availability and fares for a route and date, comparing direct trains with transfer options, or looking up station names and stop schedules.
- Requirements
- Runs locally as a Python package (Python 3.10 to below 3.14) via uvx, pip or pipx, or as a Docker image; network access to the official 12306 interfaces is required. An optional HTTP mode listens on port 8000 and is configured with SERVER_HOST, SERVER_PORT, DEBUG and LOG_LEVEL. No accounts or API keys are declared.
Installation
In SourceWeft
- Open Mcp Server 12306 in the dashboard and add it to a workspace.
- Enable the server for the chats that should use its tools.
Desktop only via STDIO. STDIO servers start a local process, so they need the SourceWeft desktop host.
Other MCP clients
Follow the launch instructions in the repository.
README
🚄 MCP Server 12306
基于 Model Context Protocol (MCP) 的 12306 火车票查询服务
[PyPI - Version] [PyPI - Downloads] [Python - 3.10+] [Docker - Pulls] [License - MIT] [MCP - SDK v2] [Transport - Stdio/HTTP] [GitHub - Stars]
支持 余票 / 票价 / 车站 / 经停 / 换乘 / 时间 六大查询能力,开箱即用,适配 AI 助手、自动化脚本、智能终端等场景。
📑 目录
✨ 功能特性
🚀 快速开始
环境要求
💡 推荐使用
uv:环境隔离、安装快、锁文件管理依赖版本。
方式一:Stdio 模式(本地客户端推荐)
MCP Server 通过标准输入/输出与客户端通信,不占用网络端口,适合 Claude Desktop、Cursor 等本地 MCP 客户端。
安装:
客户端配置(如 claude_desktop_config.json):
其他安装方式(点击展开)
pipx:
本地源码(开发者调试):
方式二:Streamable HTTP 模式(远程部署)
Server 启动 Web 服务(默认
8000端口),通过 MCP Streamable HTTP 协议通信:POST发送 JSON-RPC、GET订阅流式响应、DELETE结束会话。
启动:
客户端配置:
内置 HTTP 端点:
方式三:Docker 部署
🛠️ 工具一览
📖 每个工具的参数说明、返回示例、调用示例详见 📚 详细文档。
⚙️ 配置项
通过环境变量或项目根目录 .env 文件配置:
🏗️ 项目结构
🧑💻 开发指南
架构要点:
server.py是传输无关的核心模块——工具注册(TOOL_HANDLERS)与业务分发(call_tool)都在此,stdio 与 HTTP 复用同一实例,保证两种模式行为完全一致。- 工具 Schema 单一来源于
ticket_service.MCP_TOOLS,HTTP 的/schema/tools端点与 MCP 工具列表同源。 - 网络请求统一走
_request_with_retry(自动重试 + init 会话保持),业务错误与网络错误分离处理。
📚 详细文档
每份文档均包含:功能说明、实现方法、请求参数、返回示例与典型调用方式。
⚠️ 免责声明
- 本项目仅供学习、研究与技术交流,严禁用于任何商业用途。
- 本项目不存储、不篡改、不传播任何 12306 官方数据,仅作为官方公开接口的智能聚合与转发。
- 使用本项目造成的任何后果(包括但不限于账号封禁、数据异常、法律风险等)均由使用者本人承担,项目作者不承担任何责任。
- 请遵守中国法律法规及 12306 官方相关规定,合理合规使用。
📄 License
⭐ 如果这个项目对你有帮助,欢迎 Star 支持!
Source: README.md at commit 7993e3d
Tools
0Version history
1- v0.3.1LatestSep 16, 2026
Score
50% of the applicable checks met
How complete this listing is, computed from the registry entry, the endpoint and public sources. Not a rating of the server and not a statement that it is safe or working today: reachability is a dated check, and no installs or reviews go into the score.
- Reached in the last 30 days25 pts
Keep the endpoint answering the MCP handshake; SourceWeft probes it every 30 days.
- Auth declared10 pts
Declare the credential headers in the registry entry, or keep the endpoint answering the probe so its auth can be classified.
- Tools listed15 pts
Answer tools/list without a credential, or ship a package that starts in a sandbox without one.
- DescriptionRequired15 pts
- Logo10 pts
- Documentation15 pts
- License10 pts