MCP Server for Swiss Federal Railways (SBB) open data via data.sbb.ch
Project description
๐ sbb-opendata-mcp
๐จ๐ญ Part of the Swiss Public Data MCP Portfolio
MCP server connecting AI models to Swiss Federal Railways (SBB) open data โ passenger frequency, live rail disruptions, infrastructure & real-estate projects, train counts, platform data, rolling stock and station search from data.sbb.ch. No API key required.
Demo
Overview
sbb-opendata-mcp gives AI assistants like Claude direct access to public SBB data โ no copy-pasting or manual API calls. A question like "How many passengers passed through Zรผrich HB every day in 2024?" is answered with real measured data.
The SBB Open Data portal speaks the OpenDataSoft REST API (v2.1). This server
translates it into clean Markdown and JSON for the AI model, and adds MCP
structuredContent alongside the human-readable text so programmatic clients can
consume the underlying records without re-parsing. The server is model-agnostic
and works with any MCP-compatible client.
Anchor demo query: "Compare Zรผrich HB, Bern and Basel SBB by passenger frequency and platform capacity." โ More use cases by audience โ
Features
- ๐ Passenger frequency โ boardings/alightings by station and year (daily averages)
- ๐จ Live rail disruptions โ traffic messages, updated every 5 minutes
- ๐๏ธ Infrastructure projects โ station and line construction
- ๐ข Real-estate projects โ SBB property development (daily updates)
- ๐ Trains per segment โ train counts per route (SBB, BLS, SOB โฆ)
- ๐ค๏ธ Platform data โ length, type, area, step-free access
- ๐ Rolling stock โ capacity and year built
- ๐ Station comparison โ up to 10 stations across multiple datasets
- ๐ Stop search โ Swiss DiDok register (all of Switzerland)
- ๐ฆ Dataset catalogue โ list all ~89 SBB open datasets
- ๐ No API key โ all data is public and free to use
- โ๏ธ Dual transport โ stdio for Claude Desktop, Streamable HTTP for cloud deployment
Prerequisites
- Python 3.11+
- No API key โ all data comes from the public data.sbb.ch portal
Install uv (recommended):
curl -LsSf https://astral.sh/uv/install.sh | sh
Installation
From PyPI:
pip install sbb-opendata-mcp
Or with uvx (no permanent installation):
uvx sbb-opendata-mcp
For local development, install from a clone in editable mode:
git clone https://github.com/malkreide/sbb-opendata-mcp.git
cd sbb-opendata-mcp
pip install -e ".[dev]"
Quickstart
# Start the server (stdio mode for Claude Desktop)
sbb-opendata-mcp
Try it immediately in Claude Desktop:
"How many people boarded at Zรผrich HB daily in 2024?" "Are there any current disruptions on the Swiss rail network?"
Configuration
Environment Variables
The server needs no configuration to run over stdio. The variables below tune the optional Streamable HTTP transport, logging and observability.
| Variable | Effect | Default |
|---|---|---|
MCP_HOST |
Bind host for the HTTP transport. Keep 127.0.0.1 locally; only bind 0.0.0.0 inside a controlled container/cloud environment. |
127.0.0.1 |
MCP_PORT |
Port for the HTTP transport. | 8000 |
MCP_ALLOWED_HOSTS |
Comma-separated host allow-list for DNS-rebinding protection (e.g. your-app.onrender.com,your-app.onrender.com:*). |
localhost only |
MCP_ALLOWED_ORIGINS |
Comma-separated browser-origin allow-list (e.g. https://your-app.onrender.com). |
(none) |
LOG_LEVEL |
Log verbosity (DEBUG/INFO/WARNING/โฆ). |
INFO |
LOG_FORMAT |
json for structured logs; anything else for human-readable text. Always written to stderr. |
text |
๐ DNS-rebinding / Origin protection is always on; localhost is allow-listed so local HTTP development works out of the box. Logs go to stderr โ stdout is reserved for the stdio JSON-RPC channel.
Claude Desktop Configuration
{
"mcpServers": {
"sbb-opendata": {
"command": "uvx",
"args": ["sbb-opendata-mcp"]
}
}
}
Config file locations:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
Restart Claude Desktop โ the server is downloaded automatically on first use.
Other MCP Clients
Works with Cursor, Windsurf, VS Code + Continue, LibreChat, Cline and self-hosted
models via mcp-proxy โ same configuration as above.
Cloud Deployment (Streamable HTTP)
For use via claude.ai in the browser or remote servers (e.g. Render.com). The cloud transport is Streamable HTTP (endpoint /mcp).
Docker (recommended):
# Build + run with explicit resource limits (see docker-compose.yml)
docker compose up --build
# โ http://127.0.0.1:8000/mcp
The image is a multi-stage build running as a non-root user; docker-compose.yml
adds read_only, no-new-privileges and memory/CPU/PID limits.
Manual / Render.com:
pip install -e .
# Bind publicly (behind a rate-limiting reverse proxy) and configure
# DNS-rebinding / Origin protection for your hostname:
export MCP_HOST=0.0.0.0
export MCP_ALLOWED_HOSTS="your-app.onrender.com,your-app.onrender.com:*"
export MCP_ALLOWED_ORIGINS="https://your-app.onrender.com"
python -m sbb_opendata_mcp.server --http --port 8000
โ ๏ธ Binding: In a network transport the server binds to
127.0.0.1by default so a locally started server is not exposed to your whole network. SetMCP_HOST=0.0.0.0only in a container/cloud environment where binding to all interfaces is intended (the Docker image does this for you), and place the server behind a reverse proxy that enforces rate limiting (and authentication, if the endpoint should not be public). SeeSECURITY.md.
Available Tools
| Tool | Description | Data Update |
|---|---|---|
sbb_get_passenger_frequency |
Boardings/alightings by station and year (daily avg.) | Annual |
sbb_get_rail_disruptions |
Live rail traffic messages | Every 5 min. |
sbb_get_infrastructure_construction_projects |
Infrastructure construction (stations, lines) | Ongoing |
sbb_get_real_estate_projects |
SBB real estate development projects | Daily |
sbb_get_trains_per_segment |
Train counts per route segment (SBB, BLS, SOB โฆ) | Annual |
sbb_get_platform_data |
Platform data (length, type, area) | Ongoing |
sbb_get_rolling_stock |
Rolling stock (capacity, year built) | Ongoing |
sbb_compare_stations |
Compare up to 10 stations (multi-dataset) | โ |
sbb_search_stations |
Search stops (Swiss DiDok register, all CH) | Ongoing |
sbb_list_datasets |
List all ~89 SBB open datasets | โ |
All tools support response_format: "markdown" (human-readable) and "json"
(machine-readable), plus pagination. Every tool also returns MCP structuredContent
(the underlying records/metadata) alongside the rendered text.
Example Use Cases
| Query | Tool |
|---|---|
| "How many people boarded at Zรผrich HB daily in 2024?" | sbb_get_passenger_frequency |
| "Are there any current disruptions on the Swiss rail network?" | sbb_get_rail_disruptions |
| "Compare Zรผrich HB, Bern and Basel SBB" | sbb_compare_stations |
| "Which SBB construction projects are active in Zรผrich?" | sbb_get_infrastructure_construction_projects |
| "How many trains run yearly on the ZรผrichโWinterthur route?" | sbb_get_trains_per_segment |
| "Which stops exist in Wรคdenswil?" | sbb_search_stations |
โ More use cases by audience
Architecture
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Claude / AI โโโโโโถโ SBB Open Data MCP โโโโโโถโ data.sbb.ch โ
โ (MCP Host) โโโโโโโ (MCP Server) โโโโโโโ โ
โโโโโโโโโโโโโโโโโโโ โ โ โ OpenDataSoft REST v2.1 โ
โ 10 Tools โ โ (public, no API key) โ
โ Stdio | Streamable HTTP โ โ โ
โ โ โ passagierfrequenz โ
โ Shared httpx client โ โ rail-traffic-information โ
โ (pooled, lifespan-managed)โ โ construction-projects โ
โ ODSQL escaping + Pydantic โ โ perron ยท rollmaterial โ
โ validation โ โ zugzahlen ยท dienststellenโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Project Structure
sbb-opendata-mcp/
โโโ src/sbb_opendata_mcp/
โ โโโ __init__.py
โ โโโ server.py # FastMCP server, all 10 tool definitions
โโโ tests/
โ โโโ test_server.py # Unit + live API smoke tests
โโโ audits/ # MCP best-practice audit evidence
โโโ docs/assets/demo.svg # README demo asset
โโโ .github/workflows/ci.yml # GitHub Actions (Python 3.11/3.12/3.13)
โโโ Dockerfile # Multi-stage, non-root runtime image
โโโ docker-compose.yml # Local run with resource limits
โโโ claude_desktop_config.json # Example Claude Desktop config
โโโ pyproject.toml
โโโ CHANGELOG.md
โโโ CONTRIBUTING.md
โโโ SECURITY.md
โโโ EXAMPLES.md
โโโ LICENSE
โโโ README.md # This file (English)
โโโ README.de.md # German version
Safety & Limits
- Read-only: All 10 tools perform read-only HTTP GET requests โ no data is written, modified, or deleted upstream.
- No personal data: Queries are transient and not stored. The portal returns aggregated statistics, infrastructure and operational metadata. No PII is processed or retained.
- No API key: Data is public and free. There is no authentication and no secret to manage.
- Injection-hardened:
year/cantonare regex-validated and every value interpolated into an ODSQLwhereclause is escaped via a central helper. - Data freshness: Real-time tools (disruptions) reflect the upstream source at query time; statistical datasets update annually/daily (see the tool table).
- Terms of service: Data is published under the data.sbb.ch licence (NonCommercialAllowed-CommercialAllowed-ReferenceRequired).
- No guarantees: This server is a community project, not affiliated with SBB. Availability depends on the upstream API.
See SECURITY.md for the full security posture.
Known Limitations
- Passenger frequency: Updated annually; the latest full year may lag by some months.
- Rail disruptions: Returns all current Swiss rail messages โ use
limitand pagination. - Trains per segment: Counts are yearly aggregates, not real-time.
- Station search: Covers the full Swiss DiDok register (all operators), not just SBB.
- No rate limiting of its own: Place a public HTTP deployment behind a rate-limiting reverse proxy.
Testing
No API key is required.
# Unit tests (no network required)
PYTHONPATH=src pytest tests/ -m "not live"
# Live API smoke tests (require network access to data.sbb.ch)
PYTHONPATH=src pytest tests/ -m live
Changelog
See CHANGELOG.md
Contributing
See CONTRIBUTING.md
License
MIT License โ see LICENSE
Author
Hayal Oezkan ยท github.com/malkreide
Credits & Related Projects
- Data: data.sbb.ch โ Swiss Federal Railways (SBB) Open Data, OpenDataSoft REST API v2.1
- Protocol: Model Context Protocol โ Anthropic / Linux Foundation
- Related:
- swiss-transport-mcp โ real-time timetables, journeys & disruptions (opentransportdata.swiss)
- swiss-road-mobility-mcp โ micromobility & EV charging
- zurich-opendata-mcp โ MCP server for Zurich city open data
- Portfolio: Swiss Public Data MCP Portfolio
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sbb_opendata_mcp-0.3.0.tar.gz.
File metadata
- Download URL: sbb_opendata_mcp-0.3.0.tar.gz
- Upload date:
- Size: 101.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1586e4efb881c68f35257c5d1c995f090d0513401b30c419201d6c3618746a3f
|
|
| MD5 |
0af2ff46cd0e120a3eb972952090502e
|
|
| BLAKE2b-256 |
ebcfa781766744bff2deb71d8a5c2a60607a3612e0efbdf66f0ae208ae845ead
|
Provenance
The following attestation bundles were made for sbb_opendata_mcp-0.3.0.tar.gz:
Publisher:
publish.yml on malkreide/sbb-opendata-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sbb_opendata_mcp-0.3.0.tar.gz -
Subject digest:
1586e4efb881c68f35257c5d1c995f090d0513401b30c419201d6c3618746a3f - Sigstore transparency entry: 1740468523
- Sigstore integration time:
-
Permalink:
malkreide/sbb-opendata-mcp@462ea92984160d6091b9fa5880bcac896c040381 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/malkreide
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@462ea92984160d6091b9fa5880bcac896c040381 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file sbb_opendata_mcp-0.3.0-py3-none-any.whl.
File metadata
- Download URL: sbb_opendata_mcp-0.3.0-py3-none-any.whl
- Upload date:
- Size: 19.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1cca79353d0e42577b8b1aaf496f26c14a97f151b1ae57ce68947fc6a26a756d
|
|
| MD5 |
55bcbb3ba8b8e6b111bc8a847998ce32
|
|
| BLAKE2b-256 |
fc0408890ff1d2ca57fa41f48eab4d4341f7444ba9dd0a2168b7a0fd643e73e6
|
Provenance
The following attestation bundles were made for sbb_opendata_mcp-0.3.0-py3-none-any.whl:
Publisher:
publish.yml on malkreide/sbb-opendata-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sbb_opendata_mcp-0.3.0-py3-none-any.whl -
Subject digest:
1cca79353d0e42577b8b1aaf496f26c14a97f151b1ae57ce68947fc6a26a756d - Sigstore transparency entry: 1740468532
- Sigstore integration time:
-
Permalink:
malkreide/sbb-opendata-mcp@462ea92984160d6091b9fa5880bcac896c040381 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/malkreide
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@462ea92984160d6091b9fa5880bcac896c040381 -
Trigger Event:
workflow_dispatch
-
Statement type: