新南威尔士州交通部API客户(MCP实施)

Claude MCP,用于使用直接HTTP请求与新南威尔士州API交通部进行交互。
关于
本项目为新南威尔士州交通部API提供模型上下文协议(MCP)服务。
设置
- 克隆此存储库
- 使用uv(快速Python包管理器)安装依赖项:
uv venv
uv sync- 创建一个
.env使用API密钥文件:
OPEN_TRANSPORT_API_KEY=your_api_key_here- (可选)运行MCP检查器:
uv run mcp dev api.py并访问服务器http://localhost:5173(端口可能不同)。
特性
- Stop-Finder API:按名称或坐标查找交通站点
- 警报API:获取有关交通警报和中断的信息
- 离港监视器API:获取交通站点的实时出发信息
- MCP实施:结构化为模型上下文协议服务
使用示例
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集成
该项目遵循模型上下文协议规范,允许AI模型通过标准化接口访问新南威尔士州交通局的数据。
包管理
这个项目使用uv,一个用Rust编写的现代Python包管理器。依赖关系通过以下方式管理:
pyproject.toml:定义项目依赖关系
许可证
该项目根据 MIT许可证.
