12306 MCP 服务器 logo

12306 MCP 服务器

Community
drfccv

12306 MCP Server​​ 是一个基于 ​​Model Context Protocol (MCP)​​ 的高性能火车票查询后端系统。它通过标准化接口提供官方 12306 的实时数据服务,包括余票查询、车站信息、列车经停站、中转换乘方案等核心功能。

Publisherdrfccv
Repositorymcp-server-12306
LanguagePython
Forks
55
Stars
329
Available tools
0
Transport typestdio, streamable-http
Categories
LicenseMIT
Links
  • Connect tools to AI workflows

    12306 MCP 服务器 exposes MCP capabilities that can be used by compatible AI clients and agents.

  • 0 available tools

    Browse the callable actions below, including names and descriptions when provided by the server.

  • Ready-to-copy setup

    Use the installation snippets to configure this server in your preferred MCP client.

  • Open source signals

    329 stars and 55 forks from the linked repository.

🚄 MCP Server 12306

screenshot FastAPI License: MIT


✨ 项目简介

MCP Server 12306是一款基于 Model Context Protocol (MCP) 的高性能火车票查询后端,支持官方 12306 余票、票价、车站、经停、换乘查询以及智能时间工具,适配 AI/自动化/智能助手等场景。界面友好,易于集成,开箱即用。


🚀 功能亮点

  • 实时余票/车次/座席/时刻/换乘一站式查询
  • 全国车站信息管理与模糊搜索
  • 官方经停站、一次中转方案全支持
  • 实时查询各车次票价信息
  • 智能时间工具,支持时区和时间戳
  • Streamable HTTP/STDIO传输协议,支持MCP 2025-03-26标准
  • FastAPI异步高性能,秒级响应
  • MCP标准,AI/自动化场景即插即用

🛠️ 快速上手

本项目支持两种运行模式:

  1. Stdio 模式:适用于 Claude Desktop 等本地 MCP 客户端(推荐)。
  2. Streamable HTTP 模式:适用于远程部署或通过 SSE/Post 访问。

模式 1:Stdio 模式(Claude Desktop 推荐)

在此模式下,MCP Server 通过标准输入/输出与客户端通信,无需占用网络端口。

方式 A:使用 uvx(推荐)

uvxuv 包管理器提供的工具,环境隔离且启动极快。

json
{
  "mcpServers": {
    "12306": {
      "command": "uvx",
      "args": ["mcp-server-12306"]
    }
  }
}

方式 B:使用 pipx

如果您更习惯使用 pipx:

json
{
  "mcpServers": {
    "12306": {
      "command": "pipx",
      "args": ["run", "--no-cache", "mcp-server-12306"]
    }
  }
}

方式 C:本地源码运行

适用于开发者调试:

json
{
  "mcpServers": {
    "12306": {
      "command": "uv",
      "args": ["run", "python", "-m", "mcp_12306.cli"],
      "cwd": "/path/to/mcp-server-12306"
    }
  }
}

模式 2:Streamable HTTP 模式

在此模式下,Server 启动一个 Web 服务(默认 8000 端口),支持 MCP 的 SSE(Server-Sent Events)和 POST 交互。

方式 A:本地源码运行

bash
# 1. 克隆并安装依赖
git clone https://github.com/drfccv/mcp-server-12306.git
cd mcp-server-12306
uv sync

# 2. 启动服务器
uv run python scripts/start_server.py

MCP 客户端配置:

json
{
  "mcpServers": {
    "12306": {
      "url": "http://localhost:8000/mcp"
    }
  }
}

方式 B:Docker 部署

bash
# 拉取镜像并运行
docker run -d -p 8000:8000 --name mcp-server-12306 drfccv/mcp-server-12306:latest

🤖 工具一览

支持的主流程工具

工具名典型场景/功能描述
query_tickets余票/车次/座席/时刻一站式查询
query_ticket_price实时查询各车次票价信息
search_stations车站模糊搜索,支持中文/拼音/简拼
get_station_info获取车站详情(名称、代码、地理等)
query_transfer一次中转换乘方案,自动拼接最优中转
get_train_route_stations查询指定列车经停站及时刻表
get_current_time获取当前时间与相对日期,帮助用户准确选择出行日期

📚 工具文档

本项目所有主流程工具的详细功能、实现与使用方法,均已收录于 /docs 目录下:

每个文档包含:

  • 工具功能说明
  • 实现方法
  • 请求参数与返回示例
  • 典型调用方式

如需二次开发或集成,建议先阅读对应工具的文档。


🧩 目录结构

src/mcp_12306/    # 主源代码
  ├─ server.py    # FastAPI主入口
  ├─ services/    # 业务逻辑(车票/车站/HTTP)
  ├─ utils/       # 工具与配置
scripts/          # 启动与数据脚本

📄 License

MIT License


⚠️ 免责声明

  • 本项目仅供学习、研究与技术交流,严禁用于任何商业用途。
  • 本项目不存储、不篡改、不传播任何 12306 官方数据,仅作为官方公开接口的智能聚合与转发。
  • 使用本项目造成的任何后果(包括但不限于账号封禁、数据异常、法律风险等)均由使用者本人承担,项目作者不承担任何责任。
  • 请遵守中国法律法规及 12306 官方相关规定,合理合规使用。

Installation

TypingMind
Prerequisites:

Node.js 18+

{
  "mcpServers": {
    "drfccv-mcp-server-12306": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-server-12306"
      ]
    }
  }
}

Use 12306 MCP 服务器 MCP with multiple AI models

TypingMind connects MCP tools at the workspace level, so once 12306 MCP 服务器 is connected, you can use it with different AI models in TypingMind instead of setting it up separately for each model. You can run MCP locally on your device or connect to a remote MCP server URL.

