12306-mcp is a Model Context Protocol (MCP) server that retrieves real-time ticket data from China's 12306 railway system. It provides large language models with a structured API to access train schedules, seat availability, station lookups, and route planning. Because it operates over the Model Context Protocol, it eliminates the need for fragile browser automation or screen scraping, delivering clean, machine-readable data directly to the AI.
Parameters:
{
"date": "2025-04-15",
"from_station": "BJP",
"to_station": "SHH"
}
Sample Response:
G103 北京南 (Beijing South) -> 上海虹桥 (Shanghai Hongqiao) 06:20 -> 11:58 Duration: 05:38
Business Class: 20 seats ¥1998
First Class: Available ¥969
Second Class: Available ¥576
G1 北京南 (Beijing South) -> 上海 (Shanghai) 07:00 -> 11:29 Duration: 04:29
Business Class: 8 seats ¥2331
First Class: 2 seats ¥1067
Second Class: Sold out ¥667
Preferred First Class: 2 seats ¥1467
G105 北京南 (Beijing South) -> 上海虹桥 (Shanghai Hongqiao) 07:17 -> 13:03 Duration: 05:46
Business Class: 7 seats ¥1873
First Class: Available ¥930
Second Class: Sold out ¥553
G107 北京南 (Beijing South) -> 上海虹桥 (Shanghai Hongqiao) 07:25 -> 13:12 Duration: 05:47
Business Class: 5 seats ¥2158
First Class: Sold out ¥1006
Parameters:
{
"city": "上海"
}
Sample Response:
[
{"station_code":"LTU","station_name":"练塘"},
{"station_code":"SHH","station_name":"上海"},
{"station_code":"SNH","station_name":"上海南"},
{"station_code":"AOH","station_name":"上海虹桥"},
{"station_code":"SXH","station_name":"上海西"},
...
]
Clone and Install
git clone https://github.com/Joooook/12306-mcp.git
cd 12306-mcp
npm i
Run the Server
You can use npx for an immediate start:
npx -y 12306-mcp
MCP Configuration
To integrate the server with your MCP client (such as Claude Desktop or a Gemini environment), add the following to your configuration file (e.g., ~/.gemini/settings.json):
{
"mcpServers": {
"12306-mcp": {
"command": "npx",
"args": [
"-y",
"12306-mcp"
]
}
}
}
The system is organized into a four-layer stack. At the top level, the user or LLM interacts with high-level tools like get-tickets and get-station-codes-by-city. Beneath this, the core tool layer handles the specific query logic and formats the raw data into readable responses. The MCP server acts as the bridge between these internal tools and the external environment, translating incoming requests for the 12306 API. This design ensures that data remains clean and structured, removing the need for HTML parsing or CAPTCHA handling. By abstracting these complexities, the server allows the LLM to focus on answering complex user prompts, such as: "Find me afternoon trains from Beijing to Shanghai with available first-class seats."
PromptEnhancer: Rewrite Any Prompt for Stunning AI Images
Tempurai Coder Review: An AI Terminal Assistant That Plans Before It Acts
Grok CLI: AI-Powered Terminal Assistant for Files and Bash Commands
LetsMarkdown: Lightweight Collaborative Markdown Editor Powered by Rust
Apple Doc MCP: SwiftUI & UIKit Documentation for Cursor & Claude
MemoryOS: Equip AI Agents with Persistent Recall via a Memory Hierarchy
Seelen UI Setup: Customizing the Windows Desktop with YAML and Tiling
Chinese Wikipedia Corpus: Processing 990k Articles for NLP Tasks
Notes MCP Guide: Connect Apple Notes to Claude, Cursor, and LLMs
DeerFlow: Modular Multi-Agent Research With LangGraph and MCP
ChatWiki: Open-Source AI Knowledge Base Q&A System
Dragon Ball RPG “Peak of Power” Review: Best Teams, Goku Skills, and F2P Guide