内容
# mcp-hafas-european
欧洲公共交通查询的MCP服务器,通过 [hafas-client](https://github.com/public-transport/hafas-client)。
支持欧洲50多家铁路和公交运营商(以及美国的一些)——无需API密钥。
**状态:** 已准备就绪
---
## 前置条件
- [Bun](https://bun.sh) 运行时(`curl -fsSL https://bun.sh/install | bash`)
- 无需API密钥 — 使用公开可访问的HAFAS端点
---
## 安装
```bash
git clone git@github.com:McCullonas/mcp-hafas-european.git
cd mcp-hafas-european
bun install
```
---
## 支持的运营商
通过 `operator` 参数可访问50多家运营商:
| 代码 | 运营商 | 国家 |
|------|----------|---------|
| `db` | 德意志铁路 | 🇩🇪 德国 |
| `oebb` | 奥地利联邦铁路 | 🇦🇹 奥地利 |
| `sbb` | 瑞士联邦铁路(通过hafas) | 🇨🇭 瑞士 |
| `sncb` | 比利时国家铁路/比利时铁路 | 🇧🇪 比利时 |
| `pkp` | 波兰国铁 | 🇵🇱 波兰 |
| `rejseplanen` | 丹麦铁路 | 🇩🇰 丹麦 |
| `irish-rail` | 爱尔兰铁路 | 🇮🇪 爱尔兰 |
| `cfl` | 卢森堡铁路 | 🇱🇺 卢森堡 |
| `bvg` | 柏林公共交通 | 🇩🇪 德国 |
| `vbb` | 柏林-勃兰登堡交通联盟 | 🇩🇪 德国 |
| `rmv` | 法兰克福地区交通联盟 | 🇩🇪 德国 |
| `bart` | 湾区捷运 | 🇺🇸 美国 |
运行 `hafas_list_operators` 以查看完整列表。
---
## 可用工具
### `hafas_list_operators`
列出所有可用的运营商配置文件及其代码、名称和国家。
无参数。
### `hafas_search_stations`
按名称搜索特定运营商网络中的车站。
**参数:**
- `operator` — 运营商代码(例如 `"db"`、`"oebb"`)
- `query` — 搜索的车站名称(例如 `"法兰克福"`、`"维也纳中央车站"`)
- `results` *(可选)* — 最大结果数(默认为5)
### `hafas_get_departures`
获取车站的即将出发的列车信息。
**参数:**
- `operator` — 运营商代码
- `stationId` — 车站ID(来自 `hafas_search_stations`)
- `when` *(可选)* — ISO 8601日期时间(默认为当前时间)
- `duration` *(可选)* — 分钟为单位的时间范围(默认为60)
返回:线路名称、目的地、计划/实际时间、延误、站台号码。
### `hafas_get_arrivals`
获取车站的即将到达的列车信息。
**参数:**
- `operator` — 运营商代码
- `stationId` — 车站ID
- `when` *(可选)* — ISO 8601日期时间
- `duration` *(可选)* — 分钟为单位的时间范围
### `hafas_get_journeys`
规划两个车站之间的行程,包括换乘信息。
**参数:**
- `operator` — 运营商代码
- `fromId` — 起始车站ID
- `toId` — 终点车站ID
- `when` *(可选)* — 出发日期时间(ISO 8601)
- `results` *(可选)* — 行程选项数量(默认为3)
返回:路线、行程段、换乘信息、时长、延误、站台号码。
---
## MCP客户端配置
添加到您的 `settings.json`:
```json
{
"mcpServers": {
"hafas-european": {
"command": "bun",
"args": ["run", "/path/to/mcp-hafas-european/src/index.ts"]
}
}
}
```
无需环境变量。
---
## 开发
```bash
# 直接运行
bun run src/index.ts
# 构建
bun build src/index.ts --outdir dist --target node
```
---
## 数据源
该服务器使用 [hafas-client](https://github.com/public-transport/hafas-client) 由
[derhuerst](https://github.com/derhuerst) 开发,它连接到由各个交通管理机构运营的公开可访问的HAFAS端点。使用受限于每个运营商的条款。
---
## 许可证
MIT