Skip to main content
Glama
mcp-server-public-transport

mcp-server-public-transport

mcp-server-public-transport

一个提供欧洲实时公共交通数据的 MCP 服务器。

关于

mcp-server-public-transport 是一个兼容 Model Context Protocol (MCP) 的本地服务器,提供对欧洲各地公共交通数据的访问。 目前,它集成了英国、瑞士、挪威、比利时以及柏林/勃兰登堡地区的 API,允许您检索火车连接、实时出发信息和公交车位置。

Related MCP server: BVG MCP Server

功能实现状态

支持的国家/地区

国家/地区

API 基础 URL

状态

英国

https://transportapi.com

✅

瑞士

https://transport.opendata.ch

✅

比利时

https://api.irail.be

✅

挪威

https://api.entur.io

✅

柏林/勃兰登堡

https://v6.vbb.transport.rest

✅

各国功能

功能

API 路径

状态

英国

实时出发

/uk/train/station_timetables/{station_code}.json

✅

瑞士

搜索连接

/connections

✅

车站查询

/locations

✅

出发看板

/stationboard

✅

附近车站

/locations?x={lon}&y={lat}

✅

比利时

实时出发

/departures

✅

车站查询

/stations

✅

附近车站

/stations/nearby

✅

挪威

地点搜索

/geocoder/v1/autocomplete

✅

实时出发

GraphQL: stopPlace(id) { estimatedCalls(...) }

✅

行程规划

GraphQL: trip(from, to, dateTime, numTripPatterns, ...)

✅

最近站点

GraphQL: nearest(latitude, longitude, maximumDistance, ...)

✅

柏林/勃兰登堡

地点搜索

/locations

✅

实时出发

/stops/:id/departures

✅

实时到达

/stops/:id/arrivals

✅

行程规划

/journeys

✅

附近车站

/locations/nearby

✅

设置

环境变量

设置以下环境变量:

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 替换为您克隆存储库的实际路径。

注意:您可能需要在命令字段中填写 uv 可执行文件的完整路径。您可以通过在 MacOS/Linux 上运行 which uv 或在 Windows 上运行 where uv 来获取该路径。

开发

设置开发环境

  1. 克隆存储库

    git clone https://github.com/mirodn/mcp-server-public-transport.git
    cd mcp-server-public-transport
  2. 安装依赖

    uv sync
  3. 设置环境变量

    cp .env.example .env
  4. 运行服务器

    uv run server.py

运行测试

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

# Run all tests
make test

代码质量

# Run linting
make lint

# Run code formatting
make format

持续集成

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

  • 在 Python 3.10、3.11 和 3.12 上运行测试

  • 使用 ruff 执行代码检查

  • 在每次推送到 main 分支或提交拉取请求时运行

CI 流水线确保在合并任何更改之前,代码在支持的 Python 版本中保持高质量和兼容性。

贡献

欢迎贡献!请随时提交拉取请求 (Pull Request)。

当 pyproject.toml 中的 project.version 更新时,该包会自动部署到 PyPI。 版本控制请遵循 semver 规范。

许可证

MIT 许可证

Available Tools

13 tools
be_get_departuresB

Get live departure board for a Belgian train station.

Inputs: station (required), limit. Returns: object

be_get_vehicleA

Get details about a specific Belgian train vehicle by its ID.

Inputs: vehicle_id (required). Returns: object

be_search_connectionsB

Search train connections in Belgium between two stations. Powered by iRail API for real-time routes and schedules.

Inputs: origin (required), destination (required), results, date, +1 more. Returns: object

be_search_stationsB

Search for Belgian train stations by name.

Inputs: query (required). Returns: object

ch_get_departuresC

Get departure board for a Swiss train station with real-time information.

Inputs: station (required), limit, datetime. Returns: object

ch_nearby_stationsC

Find nearby Swiss train stations based on coordinates (latitude, longitude).

Inputs: latitude (required), longitude (required), distance. Returns: object

ch_search_connectionsA

Search for train connections in Switzerland between two stations. Uses transport.opendata.ch API to provide real-time connection data including departure times, duration, platforms, and transfers.

Inputs: origin (required), destination (required), limit, date, +2 more. Returns: object

ch_search_stationsC

Search for Swiss train stations by name or location.

Inputs: query (required), type. Returns: object

no_nearest_stopsB

Find nearest StopPlaces for a coordinate (lat, lon) within a radius in meters.

Inputs: lat (required), lon (required), radius, limit. Returns: object

no_search_placesC

Autocomplete search across stops/addresses/POIs in Norway via Entur Geocoder.

Inputs: text (required), lang, size. Returns: object

no_stop_departuresB

Upcoming departures for a StopPlace ID (e.g., 'NSR:StopPlace:58368').

Inputs: stop_place_id (required), limit. Returns: object

no_tripC

Door-to-door trip planning between two StopPlaces (NSR IDs).

Inputs: from_id (required), to_id (required), date_time, results. Returns: object

uk_live_departuresA

Get live departure information for a UK train station using its CRS code (e.g., 'PAD' for London Paddington, 'MAN' for Manchester Piccadilly). Uses the TransportAPI station timetables endpoint with live data.

Inputs: station_code (required). Returns: object

Tool Schema Changelog

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

    TDQS

    A3.5/5.0

    Scored across 13 tools

    Disambiguation4/5

    Tools are clearly distinguished by country prefix (be_, ch_, no_, uk_) and specific functions like departures, connections, stations, and trips, with minimal overlap. However, some tools like be_get_departures and uk_live_departures serve similar purposes across different regions, which could cause minor confusion if an agent doesn't prioritize the country prefix.

    Naming Consistency4/5

    Naming follows a consistent pattern of country prefix + verb_noun (e.g., be_get_departures, ch_search_connections), with all tools using snake_case. Minor deviations include no_nearest_stops (using 'nearest' instead of 'search' or 'get') and no_trip (using a noun instead of verb_noun), but overall the convention is predictable and readable.

    Tool Count5/5

    With 13 tools, the count is well-scoped for a public transport server covering multiple countries (Belgium, Switzerland, Norway, UK). Each tool earns its place by providing distinct functionality per region, such as departures, connections, station searches, and trip planning, without being overly bloated or sparse.

    Completeness4/5

    The toolset offers comprehensive coverage for public transport queries across four countries, including core operations like searching stations, getting departures, and planning connections. Minor gaps exist, such as no tool for vehicle details outside Belgium or real-time alerts, but agents can work around these with the available tools for most common use cases.

    Maintenance

    ActivityActive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers