Skip to main content

mcp_12306

项目简介

mcp_12306 是一个基于 MCP(Model Context Protocol)协议的 12306 火车票查询服务端项目。
它支持通过自然语言或 API 查询中国铁路 12306 的余票信息、车站代码等,并支持 Redis 缓存加速查询。

主要功能

  • 火车票余票查询
    支持指定出发站、到达站、出发日期、乘客类型(成人/学生)等参数,查询 12306 实时余票信息。

  • 车站代码/名称查询
    可根据车站中文名查询对应的 12306 车站代码,或反查车站名称。

  • Redis 缓存支持
    查询结果可自动缓存到 Redis,提升高频查询性能。

  • MCP 工具集成
    以工具(tool)的形式对外暴露接口,便于 LLM/自动化系统集成。

  • 命令行参数灵活
    支持自定义服务端口、传输方式(stdio/sse)、是否启用 Redis 等。


安装与运行

1. 安装依赖

uv pip install mcp-12306

2. 启动 Redis(可选)

如需启用 Redis 缓存,需先启动本地 Redis 服务(默认端口 6379)。

# Linux
redis-server

# Windows(需提前安装 Redis for Windows 或 Memurai)
redis-server.exe

3. 启动服务

3.1 python 启动

进入 mcp_12306 目录后,使用以下命令启动服务:

python -m mcp_12306 --redis 6379

3.2 uvx 启动

不带 Redis 启动:

uvx mcp-12306

带 Redis 启动:

uvx mcp-12306 --redis 6379
  • --redis:指定 Redis 端口,不填则不启用 Redis

主要接口/工具

  • query_tickets:查询火车票信息
    • 参数:from_station(出发站),to_station(到达站),train_date(出发日期),purpose_codes(乘客类型)
  • get_station_code:获取车站代码
    • 参数:station_name(车站中文名)
  • get_station_name:获取车站名称
    • 参数:station_code(车站代码)

项目结构

 mcp_12306/
    ├── LICENSE
    ├── mcp_12306/
    │   ├── __init__.py
    │   ├── __main__.py
    │   ├── mcp_12306_server.py
    │   ├── query_12306.py
    │   └── station.txt
    ├── mcp_12306.egg-info/
    ├── pyproject.toml
    ├── README.md
    └── uv.lock

后续工作计划

  • 支持更多 12306 查询接口
    • 车次时刻表
    • 列车中转查询
  • 增强异常处理与日志记录
  • 提供 Web UI 或 API 文档
  • 支持 Docker 一键部署
  • 国际化与多语言支持

贡献与反馈

如有疑问可联系维护者:zhengchenguang315@gmail.com


Metadata

Release files for mcp-12306 0.1.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for mcp-12306 0.1.8
File Interpreter ABI Platform
mcp_12306-0.1.8-py3-none-any.whl Python 3 none any Details

Release files / mcp_12306-0.1.8-py3-none-any.whl

Download URL mcp_12306-0.1.8-py3-none-any.whl
Size 87.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
efe3b8b1d58de01296590cf7419c9251569320649a125ab449e84911579491ca
BLAKE2b-256 checksum
How to use checksums
7aac26a76d02ee24a096bf525f4c38e1751a97bb3a9a2297ddd30123b6b1cca7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5

Security for mcp-12306 0.1.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page