Skip to main content
Glama
train-mcp-server

train-mcp-server

Train Ticket Query MCP Server (FastMCP)

A train/high-speed rail query service implemented with FastMCP, which can be called as a remote MCP tool by any Agent (such as deepagents, LangGraph, Claude, etc.).

Capabilities

One tool function: query_train_tickets(from_station, to_station, date)

  • Query the train numbers, schedules, durations, booking availability, and remaining tickets between two stations on a given day

  • Data source: 12306 public query interface (real data); automatically switches to simulated data when the interface is blocked, with the source clearly marked, ensuring the pipeline can be demonstrated at any time

Related MCP server: YHT Bilet MCP Server

Local Run

pip install -r requirements.txt
python server.py        # 启动 streamable-http 服务,默认 http://127.0.0.1:8000

MCP client configuration (local debugging):

{
  "mcpServers": {
    "train": {
      "url": "http://127.0.0.1:8000/mcp/",
      "transport": "streamable_http"
    }
  }
}

Deploy to ModelScope MCP Plaza (Key Steps)

  1. Push this repository to GitHub

  2. Open modelscope.cn/mcp → Log in → Click "Create MCP"

  3. Select "GitHub Quick Create" as the creation type; select "Hosted Deployment" as the hosting type

  4. Fill in the English/Chinese name, source URL (GitHub repository URL), and complete the configuration as prompted by the platform

  5. After submission, the platform generates an access URL: https://mcp.api-inference.modelscope.net/<your ID>/sse or /mcp (can be set to be valid indefinitely)

  6. Fill this URL back into the MCP configuration of the Agent project

Tip: The platform has startup method requirements for hosted projects (usually requires Python + starting an HTTP service). If deployment fails, adjust the entry point as prompted by the platform (e.g., provide a run script or environment variable).

Data Source Description

  • 12306 has no official open API. This project uses its public query interface (kyfw.12306.cn/otn/leftTicket) for querying without login, for personal learning and research only

  • The interface has anti-bot measures (occasional 302 redirects). The code includes session cookies + simulated data as a fallback

  • If more stable data is needed, you can replace _fetch_12306 with a third-party data source (pluggable)

Directory

  • server.py — FastMCP service main program

  • test_client.py — Local debugging script (directly calls tool functions + tests via MCP protocol)

  • requirements.txt — Dependencies

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables searching Turkish high-speed train (YHT) tickets via TCDD API. Supports real-time availability, station name resolution, date formatting, and passenger count.
      MIT
    • F
      license
      Not graded
      quality
      D
      maintenance
      Enables real-time flight and train ticket queries, dynamic trip tracking, and knowledge-based Q&A about rail and aviation policies.
      -
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables AI agents to query public China Railway 12306 information via MCP, including station lookup, ticket availability, transfer planning, and train route details. It does not support login, booking, or payment.
      MIT