用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/Aradotso/mcp-skills --skill mcp-server-12306命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
| name | mcp-server-12306 |
| description | MCP server for querying China Railway 12306 train tickets, stations, transfers, and schedules in real-time |
| triggers | ["how do I query train tickets in China","set up 12306 MCP server for train information","search for railway stations by name or pinyin","find train transfer connections between cities","check train ticket prices and availability","get train route and schedule information","query China railway data through MCP","integrate 12306 train queries with AI assistant"] |
Skill by ara.so — MCP Skills collection.
MCP Server 12306 is a Model Context Protocol server that provides real-time access to China Railway 12306 data including train tickets, station information, transfers, prices, and schedules. Built with FastAPI for high-performance async operations.
This MCP server exposes tools for:
Add to your Claude Desktop configuration file:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"12306": {
"command": "uvx",
"args": ["mcp-server-12306"]
}
}
}
{
"mcpServers": {
"12306": {
"command": "pipx",
"args": ["run", "--no-cache", "mcp-server-12306"]
}
}
}
{
"mcpServers": {
"12306": {
"command": "uv",
"args": ["run", "python", "-m", "mcp_12306.cli"],
"cwd": "/path/to/mcp-server-12306"
}
}
}
git clone https://github.com/drfccv/mcp-server-12306.git
cd mcp-server-12306
uv sync
uv run python scripts/start_server.py
Then configure your MCP client:
{
"mcpServers": {
"12306": {
"url": "http://localhost:8000/mcp"
}
}
}
docker run -d -p 8000:8000 --name mcp-server-12306 drfccv/mcp-server-12306:latest
Search for available train tickets between stations.
Parameters:
from_station (string, required): Departure station name (Chinese or pinyin)to_station (string, required): Arrival station name (Chinese or pinyin)train_date (string, required): Travel date in YYYY-MM-DD formatpurpose_codes (string, optional): "ADULT" (default) or "0X00" for student ticketsExample usage:
# Search tickets from Beijing to Shanghai on a specific date
result = await mcp_client.call_tool("query_tickets", {
"from_station": "北京",
"to_station": "上海",
"train_date": "2025-06-15",
"purpose_codes": "ADULT"
})
Response includes:
Get real-time ticket prices for a specific train.
Parameters:
train_no (string, required): Train number (e.g., "G101")from_station_no (string, required): Departure station codeto_station_no (string, required): Arrival station codeseat_types (string, required): Comma-separated seat type codestrain_date (string, required): Travel date in YYYY-MM-DD formatExample usage:
# Get prices for train G101
result = await mcp_client.call_tool("query_ticket_price", {
"train_no": "G101",
"from_station_no": "BJP",
"to_station_no": "SHH",
"seat_types": "9,M,O",
"train_date": "2025-06-15"
})
Response includes:
Search for railway stations by name, pinyin, or abbreviation.
Parameters:
keyword (string, required): Search term (Chinese, pinyin, or abbreviation)Example usage:
# Search stations containing "beijing"
result = await mcp_client.call_tool("search_stations", {
"keyword": "beijing"
})
# Also works with Chinese
result = await mcp_client.call_tool("search_stations", {
"keyword": "北京"
})
Response includes:
Get detailed information about a specific station.
Parameters:
station_name (string, required): Exact station name or codeExample usage:
result = await mcp_client.call_tool("get_station_info", {
"station_name": "北京南"
})
Find one-transfer routes between cities (when no direct train available).
Parameters:
from_station (string, required): Departure stationto_station (string, required): Arrival stationtrain_date (string, required): Travel date in YYYY-MM-DD formatpurpose_codes (string, optional): Ticket typeExample usage:
# Find transfer routes from Beijing to Guilin
result = await mcp_client.call_tool("query_transfer", {
"from_station": "北京",
"to_station": "桂林",
"train_date": "2025-06-20",
"purpose_codes": "ADULT"
})
Response includes:
Query all stops and schedule for a specific train.
Parameters:
train_no (string, required): Train numberfrom_station_telecode (string, required): Origin station codeto_station_telecode (string, required): Destination station codedepart_date (string, required): Departure date in YYYY-MM-DD formatExample usage:
result = await mcp_client.call_tool("get_train_route_stations", {
"train_no": "G101",
"from_station_telecode": "BJP",
"to_station_telecode": "SHH",
"depart_date": "2025-06-15"
})
Response includes:
Get current time and calculate relative dates for booking.
Parameters:
timezone (string, optional): Timezone (default: "Asia/Shanghai")Example usage:
result = await mcp_client.call_tool("get_current_time", {
"timezone": "Asia/Shanghai"
})
Response includes:
# 1. Get current time to determine valid booking dates
time_info = await client.call_tool("get_current_time", {})
travel_date = time_info["dates"]["tomorrow"]
# 2. Search for station codes if needed
stations = await client.call_tool("search_stations", {
"keyword": "beijing"
})
from_code = stations[0]["code"]
stations = await client.call_tool("search_stations", {
"keyword": "shanghai"
})
to_code = stations[0]["code"]
# 3. Query available tickets
tickets = await client.call_tool("query_tickets", {
"from_station": "北京",
"to_station": "上海",
"train_date": travel_date,
"purpose_codes": "ADULT"
})
# 4. Get price for specific train
if tickets["trains"]:
train = tickets["trains"][0]
prices = await client.call_tool("query_ticket_price", {
"train_no": train["station_train_code"],
"from_station_no": train["from_station_telecode"],
"to_station_no": train["to_station_telecode"],
"seat_types": train["seat_types"],
"train_date": travel_date
})
# When no direct trains available, query transfers
transfers = await client.call_tool("query_transfer", {
"from_station": "拉萨",
"to_station": "厦门",
"train_date": "2025-07-01",
"purpose_codes": "ADULT"
})
# Each result shows:
# - First train to transfer city
# - Layover duration
# - Second train to final destination
for route in transfers["transfer_routes"]:
print(f"Transfer at: {route['transfer_station']}")
print(f"Layover: {route['layover_minutes']} minutes")
print(f"Total duration: {route['total_duration']}")
# Get complete route for a train
route = await client.call_tool("get_train_route_stations", {
"train_no": "G7",
"from_station_telecode": "BJP",
"to_station_telecode": "SHH",
"depart_date": "2025-06-15"
})
# Shows all stops with arrival/departure times
for stop in route["stations"]:
print(f"{stop['station_name']}: {stop['arrive_time']} - {stop['start_time']}")
The server uses default 12306 public APIs and doesn't require API keys. However, you can configure:
PORT environment variable (default: 8000)get_current_time tool (default: "Asia/Shanghai")The server includes a pre-built station database. To update:
cd scripts
uv run python update_station_data.py
This fetches the latest station list from 12306 and updates src/mcp_12306/data/station_names.json.
src/mcp_12306/
├── server.py # FastAPI main entry point
├── services/
│ ├── ticket_service.py # Ticket query logic
│ ├── station_service.py # Station search logic
│ └── http_service.py # 12306 API client
├── utils/
│ ├── config.py # Configuration
│ └── logger.py # Logging
├── data/
│ └── station_names.json # Station database
scripts/
├── start_server.py # HTTP mode launcher
└── update_station_data.py # Station data updater
The station database uses exact matching. Use search_stations first to find the correct station name:
# Search before querying
results = await client.call_tool("search_stations", {
"keyword": "beijing"
})
# Use the exact name from results
station_name = results[0]["name"]
get_current_time to get valid booking datesquery_transfer for indirect routesuv run python scripts/start_server.py)-p 8000:8000uvx or pipx is installed: uvx --versioncwd points to correct directoryThe 12306 API may rate-limit requests. The server includes basic retry logic, but for production use:
get_current_time to determine valid booking datessearch_stationsquery_tickets before query_transferget_station_info resultsThis project is for educational and research purposes only. It queries publicly available 12306 APIs and does not store, modify, or distribute official data. Users must comply with Chinese laws and 12306 terms of service. The authors assume no liability for misuse.
基于 SOC 职业分类