Transport NSW API Client MCP
新南威尔士州交通 API 客户端(MCP 实施)
使用直接 HTTP 请求与 Transport NSW API 进行交互的 Claude MCP。
关于
该项目为新南威尔士州交通局的 API 实现了模型上下文协议 (MCP) 服务。
Related MCP server: transport12 MCP Server
设置
克隆此存储库
使用 uv(快速 Python 包管理器)安装依赖项:
uv venv uv sync使用您的 API 密钥创建一个
.env文件:OPEN_TRANSPORT_API_KEY=your_api_key_here(可选)运行 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 都会自动运行测试。工作流程如下:
设置 Python 3.10
安装 uv 和项目依赖项
运行测试并报告覆盖率
要使用此功能:
将您的
OPEN_TRANSPORT_API_KEY添加为 GitHub 存储库密钥将代码推送到 GitHub
MCP 集成
该项目遵循模型上下文协议规范,允许人工智能模型通过标准化接口访问新南威尔士州交通部数据。
包管理
本项目使用 uv,一个用 Rust 编写的现代 Python 包管理器。依赖项通过以下方式管理:
pyproject.toml:定义项目依赖项uv.lock:锁定可重现环境的依赖版本
Available Tools
3 toolsfind_transport_stopsB
Find transport stops around a specific location.
Args:
location_coord (str): Coordinates in format 'LONGITUDE:LATITUDE:EPSG:4326'
stop_type (str): Type of stops to find: 'BUS_POINT', 'POI_POINT', or 'GIS_POINT'
radius (int): Search radius in meters
Returns:
API response with transport stops
| Name | Required | Description | Default |
|---|---|---|---|
| location_coord | Yes | ||
| stop_type | No | BUS_POINT | |
| radius | No |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions the tool 'finds' stops and returns an 'API response,' but doesn't describe error handling, rate limits, authentication needs, or what the response format entails. For a tool with no annotations, this leaves significant behavioral gaps.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is appropriately sized and front-loaded with the core purpose. The parameter and return sections are structured clearly, with no redundant sentences. However, the 'Returns' line is vague ('API response with transport stops'), slightly reducing efficiency.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given 3 parameters with no schema descriptions and no output schema, the description provides good parameter semantics but lacks details on behavioral aspects and output. It's adequate for basic use but incomplete for full agent understanding, especially without annotations to cover safety or performance traits.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The description adds meaningful semantics beyond the input schema, which has 0% description coverage. It explains the format for 'location_coord' (coordinates in 'LONGITUDE:LATITUDE:EPSG:4326'), enumerates possible values for 'stop_type' ('BUS_POINT', 'POI_POINT', 'GIS_POINT'), and clarifies 'radius' as 'Search radius in meters.' This compensates well for the schema's lack of descriptions.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the tool's purpose: 'Find transport stops around a specific location.' It specifies the verb ('find') and resource ('transport stops'), and the scope ('around a specific location'). However, it doesn't explicitly differentiate from sibling tools like 'get_departure_monitor' or 'get_transport_alerts', which prevents a perfect score.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description provides no guidance on when to use this tool versus alternatives. There's no mention of sibling tools or contextual cues for selection. Usage is implied by the purpose but lacks explicit when/when-not instructions or prerequisites.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
get_departure_monitorA
Get real-time departure monitor information for a specific stop from the Trip Planner API.
This function uses direct HTTP requests to the Transport NSW API.
Args:
stop_id (str): Stop ID or global stop ID
date (str, optional): Date in DD-MM-YYYY format. Defaults to today's date.
time (str, optional): Time in HH:MM format. Defaults to current time.
mot_type (int, optional): Mode of transport type filter. Options:
1: Train
2: Metro
4: Light Rail
5: Bus
7: Coach
9: Ferry
11: School Bus
max_results (int, optional): Maximum number of results to return. Default is 1.
Returns:
list: Simplified list of departure information
| Name | Required | Description | Default |
|---|---|---|---|
| stop_id | Yes | ||
| date | No | ||
| time | No | ||
| mot_type | No | ||
| max_results | No |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are provided, so the description carries the full burden. It mentions using 'direct HTTP requests to the Transport NSW API', which hints at external API calls, but doesn't disclose critical behavioral traits like error handling, rate limits, authentication needs, or what 'simplified list' means in the Returns section. For a tool with no annotations, this leaves significant gaps in understanding its behavior.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is well-structured with a clear purpose statement upfront, followed by an Args section with bullet-point details and a Returns section. It's appropriately sized for a 5-parameter tool, though the 'This function uses direct HTTP requests...' sentence could be integrated more tightly or omitted if redundant with context.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given no annotations and no output schema, the description provides good parameter semantics and a basic return type ('Simplified list of departure information'), but lacks details on output structure, error cases, or API constraints. For a tool with moderate complexity (5 parameters, external API), it's adequate but has clear gaps in behavioral context.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 0%, so the description must compensate. It provides detailed semantics for all 5 parameters, including formats (e.g., 'DD-MM-YYYY' for date, 'HH:MM' for time), defaults, and a clear enum-like explanation for 'mot_type' with transport mode options. This adds substantial value beyond the bare schema, though it doesn't fully explain all edge cases (e.g., what 'global stop ID' entails).
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the specific action ('Get real-time departure monitor information'), the resource ('for a specific stop'), and the source ('from the Trip Planner API'). It distinguishes this tool from sibling tools like 'find_transport_stops' (which likely finds stops) and 'get_transport_alerts' (which gets alerts rather than departures).
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description implies usage by specifying it's for departure information from a stop, but doesn't explicitly state when to use this tool versus alternatives like 'find_transport_stops' or 'get_transport_alerts'. No exclusions or prerequisites are mentioned, leaving the agent to infer context from the tool name and description alone.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
get_transport_alertsB
Get transport alerts from the Transport NSW API.
Args:
date (str, optional): Date in DD-MM-YYYY format. Defaults to today's date.
mot_type (int, optional): Mode of transport type filter. Options:
1: Train
2: Metro
4: Light Rail
5: Bus
7: Coach
9: Ferry
11: School Bus
stop_id (str, optional): Stop ID or global stop ID to filter by.
line_number (str, optional): Line number to filter by (e.g., '020T1').
operator_id (str, optional): Operator ID to filter by.
Returns:
dict: API response containing alerts information
| Name | Required | Description | Default |
|---|---|---|---|
| date | No | ||
| mot_type | No | ||
| stop_id | No | ||
| line_number | No | ||
| operator_id | No |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries full burden for behavioral disclosure. It mentions the API source but doesn't describe rate limits, authentication requirements, error handling, pagination, or what happens when no alerts are found. The return type 'dict: API response' is vague and doesn't explain the structure or content of the response.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is well-structured with clear sections (Args, Returns) and uses bullet points for the mot_type options. It's appropriately sized for a tool with 5 parameters. The only minor inefficiency is repeating 'to filter by' for multiple parameters, but overall it's front-loaded and efficient.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
For a read-only tool with 5 optional parameters and no output schema, the description provides good parameter documentation but lacks behavioral context. Without annotations or output schema, the agent doesn't know about rate limits, authentication, error handling, or the structure of returned data. The description is adequate but has clear gaps in behavioral transparency.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The description provides excellent parameter semantics beyond the input schema, which has 0% description coverage. It explains the date format (DD-MM-YYYY), default behavior (today's date), enumerates all mot_type options with clear mappings, and provides examples (e.g., '020T1' for line_number). This fully compensates for the schema's lack of descriptions.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the verb 'Get' and resource 'transport alerts from the Transport NSW API', which is specific and actionable. However, it doesn't explicitly differentiate from sibling tools like 'find_transport_stops' or 'get_departure_monitor', which likely serve different purposes (finding stops vs monitoring departures vs getting alerts).
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description provides no guidance on when to use this tool versus the sibling tools 'find_transport_stops' or 'get_departure_monitor'. It doesn't mention any prerequisites, alternatives, or exclusion criteria. The only contextual information is the parameter descriptions, which don't constitute usage guidelines.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
3 tool updates
v1.0.0- First observed
find_transport_stops - First observed
get_departure_monitor - First observed
get_transport_alerts
TDQS
Scored across 3 tools
Each tool has a clearly distinct purpose: find_transport_stops locates stops, get_departure_monitor provides real-time departures, and get_transport_alerts retrieves service alerts. There is no overlap in functionality, and the descriptions clearly differentiate their roles.
All tool names follow a consistent verb_noun pattern using snake_case: find_transport_stops, get_departure_monitor, and get_transport_alerts. The naming is predictable and readable throughout the set.
With only 3 tools, the set feels thin for a transport API client, lacking operations like route planning, trip details, or fare information. While the tools cover basic needs, the scope suggests more comprehensive coverage would be expected.
The tools provide core functionality for stops, departures, and alerts, but there are notable gaps. Missing operations include trip planning, route searches, service status beyond alerts, and fare queries, which are typical for a transport API and could limit agent effectiveness.
Maintenance
Related MCP Connectors
Transport for NSW MCP — journey planning, live departures, service alerts
Transport for London (TfL) Unified API MCP — keyless.
Swiss Transport MCP — wraps Transport Open Data API (free, no auth)
Provide real-time transportation data including bus arrivals, train service alerts, carpark availa…
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceAn MCP server for interacting with the Berlin Public Transport (BVG) API to search for locations and plan journeys. It provides real-time access to departures, arrivals, trip details, and vehicle tracking within Berlin's transit network.MIT
- AlicenseBqualityDmaintenanceMCP server that integrates with the transport12 API to provide tools for searching stops, routes, arrivals, and vehicle forecasts, enabling natural language interaction with public transport data.179 npmMIT
- AlicenseNot gradedqualityDmaintenanceEnables querying real-time BART and SF Muni transit data, including departures, trip planning, fares, advisories, routes, alerts, vehicle positions, and schedules, from any MCP-compatible client.1MIT
- AlicenseAqualityBmaintenanceEnables LLM clients to search stops, plan journeys, check live departures, service alerts, nearby locations, and vehicle positions using Transport for NSW open data, with per-request API key authentication.10MIT