Skip to main content
Glama
README.md
# OC Transpo MCP Server for Learning

A Model Context Protocol (MCP) server for OC Transpo Ottawa, providing real-time transit data to AI agents and developers.

## Features

- **`get_vehicle_positions`**: Retrieves real-time latitude, longitude, and trip info for all active buses and trains.
- **`get_trip_updates`**: Fetches real-time arrival/departure delays and schedule updates.
- **`get_service_alerts`**: (Coming Soon) Standardized access to service disruptions (pending OC Transpo API activation).
- **FastMCP Integration**: Lightweight and easy to use with any MCP-compatible agent.
- **GTFS-RT Support**: Native protocol buffer parsing for live transit feeds.

## Prerequisites

- Python 3.10+
- [uv](https://docs.astral.sh/uv/) (recommended for dependency management)
- OC Transpo API Subscription Key (Get one at the [OC Transpo Developer Portal](https://nextrip-public-api.developer.azure-api.net/))

## Setup

1. **Clone the repository**:
   ```bash
   git clone <repository-url>
   ```

2. **Configure environment variables**:
   Create a `.env` file in the root directory:
   ```env
   Ocp_Apim_Subscription_Key=your_key_here
   ```

3. **Install dependencies**:
   ```bash
   uv sync
   ```

## Usage

### Running the MCP Server
Start the server using `uv`:
```bash
uv run mcp-server.py
```

### Testing with MCP Inspector
You can visually test the tools using the MCP Inspector:
```bash
npx -y @modelcontextprotocol/inspector uv run mcp-server.py
```

### Scripting Example
You can use the helper script `check_route.py` to filter vehicles by route ID:
```bash
uv run check_route.py 62
```

## Deployment

### Google Cloud Run
You can deploy this server to Google Cloud Run to make it accessible over the internet via HTTPS.

1.  **Build and Deploy**:
    ```bash
    gcloud run deploy octranspo-mcp \
      --source . \
      --region us-central1 \
      --allow-unauthenticated \
      --set-env-vars Ocp_Apim_Subscription_Key=YOUR_API_KEY
    ```

2.  **Access the Server**:
    The server is probably live at: `https://octranspo-mcp-PROJECT_ID.us-central1.run.app/mcp`

## Project Structure

- `mcp-server.py`: Main MCP server implementation.
- `octranspo.py`: API helper for GTFS-RT fetching and parsing.
- `check_route.py`: CLI tool for filtering live data.
- `test_api.py`: Connectivity and data parsing verification script.

## License

MIT

Made with ❤️ by Antigravity