Back to MCP directory
publicPublicdnsLocal runtime

mcp-server-public-transport

一个兼容MCP协议的本地服务器,提供欧洲多国的公共交通实时数据,包括英国、瑞士和比利时的火车班次、实时出发信息和公交位置查询。

article

README

🚀 mcp-server-public-transport

这是一个兼容MCP的服务器,可提供全欧洲的实时公共交通数据。借助该服务器,用户能够轻松获取欧洲各地的公共交通信息,极大提升出行规划的便利性。

🚀 快速开始

环境变量

设置以下环境变量:

UK_TRANSPORT_APP_ID=your_uk_app_id
UK_TRANSPORT_API_KEY=your_uk_api_key

在Claude Desktop中使用

添加到 claude_desktop_config.json 文件:

{
  "mcpServers": {
    "mcp-server-public-transport": {
      "command": "uv",
      "args": [
        "--directory",
        "/ABSOLUTE/PATH/TO/mcp-server-public-transport",
        "run",
        "server.py"
      ],
      "env": {
        "UK_TRANSPORT_APP_ID": "your-uk-app-id",
        "UK_TRANSPORT_API_KEY": "your-uk-api-key"
      }
    }
  }
}

请将 /ABSOLUTE/PATH/TO/PARENT/FOLDER/mcp-server-public-transport 替换为你克隆仓库的实际路径。

⚠️ 重要提示

你可能需要在 command 字段中填写 uv 可执行文件的完整路径。在MacOS/Linux系统中可通过运行 which uv 获取,在Windows系统中可通过运行 where uv 获取。

✨ 主要特性

mcp-server-public-transport 是一个兼容 模型上下文协议(MCP) 的本地服务器,可让你访问全欧洲的公共交通数据。目前,它集成了英国、瑞士和比利时的API,你可以通过它检索火车车次、实时出发信息和公交车位置。

支持的国家

| 国家 | API基础URL | 状态 | | ---- | ---- | ---- | | 英国 | https://transportapi.com | ✅ | | 瑞士 | https://transport.opendata.ch | ✅ | | 比利时 | https://api.irail.be | ✅ |

各国支持的功能

| 功能 | API路径 | 状态 | | ---- | ---- | ---- | | 英国 | | | | 实时出发信息 | /uk/train/station_timetables/{station_code}.json | ✅ | | 瑞士 | | | | 搜索车次 | /connections | ✅ | | 车站查询 | /locations | ✅ | | 出发信息板 | /stationboard | ✅ | | 附近车站 | /locations?x={lon}&y={lat} | ✅ | | 比利时 | | | | 实时出发信息 | /departures | ✅ | | 车站查询 | /stations | ✅ | | 附近车站 | /stations/nearby | ✅ |

📦 安装指南

开发环境搭建

  1. 克隆仓库
git clone https://github.com/mirodn/mcp-server-public-transport.git
cd mcp-server-public-transport
  1. 安装依赖
uv sync
  1. 设置环境变量
cp .env.example .env
  1. 运行服务器
uv run server.py

运行测试

项目使用 pytest 进行测试,可使用以下命令:

# 运行所有测试
make test

代码质量

# 运行代码检查
make lint

# 运行代码格式化
make format

持续集成

项目包含一个GitHub Actions工作流(.github/workflows/test.yml),它会自动执行以下操作:

  • 在Python 3.10、3.11和3.12版本上运行测试
  • 使用 ruff 执行代码检查
  • 在每次推送到 main 分支或发起拉取请求时运行

CI管道可确保在合并任何更改之前,代码质量和兼容性都能满足要求。

🤝 贡献代码

欢迎贡献代码!请随时提交拉取请求。当 pyproject.toml 中的 project.version 更新时,该包会自动部署到PyPI。请遵循语义化版本控制规范进行版本管理。

📄 许可证

MIT许可证

help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client