BART (San Francisco Transit) MCP server

Integrates with BART's API to provide real-time train departure information in San Francisco.
Back to servers
Setup instructions
Provider
tchbw
Release date
Jan 11, 2025
Language
TypeScript
Stats
1 star

This MCP server provides a simple interface to access Bay Area Rapid Transit (BART) departure data. It implements the Model Context Protocol (MCP) to offer structured information about BART trains, allowing users to query departure times, station information, and other transit details.

Installation

The BART MCP server can be installed using pip:

pip install mcp-bart

Alternatively, you can clone the repository and install it directly:

git clone https://github.com/username/mcp-bart.git
cd mcp-bart
pip install -e .

Usage

Starting the Server

To start the MCP server, run the following command:

python -m mcp_bart.server

By default, the server will listen on port 8080. You can specify a different port using the --port option:

python -m mcp_bart.server --port 9000

Querying BART Departures

The server exposes endpoints that follow the MCP specification. You can query BART departures using HTTP requests:

curl http://localhost:8080/api/departures

Filtering Departures

You can filter departures by station using the station parameter:

curl http://localhost:8080/api/departures?station=montgomery

Supported Stations

The following stations are supported:

  • 12th St. Oakland City Center
  • 16th St. Mission
  • 19th St. Oakland
  • 24th St. Mission
  • Antioch
  • Ashby
  • Balboa Park
  • Bay Fair
  • Castro Valley
  • Civic Center/UN Plaza
  • Coliseum
  • Colma
  • Concord
  • Daly City
  • Downtown Berkeley
  • Dublin/Pleasanton
  • El Cerrito del Norte
  • El Cerrito Plaza
  • Embarcadero
  • Fremont
  • Fruitvale
  • Glen Park
  • Hayward
  • Lafayette
  • Lake Merritt
  • MacArthur
  • Millbrae
  • Montgomery St.
  • North Berkeley
  • North Concord/Martinez
  • Oakland International Airport
  • Orinda
  • Pittsburg/Bay Point
  • Pittsburg Center
  • Pleasant Hill/Contra Costa Centre
  • Powell St.
  • Richmond
  • Rockridge
  • San Bruno
  • San Francisco International Airport
  • San Leandro
  • South Hayward
  • South San Francisco
  • Union City
  • Walnut Creek
  • Warm Springs/South Fremont
  • West Dublin/Pleasanton
  • West Oakland

Configuration

Environment Variables

The server can be configured using environment variables:

  • BART_API_KEY: Your BART API key (optional)
  • BART_DEFAULT_STATION: Default station for queries
  • MCP_LOG_LEVEL: Log level (default: INFO)

Example:

export BART_API_KEY="your-api-key"
export BART_DEFAULT_STATION="montgomery"
python -m mcp_bart.server

Config File

You can also create a config file at ~/.mcp-bart/config.json:

{
  "api_key": "your-api-key",
  "default_station": "embarcadero",
  "log_level": "DEBUG"
}

Connecting with MCP Clients

This server implements the Model Context Protocol, which means you can use any MCP-compatible client to interact with it. Here's an example using the Python MCP client:

from mcp_client import MCPClient

client = MCPClient("http://localhost:8080")
departures = client.query("departures", {"station": "montgomery"})

for departure in departures:
    print(f"Train to {departure['destination']} departing at {departure['time']}")

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 "bart-mcp" '{"command":"npx","args":["-y","bart-mcp"]}'

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": {
        "bart-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "bart-mcp"
            ]
        }
    }
}

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": {
        "bart-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "bart-mcp"
            ]
        }
    }
}

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