Skip to main content
Glama
danhussey

Transport NSW API Client MCP

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

测试

使用直接 HTTP 请求与 Transport NSW API 进行交互的 Claude MCP。

关于

该项目为新南威尔士州交通局的 API 实现了模型上下文协议 (MCP) 服务。

Related MCP server: TfNSW Realtime Alerts MCP Server

设置

  1. 克隆此存储库

  2. 使用 uv(快速 Python 包管理器)安装依赖项:

    uv venv
    uv sync
  3. 使用您的 API 密钥创建一个.env文件:

    OPEN_TRANSPORT_API_KEY=your_api_key_here
  4. (可选)运行 MCP 检查器:

    uv run mcp dev api.py

    并访问服务器http://localhost:5173 (端口可能不同)。

特征

  • 站点查找器 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 都会自动运行测试。工作流程如下:

  1. 设置 Python 3.10

  2. 安装 uv 和项目依赖项

  3. 运行测试并报告覆盖率

要使用此功能:

  1. 将您的OPEN_TRANSPORT_API_KEY添加为 GitHub 存储库密钥

  2. 将代码推送到 GitHub

MCP 集成

该项目遵循模型上下文协议规范,允许人工智能模型通过标准化接口访问新南威尔士州交通部数据。

包管理

本项目使用 uv,一个用 Rust 编写的现代 Python 包管理器。依赖项通过以下方式管理:

  • pyproject.toml :定义项目依赖项

  • uv.lock :锁定可重现环境的依赖版本

Install Server
A
security – no known vulnerabilities
A
license - permissive license
A
quality - confirmed to work

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/danhussey/transportnsw-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server