/ 目錄 / 演練場 / mcp-server-12306
● 社群 drfccv ⚡ 即開即用

mcp-server-12306

作者 drfccv · drfccv/mcp-server-12306

High-performance Python MCP server for 12306 — real-time tickets, prices, station search, train routes, and transfer planning.

mcp-server-12306 is a FastAPI-based MCP server providing real-time data from China's 12306 railway system. It offers 7 tools for ticket queries, price lookups, station search (Chinese/pinyin/abbreviation), train route stops, transfer planning, and time utilities. Supports both stdio (Claude Desktop) and Streamable HTTP modes, with Docker deployment and sub-second response times.

為什麼要用

核心特性

即時演示

實際使用效果

mcp-server-12306-2.replay ▶ 就緒
0/0

安裝

選擇你的客戶端

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

開啟 Claude Desktop → Settings → Developer → Edit Config。儲存後重啟應用。

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

Cursor 使用與 Claude Desktop 相同的 mcpServers 格式。專案級設定優先於全域。

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

點擊 Cline 側欄中的 MCP Servers 圖示,然後選 "Edit Configuration"。

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

格式與 Claude Desktop 相同。重啟 Windsurf 生效。

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

Continue 使用伺服器物件陣列,而非映射。

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

加入 context_servers。Zed 儲存後熱重載。

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

一行命令搞定。用 claude mcp list 驗證,claude mcp remove 移除。

使用場景

實戰用法: mcp-server-12306

How to compare train ticket prices for a journey with mcp-server-12306

👤 Budget-conscious travelers in China ⏱ ~5 min beginner

何時使用: You want to find the cheapest option for your train journey.

前置條件
  • mcp-server-12306 running — uvx mcp-server-12306 or Docker: docker run -p 8000:8000 drfccv/mcp-server-12306:latest
步驟
  1. Search tickets with prices
    Query tickets from Beijing to Guangzhou for tomorrow. Show all available trains with prices for each seat class.✓ 已複製
    → Table of trains with departure times, durations, and prices per seat class
  2. Get detailed pricing
    Show me the detailed pricing for train G79, including all seat types.✓ 已複製
    → Complete fare breakdown for the specific train

結果: Clear price comparison to choose the best value train.

注意事項
  • Prices may vary by date and availability — Check availability alongside prices — cheap seats sell out first

Plan a multi-city train trip across China

👤 Tourists planning a scenic route through multiple Chinese cities ⏱ ~15 min beginner

何時使用: You want to visit several cities and need to plan the train connections.

前置條件
  • mcp-server-12306 running — uvx mcp-server-12306
步驟
  1. Search stations
    Search for the main train stations in Shanghai, Hangzhou, and Suzhou. Show me the station codes.✓ 已複製
    → Station names and codes for each city
  2. Plan the route
    Find the fastest train connections for: Shanghai → Hangzhou → Suzhou → back to Shanghai, spending one day in each city. Show departure times and durations.✓ 已複製
    → Complete itinerary with train numbers and times

結果: A multi-city itinerary with all train connections planned.

注意事項
  • Small cities may only have one station — Use the station search to confirm available stations before planning

組合

與其他 MCP 搭配,撬動十倍槓桿

mcp-server-12306-2 + fetch

Check weather at your destination alongside train schedules

Find trains from Beijing to Chengdu this weekend and check the weather forecast for Chengdu.✓ 已複製

工具

此 MCP 暴露的能力

工具輸入參數何時呼叫成本
query_tickets from: str, to: str, date: str Search for available train tickets 1 API call
query_ticket_price train_no: str, from: str, to: str, date: str Get detailed pricing for a specific train 1 API call
search_stations keyword: str Search stations by name, pinyin, or abbreviation 1 API call
get_station_info station_code: str Get detailed station metadata 1 API call
query_transfer from: str, to: str, date: str Find optimal transfer routes 1 API call
get_train_route_stations train_no: str Get all stops along a train route 1 API call
get_current_time none Get current time for relative date calculations 0

成本與限制

運行它的成本

API 配額
Subject to 12306 public API rate limits
每次呼叫 Token 數
200–800 tokens per query
費用
Free — uses public 12306 API
提示
Use station search to confirm names before querying tickets to avoid wasted calls.

安全

權限、密鑰、影響範圍

憑證儲存: No credentials required
資料出站: All calls to 12306.cn official API

故障排查

常見錯誤與修復

No tickets found

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

驗證: Try today's date to confirm connectivity
Station not recognized

Use search_stations first with pinyin or Chinese to find the exact station name.

驗證: search_stations with a broader keyword
Timeout during peak hours

12306 API is slow during peak ticket sales (holidays, Spring Festival). Retry after a few minutes.

驗證: Test with a simple station search

替代方案

mcp-server-12306 對比其他方案

替代方案何時用它替代權衡
12306-mcpYou prefer a JavaScript/npx-based server with simpler setupSimpler install but fewer features (no price queries or HTTP streaming)

更多

資源

📖 閱讀 GitHub 上的官方 README

🐙 查看未解決的 issue

🔍 瀏覽全部 400+ MCP 伺服器和 Skills