Transport NSW MCP server

Integrates with Transport NSW API to provide real-time public transportation data, including nearby stops, service alerts, and disruptions across trains, buses, and ferries throughout New South Wales.
Back to servers
Setup instructions
Provider
Dan Hussey
Release date
Mar 19, 2025
Language
Python

This MCP server provides access to Transport NSW's API services through a standardized Model Context Protocol interface. It allows you to search for transport stops, get information about service alerts, and monitor real-time departures from transport stops across New South Wales.

Installation

To get started with the Transport NSW MCP server:

  1. Clone the repository from GitHub
  2. Install dependencies using uv (a fast Python package manager):
uv venv
uv sync
  1. Create a .env file in the project root with your API key:
OPEN_TRANSPORT_API_KEY=your_api_key_here
  1. To run the MCP Inspector for testing:
uv run mcp dev api.py

Then visit http://localhost:5173 (or the port shown in your terminal) to access the inspector interface.

Basic Usage

The server provides three main API functions: finding transport stops, getting alerts, and monitoring departures.

Finding Transport Stops

You can search for stops by name or location coordinates:

from api import find_transport_stops

# Search by name
stops = find_transport_stops(stop_name="Central Station")

# Search by coordinates with a radius in meters
central_station = '151.206290:-33.884080:EPSG:4326'
stops = find_transport_stops(coord=central_station, radius=500)

Getting Transport Alerts

Retrieve information about service disruptions and alerts:

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)

Monitoring Real-time Departures

Get real-time departure information for specific stops:

from api import get_departure_monitor

# Get all departures from Central Station
departures = get_departure_monitor("200060")  # Central Station ID

# Get departures for a specific time
time_departures = get_departure_monitor("200060", time="15:30")

# Get only train departures
train_departures = get_departure_monitor("200060", mot_type=1)  # 1 = Train

Running the Demo

A comprehensive demo script is included to showcase all API functionality:

# 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

Testing the Installation

To verify your installation is working correctly, run the test suite:

uv run pytest

For coverage reporting:

uv run pytest --cov=api

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "transportnsw-mcp" '{"command":"uv","args":["run","mcp","dev","api.py"]}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "transportnsw-mcp": {
            "command": "uv",
            "args": [
                "run",
                "mcp",
                "dev",
                "api.py"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "transportnsw-mcp": {
            "command": "uv",
            "args": [
                "run",
                "mcp",
                "dev",
                "api.py"
            ]
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later