/ 目录 / 演练场 / 12306-mcp
● 社区 Joooook ⚡ 即开即用

12306-mcp

作者 Joooook · Joooook/12306-mcp

Query China's 12306 railway tickets via AI — search trains, check availability, and plan routes with natural language.

12306-mcp is an MCP server that connects AI assistants to China's official 12306 railway system. It supports ticket availability queries, train filtering, transit stop lookups, and multi-leg transfer planning. Runs via npx, Docker, or HTTP mode for flexible deployment.

为什么要用

核心特性

实时演示

实际使用效果

12306-mcp-2.replay ▶ 就绪
0/0

安装

选择你的客户端

~/Library/Application Support/Claude/claude_desktop_config.json  · Windows: %APPDATA%\Claude\claude_desktop_config.json
{
  "mcpServers": {
    "12306-mcp-2": {
      "command": "TODO",
      "args": [
        "See README: https://github.com/Joooook/12306-mcp"
      ]
    }
  }
}

打开 Claude Desktop → Settings → Developer → Edit Config。保存后重启应用。

~/.cursor/mcp.json · .cursor/mcp.json
{
  "mcpServers": {
    "12306-mcp-2": {
      "command": "TODO",
      "args": [
        "See README: https://github.com/Joooook/12306-mcp"
      ]
    }
  }
}

Cursor 使用与 Claude Desktop 相同的 mcpServers 格式。项目级配置优先于全局。

VS Code → Cline → MCP Servers → Edit
{
  "mcpServers": {
    "12306-mcp-2": {
      "command": "TODO",
      "args": [
        "See README: https://github.com/Joooook/12306-mcp"
      ]
    }
  }
}

点击 Cline 侧栏中的 MCP Servers 图标,然后选 "Edit Configuration"。

~/.codeium/windsurf/mcp_config.json
{
  "mcpServers": {
    "12306-mcp-2": {
      "command": "TODO",
      "args": [
        "See README: https://github.com/Joooook/12306-mcp"
      ]
    }
  }
}

格式与 Claude Desktop 相同。重启 Windsurf 生效。

~/.continue/config.json
{
  "mcpServers": [
    {
      "name": "12306-mcp-2",
      "command": "TODO",
      "args": [
        "See README: https://github.com/Joooook/12306-mcp"
      ]
    }
  ]
}

Continue 使用服务器对象数组,而非映射。

~/.config/zed/settings.json
{
  "context_servers": {
    "12306-mcp-2": {
      "command": {
        "path": "TODO",
        "args": [
          "See README: https://github.com/Joooook/12306-mcp"
        ]
      }
    }
  }
}

加入 context_servers。Zed 保存后热重载。

claude mcp add 12306-mcp-2 -- TODO 'See README: https://github.com/Joooook/12306-mcp'

一行命令搞定。用 claude mcp list 验证,claude mcp remove 卸载。

使用场景

实战用法: 12306-mcp

How to find the cheapest train between two cities with 12306-mcp

👤 Travelers planning trips within China ⏱ ~5 min beginner

何时使用: You need to compare train options between two Chinese cities and find the best deal.

前置条件
  • 12306-mcp server running — npx -y 12306-mcp
步骤
  1. Search for available trains
    Search for trains from Beijing to Shanghai tomorrow. Show me all available options with prices and seat types.✓ 已复制
    → A table of trains with departure times, durations, seat classes, and prices
  2. Filter by preference
    Which of these has second-class seats available and arrives before 6pm?✓ 已复制
    → Filtered list matching the criteria

结果: A clear comparison of train options to make a booking decision.

注意事项
  • Station names must match 12306's database exactly — Use the station search tool first to confirm the correct station name

Plan a multi-leg train journey with transfers using 12306-mcp

👤 Travelers heading to cities without direct trains ⏱ ~10 min beginner

何时使用: No direct train exists between your origin and destination.

前置条件
  • 12306-mcp server running — npx -y 12306-mcp
步骤
  1. Query transfer options
    I need to get from Chengdu to Lhasa by train. Find me transfer routes with the shortest total travel time.✓ 已复制
    → One or more transfer itineraries with intermediate stations and connection times
  2. Check availability on each leg
    Check ticket availability for each leg of the recommended route on March 15.✓ 已复制
    → Seat availability for both legs of the journey

结果: A complete multi-leg itinerary with confirmed availability.

注意事项
  • Tight transfer windows may cause missed connections — Ask Claude to filter for transfers with at least 2 hours between trains

组合

与其他 MCP 搭配,撬动十倍杠杆

12306-mcp-2 + fetch

Combine train search with web fetch to check weather at your destination before booking

Find me a train from Shanghai to Hangzhou this Saturday, and check the weekend weather forecast for Hangzhou.✓ 已复制

工具

此 MCP 暴露的能力

工具输入参数何时调用成本
query_tickets from: str, to: str, date: str Search for available train tickets between two stations 1 API call
search_stations keyword: str Look up station names and codes by keyword 1 API call
query_transfer from: str, to: str, date: str Find transfer routes when no direct train exists 1 API call
get_train_route_stations train_no: str Get all stops along a specific train's route 1 API call

成本与限制

运行它的成本

API 配额
Depends on 12306 public API rate limits — typically sufficient for personal use
每次调用 Token 数
200–800 tokens per query
费用
Free — queries the public 12306 API
提示
Batch station lookups before running ticket queries to avoid redundant calls.

安全

权限、密钥、影响范围

凭据存储: No credentials required — uses public 12306 API endpoints
数据出站: All calls go to 12306.cn official API endpoints

故障排查

常见错误与修复

Station name not found

Use the station search tool to find the exact name. Chinese station names must match the 12306 database — try both simplified Chinese and pinyin.

验证: Search for the station by keyword first
No trains found for the given date

12306 only sells tickets 15 days in advance. Ensure your date is within the booking window.

验证: Try a date within the next 15 days
Connection timeout

The 12306 API can be slow during peak booking times (e.g., Spring Festival). Retry after a few minutes.

验证: Test with a simple station search to confirm connectivity

替代方案

12306-mcp 对比其他方案

替代方案何时用它替代权衡
mcp-server-12306You want a Python-based alternative with FastAPI backend and additional price query toolsMore features (price queries, HTTP streaming) but requires Python/uv setup

更多

资源

📖 阅读 GitHub 上的官方 README

🐙 查看未解决的 issue

🔍 浏览全部 400+ MCP 服务器和 Skills