Option 1: Use the local connector

Use this when the MCP server needs access to local files, apps, or private resources on your computer.

1

Open the MCP settings

In TypingMind, go to Settings, Advanced Settings, then Model Context Protocol and choose Setup Connector.

  1. Open TypingMind in your browser.
  2. Click the Settings icon.
  3. Go to Advanced Settings.
  4. Open the Model Context Protocol section.
  5. Click Setup Connector and choose This Device.
TypingMind MCP connector setup screen with This Device selected
2

Run the connector command

Choose This Device, copy the command from TypingMind, and run it in Terminal. Keep the process running while you use MCP.

  1. Copy the setup command shown by TypingMind.
  2. Open Terminal on macOS or Windows Terminal on Windows.
  3. Paste and run the command.
  4. Approve the package install if Terminal asks you to proceed.
  5. Keep the Terminal window running while using MCP tools.
3

Add 12306 MCP 服务器 as a server

When the connector status is Ready, click Edit Servers and paste the MCP server configuration.

  1. Wait until the connector status shows Ready.
  2. Click Edit Servers.
  3. Paste the 12306 MCP 服务器 MCP server configuration.
  4. Save the server list.
  5. Refresh if you want to confirm the connector is still ready.
TypingMind MCP settings showing active server and Edit Servers button
{
  "mcpServers": {
    "drfccv-mcp-server-12306": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-server-12306"
      ]
    }
  }
}
4

Use it across models

Save the server list, open Plugins, enable the 12306 MCP 服务器 MCP tools, then select any supported AI model in TypingMind and use the tools in chat or assign them to an AI agent.

  1. Open the Plugins page in TypingMind.
  2. Enable the 12306 MCP 服务器 MCP tools.
  3. Start a chat and choose the AI model you want to use.
  4. Use the MCP tools in chat or assign them to an AI agent.
  5. Switch to another AI model whenever needed without reconnecting MCP.
TypingMind chat using enabled MCP tools with a selected AI model
Can you use 12306 MCP 服务器 to help me with this task?
12306 MCP 服务器
Sure. I read it.
Here is what I found using 12306 MCP 服务器.

Option 2: Add an MCP server URL

Use this when 12306 MCP 服务器 is already hosted remotely or your team wants one shared connector that multiple users can access.

1

Open MCP connectors

In TypingMind, go to Plugins, open MCP connectors, then choose Add URL.

  1. Open TypingMind in your browser.
  2. Go to Plugins.
  3. Open MCP connectors.
  4. Click Add URL.
TypingMind Add Custom MCP Server URL form
2

Paste the server URL

Enter your server URL in the Server URL field. Add a connection name, description, icon, custom HTTP headers, or OAuth client settings if the server requires them.

  1. Paste your server URL into the Server URL field.
  2. Enter a connection name for 12306 MCP 服务器.
  3. Add a description and icon if you want it to be easier to identify.
  4. Add custom HTTP headers or OAuth client details if the server requires authentication.
3

Create the connection

Click Create connection, then return to the Plugins list and confirm the new MCP connection is active.

  1. Click Create connection.
  2. Return to the MCP connectors list.
  3. Confirm the 12306 MCP 服务器 connection appears as active.
  4. Refresh the plugin list if the connection does not appear immediately.
4

Switch models without reconnecting

Start a chat with your preferred model, enable the 12306 MCP 服务器 tools from Plugins, and switch to another model whenever needed. The MCP connection stays available to the TypingMind workspace.

  1. Start a new chat in TypingMind.
  2. Select the AI model you want to use.
  3. Enable the 12306 MCP 服务器 tools from Plugins.
  4. Ask the model to use the tool when needed.
  5. Switch to another AI model and reuse the same MCP connection.
TypingMind chat using enabled MCP tools with a selected AI model
Can you use 12306 MCP 服务器 to help me with this task?
12306 MCP 服务器
Sure. I read it.
Here is what I found using 12306 MCP 服务器.

Frequently asked questions

What is the 12306 MCP 服务器 MCP server used for?

12306 MCP 服务器 is an MCP server that lets compatible AI clients connect to external tools and context. In TypingMind, you can add this MCP server once and make its tools available in your AI workspace.

Can I use 12306 MCP 服务器 MCP with multiple AI models in TypingMind?

Yes. TypingMind connects MCP tools at the workspace level, so you can use 12306 MCP 服务器 with different AI models such as Claude, ChatGPT, Gemini, or other models you have configured in TypingMind without setting up the MCP server separately for each model.

Why use 12306 MCP 服务器 MCP with TypingMind?

TypingMind is one of the best frontends for LLM chat because it brings multiple AI models, prompts, plugins, AI agents, API keys, and MCP tools into one workspace. With 12306 MCP 服务器 connected, you can use its MCP tools across your preferred models while keeping your chat workflow organized in TypingMind.

How do I connect 12306 MCP 服务器 MCP to TypingMind?

12306 MCP 服务器 can be connected in TypingMind with the local MCP connector or by adding a remote MCP server URL. Use the local connector when the server needs access to files, apps, or private resources on your device, and use a server URL when the MCP server is hosted remotely.

What tools does 12306 MCP 服务器 MCP provide in TypingMind?

12306 MCP 服务器 exposes MCP capabilities that can be enabled from the TypingMind Plugins page and used in chat or assigned to AI agents.

Do I need to share my API keys with TypingMind to use 12306 MCP 服务器 MCP?

No. TypingMind is local-first and lets you keep your model providers, API keys, prompts, and MCP configuration under your control. If 12306 MCP 服务器 requires authentication, add the required headers, OAuth settings, or local configuration for that MCP server when you create the connection.

Related MCP Servers

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