Runs on your machine from its package; the steps are below.
At most: only reads or looks up information.
Odel charges nothing per call. The publisher may charge for its own service.
Runs locally over stdio
This server isn't hosted β your MCP client launches it from a package registry. Use one of the commands below, or drop the config into your client (e.g. Claude Desktop).
Run
uvx sbb-opendata-mcp
MCP client config
{
"mcpServers": {
"sbb-opendata": {
"command": "uvx",
"args": [
"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.
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 β
Install uv (recommended):
curl -LsSf https://astral.sh/uv/install.sh | sh
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]"
# 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?"
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.
{
"mcpServers": {
"sbb-opendata": {
"command": "uvx",
"args": ["sbb-opendata-mcp"]
}
}
}
Config file locations:
~/Library/Application Support/Claude/claude_desktop_config.json%APPDATA%\Claude\claude_desktop_config.jsonRestart Claude Desktop β the server is downloaded automatically on first use.
Works with Cursor, Windsurf, VS Code + Continue, LibreChat, Cline and self-hosted
models via mcp-proxy β same configuration as above.
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.
| 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_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, and declares its shape
as outputSchema. Error results carry isError: true and
{error, upstream_unavailable} instead.
| 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 real-estate construction projects are running?" | sbb_get_real_estate_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
βββββββββββββββββββ βββββββββββββββββββββββββββββ ββββββββββββββββββββββββββββ
β Claude / AI ββββββΆβ SBB Open Data MCP ββββββΆβ data.sbb.ch β
β (MCP Host) βββββββ (MCP Server) βββββββ β
βββββββββββββββββββ β β β OpenDataSoft REST v2.1 β
β 9 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β
βββββββββββββββββββββββββββββ ββββββββββββββββββββββββββββ
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
year/canton are regex-validated and every value interpolated into an ODSQL where clause is escaped via a central helper.See SECURITY.md for the full security posture.
limit and pagination.This server speaks two protocol eras over the same endpoint. The client's first request on a connection decides which one applies; a later claim from the other era is refused.
| Era | Revision | Who reaches it |
|---|---|---|
initialize handshake | 2024-11-05 β¦ 2025-11-25 | What today's clients speak. The server answers with the revision asked for, or with the 2025-11-25 ceiling when the request asks for something newer. |
| Per-request envelope | 2026-07-28 | A request carrying the 2026-07-28 _meta envelope opens a modern connection. |
Both revisions are pinned in
tests/test_protocol_version.py and asserted
against the installed SDK, so a Dependabot bump of mcp cannot move either one
silently. Two wire tests send a real request per era through
mcp.streamable_http_app() β the app --http serves β and read the revision
from the response: a 2026-07-28 server/discover POST without session, and an
initialize asking for 2026-07-28 that comes back capped at 2025-11-25.
What the server itself contributes to 2026-07-28, beyond what the SDK does on
its own, is pinned in
tests/test_spec_2026_07_28.py: a complete
serverInfo (the modern era stamps it on every result β without version it
read ""), a top-level title on every tool, an outputSchema per tool that
both the server and the SDK client validate against, and ttlMs/cacheScope
on the listing methods.
Note that the SDK's LATEST_PROTOCOL_VERSION is an alias for the modern
era, not for the handshake era β pinning against it alone would leave the era
that current clients actually negotiate free to drift.
Update policy. When the gate fails, do not edit the constant blindly: read
the spec changelog between the two revisions, verify the server still behaves,
then move the constant, this section, README.de.md and
CHANGELOG.md together.
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
# Re-record the fixtures from data.sbb.ch (writes tests/fixtures/PROVENANCE.md)
python scripts/record_fixtures.py
The unit-test payloads are recorded, not invented. Source, retrieval date,
selection rule and SHA-256 per file are in
tests/fixtures/PROVENANCE.md.
tests/fixtures/dataset_fields.json is not a data excerpt but the contract:
the Explore v2.1 API declares each dataset's field names, and a select or
order_by on a field it does not have is answered with HTTP 400 β not with
fewer columns. TestFieldContract holds every field name the server uses
against that declaration, so the next rename fails a test instead of a user's
request. Until 2026-08-08 three of ten tools were permanently broken for
exactly this reason.
Live tests are not run by CI (
-m "not live"). Two of those three broken tools had live tests covering them βtest_live_search_waedenswilandtest_live_list_datasets. The coverage existed; the run did not.
See CHANGELOG.md
See CONTRIBUTING.md
See SECURITY.md (Deutsch) for the security posture and how to report a vulnerability.
MIT License β see LICENSE
Hayal Oezkan Β· github.com/malkreide
Run via uv's uvx β no clone or manual install needed. Add to your MCP client config (mcpServers for Claude Desktop, Cursor and Windsurf; use a top-level servers key for VS Code in .vscode/mcp.json):
{
"mcpServers": {
"sbb-opendata-mcp": {
"command": "uvx",
"args": [
"sbb-opendata-mcp"
]
}
}
}