MCP新州交通
一种用于与新南威尔士州交通局的API进行交互的MCP服务,该服务使用户能够查找某个地点周围的交通站点,并获取有关交通警报和中断的信息。
服务介绍
Transport NSW API 客户端 (MCP 实现)
一个使用直接 HTTP 请求与 Transport NSW API 交互的 Claude MCP。
关于
此项目实现了用于 Transport NSW API 的 Model Context Protocol (MCP) 服务。
设置
- 克隆此仓库
- 使用 uv(快速 Python 包管理器)安装依赖项:
uv venv uv sync - 创建一个包含您的 API 密钥的
.env文件:OPEN_TRANSPORT_API_KEY=your_api_key_here - (可选)运行 MCP Inspector:
并访问 http://localhost:5173 上的服务器(端口可能不同)。uv run mcp dev api.py
功能
- 站点查找 API:通过名称或坐标查找运输站点
- 警报 API:获取有关运输警报和中断的信息
- 出发监控 API:获取运输站点的实时出发信息
- MCP 实现:结构化为 Model Context Protocol 服务
使用示例
即将推出 MCP 示例。以下为标准 Python 示例:
查找运输站点
from api import find_transport_stops
# Search by name
stops = find_transport_stops(stop_name="Central Station")
# Search by coordinates (Central Station area)
central_station = '151.206290:-33.884080:EPSG:4326'
stops = find_transport_stops(coord=central_station, radius=500)
获取运输警报
from api import get_transport_alerts
# Get all current alerts
alerts = get_transport_alerts()
# Get alerts for a specific date
date_alerts = get_transport_alerts(date='22-03-2025')
# Get train alerts only (mot_type=1)
train_alerts = get_transport_alerts(mot_type=1)
监控实时出发
from api import get_departure_monitor
# Get departures from Central Station
departures = get_departure_monitor("200060") # Central Station ID
# Get departures for a specific time
from datetime import datetime
time_departures = get_departure_monitor("200060", time="15:30")
# Get only train departures
train_departures = get_departure_monitor("200060", mot_type=1) # 1 = Train
演示脚本
该项目包括一个全面的演示脚本,展示了所有 API 功能:
# Run the full demo
python demo.py
# Run specific sections
python demo.py --stops # Stop finder demo
python demo.py --alerts # Transport alerts demo
python demo.py --departures # Departure monitoring demo
测试
本地测试
使用 pytest 运行完整的测试套件:
uv run pytest
带有覆盖率报告运行:
uv run pytest --cov=api
持续集成
每次向主分支推送或拉取请求时,测试都会在 GitHub Actions 上自动运行。工作流程如下:
- 设置 Python 3.10
- 安装 uv 和项目依赖项
- 带有覆盖率报告运行测试
要使用此功能:
- 将您的
OPEN_TRANSPORT_API_KEY添加为 GitHub 仓库密钥 - 将代码推送到 GitHub
MCP 集成
此项目遵循 Model Context Protocol 规范,允许 AI 模型通过标准化接口访问 Transport NSW 数据。
包管理
此项目使用 uv,一种用 Rust 编写的现代 Python 包管理器。依赖项通过以下文件管理:
pyproject.toml:定义项目依赖项uv.lock:锁定依赖项版本以实现可再现环境