SBB Open Data MCP Server
This server exposes 9 read-only tools for querying public Swiss Federal Railways (SBB) open data from data.sbb.ch — no API key required — so an AI model can look up passenger stats, live disruptions, infrastructure, rolling stock and station info.
Passenger frequency (
sbb_get_passenger_frequency): daily, workday and non-workday passenger averages per station and year, filterable by station name, canton ('ZH', 'BE') and year.Live rail disruptions (
sbb_get_rail_disruptions): current Swiss rail traffic messages (title, description, cause, timing, affected lines), refreshed every 5 minutes.Real-estate projects (
sbb_get_real_estate_projects): SBB property development projects with city, phase, construction/move-in dates and floor area.Trains per segment (
sbb_get_trains_per_segment): yearly train counts per route segment for SBB, BLS, SOB, DB and others, split by passenger/freight traffic.Platform data (
sbb_get_platform_data): platform length, gross/net area, type and step-free accessibility per station.Rolling stock (
sbb_get_rolling_stock): vehicle types with seating capacity (1st/2nd class), year built, length and weight.Station comparison (
sbb_compare_stations): side-by-side comparison of 2–10 stations across passenger frequency and platform metrics.Stop search (
sbb_search_stations): search the full Swiss DiDok stop register (all operators) by name and canton, returning UIC numbers and coordinates.Dataset catalogue (
sbb_list_datasets): list all ~89 SBB open datasets with IDs, titles, record counts and update frequency.Common options across tools: markdown or JSON output, pagination (limit/offset), and MCP
structuredContentplus declaredoutputSchemafor programmatic clients.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@SBB Open Data MCP Server Are there any current disruptions on the Swiss rail network?"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
🚆 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 →
Related MCP server: swiss-rail-mcp
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 | shInstallation
From PyPI:
pip install sbb-opendata-mcpOr with uvx (no permanent installation):
uvx sbb-opendata-mcpFor 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-mcpTry 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 |
| Bind host for the HTTP transport. Keep |
|
| Port for the HTTP transport. |
|
| Comma-separated host allow-list for DNS-rebinding protection (e.g. | localhost only |
| Comma-separated browser-origin allow-list (e.g. | (none) |
| Log verbosity ( |
|
|
|
|
🔒 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.jsonWindows:
%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/mcpThe 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 |
| Boardings/alightings by station and year (daily avg.) | Annual |
| Live rail traffic messages | Every 5 min. |
| SBB real estate development projects | Daily |
| Train counts per route segment (SBB, BLS, SOB …) | Annual |
| Platform data (length, type, area) | Ongoing |
| Rolling stock (capacity, year built) | Ongoing |
| Compare up to 10 stations (multi-dataset) | – |
| Search stops (Swiss DiDok register, all CH) | Ongoing |
| 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.
Example Use Cases
Query | Tool |
"How many people boarded at Zürich HB daily in 2024?" |
|
"Are there any current disruptions on the Swiss rail network?" |
|
"Compare Zürich HB, Bern and Basel SBB" |
|
"Which SBB real-estate construction projects are running?" |
|
"How many trains run yearly on the Zürich–Winterthur route?" |
|
"Which stops exist in Wädenswil?" |
|
Architecture
┌─────────────────┐ ┌───────────────────────────┐ ┌──────────────────────────┐
│ 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│
└───────────────────────────┘ └──────────────────────────┘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 versionSafety & Limits
Read-only: All 9 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.
MCP Protocol Version
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 |
|
| What today's clients speak. The server answers with the revision asked for, or with the |
Per-request envelope |
| A request carrying the |
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.
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
# Re-record the fixtures from data.sbb.ch (writes tests/fixtures/PROVENANCE.md)
python scripts/record_fixtures.pyThe 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.
Changelog
See CHANGELOG.md
Contributing
See CONTRIBUTING.md
Security
See SECURITY.md (Deutsch) for the security posture and how to report a vulnerability.
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
Installation
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"
]
}
}
}Available Tools
9 toolssbb_compare_stationsSBB Bahnhöfe vergleichenARead-onlyIdempotent
Vergleicht mehrere SBB-Bahnhöfe anhand Passagierfrequenz und Perrondaten.
Kombiniert drei Datensätze (Passagierfrequenz, Bahnhofnutzer, Perrons) zu einem kompakten Vergleich. Nützlich für Planungsentscheide, Präsentationen und Standortanalysen.
Args: params (CompareStationsInput): Parameter: - stations (list[str]): Liste von Bahnhofsnamen (2–10), z.B. ['Zürich HB', 'Bern'] - year (Optional[str]): Vergleichsjahr, z.B. '2024'
Returns: str: Tabellarischer Vergleich der Bahnhöfe mit Passagierfrequenz und Perron-Kennzahlen.
Inputs: params (required). Returns: year, stations
sbb_get_passenger_frequencySBB Passagierfrequenz nach BahnhofARead-onlyIdempotent
Ruft Passagierfrequenzdaten (Ein-/Aussteigende) für SBB-Bahnhöfe ab.
Datensatz wird jährlich aktualisiert. Enthält Tagesschnitt (DTV), Werktagesschnitt (DWV) und Nicht-Werktages-Schnitt (DNWV) pro Bahnhof und Jahr.
Args: params (PassengerFrequencyInput): Filterparameter: - station_name (Optional[str]): Bahnhofsname (Teilsuche) - canton (Optional[str]): Kantonskürzel, z.B. 'ZH' - year (Optional[str]): Jahr, z.B. '2024' - limit (int): Max. Resultate (1–100), Standard 20 - offset (int): Offset für Paginierung - response_format (str): 'markdown' oder 'json'
Returns: str: Passagierfrequenzdaten mit DTV/DWV-Werten und Paginierungsinfo. Schema: {station, year, daily_avg, workday_avg, non_workday_avg, canton, operator}
Inputs: params (required). Returns: A page of raw data.sbb.ch records plus pagination.
sbb_get_platform_dataSBB PerrondatenBRead-onlyIdempotent
Ruft Perrondaten (Länge, Fläche, Typ) für SBB-Bahnhöfe ab.
Enthält Perronlänge (m), Netto-/Bruttofläche (m²), Perrontyp und Angaben zur schienenfreien Zugänglichkeit.
Args: params (PlatformDataInput): Parameter: - station_name (Optional[str]): Bahnhofsname, z.B. 'Zürich HB' - platform_type (Optional[str]): Perrontyp, z.B. 'Mittelperron' - limit (int): Max. Resultate - offset (int): Paginierung - response_format (str): 'markdown' oder 'json'
Returns: str: Perrondaten mit Länge, Fläche und Typ. Schema: {station, platform_nr, type, length_m, gross_area_m2, net_area_m2, accessible}
Inputs: params (required). Returns: A page of raw data.sbb.ch records plus pagination.
sbb_get_rail_disruptionsSBB Bahnverkehrsstörungen (Live)ARead-only
Ruft aktuelle Bahnverkehrsstörungen und -meldungen ab (alle 5 Minuten aktualisiert).
Enthält Titel, Beschreibung, Ursache, Start-/Endzeitpunkt und betroffene Linien. Ideal für Echtzeit-Monitoring und Kommunikation bei Ereignissen.
Args: params (RailDisruptionsInput): Parameter: - limit (int): Max. Meldungen (1–100), Standard 20 - offset (int): Offset für Paginierung - response_format (str): 'markdown' oder 'json'
Returns: str: Liste aktueller Störungsmeldungen mit Zeitfenstern und Beschreibungen. Schema: {title, description, published, start, end, type, author}
Inputs: params (required). Returns: A page of raw data.sbb.ch records plus pagination.
sbb_get_real_estate_projectsSBB Immobilien-BauprojekteARead-onlyIdempotent
Ruft laufende SBB-Immobilien-Bauprojekte (Wohn- und Geschäftsbauten) ab.
Täglich aktualisiert. Enthält Projektname, Stadt, Bauphase, Nutzfläche, Baudaten und Beschreibungen (DE/FR/IT/EN).
Args: params (RealEstateProjectsInput): Parameter: - city (Optional[str]): Stadt, z.B. 'Zürich', 'Bern', 'Luzern' - phase (Optional[str]): Projektphase, z.B. 'CONSTRUCTION', 'PLANNING' - limit (int): Max. Resultate - offset (int): Paginierung - response_format (str): 'markdown' oder 'json'
Returns: str: Immobilien-Bauprojekte mit Baustart, Einzug und Nutzfläche. Schema: {title, city, phase, start_of_construction, move_in, area_m2, description}
Inputs: params (required). Returns: A page of raw data.sbb.ch records plus pagination.
sbb_get_rolling_stockSBB RollmaterialARead-onlyIdempotent
Ruft technische Daten zum SBB-Rollmaterial (Züge, Triebzüge, Wagen) ab.
Enthält Fahrzeugtyp, Sitzplatzkapazität (1./2. Kl.), Baujahr, Länge und Gewicht.
Args: params (RollingStockInput): Parameter: - vehicle_type (Optional[str]): Fahrzeugtyp, z.B. 'IC 2000', 'TGV', 'FV-Dosto' - limit (int): Max. Resultate - offset (int): Paginierung - response_format (str): 'markdown' oder 'json'
Returns: str: Rollmaterial-Daten mit Kapazität, Baujahr und technischen Kennzahlen. Schema: {vehicle_type, built_year, seats_1st, seats_2nd, total_seats, length_mm, weight_t}
Inputs: params (required). Returns: A page of raw data.sbb.ch records plus pagination.
sbb_get_trains_per_segmentSBB Züge pro StreckenabschnittBRead-onlyIdempotent
Ruft Anzahl Züge pro Streckenabschnitt und Verkehrstyp ab.
Deckt SBB, BLS, SOB, DB und weitere Infrastrukturbetreiberinnen ab. Enthält Personenverkehr und Güterverkehr, Trassenkilometer und Stromverbrauch.
Args: params (TrainsPerSegmentInput): Parameter: - line_name (Optional[str]): Streckenbezeichnung (Teilsuche) - operator (Optional[str]): Infrastrukturbetreiberin, z.B. 'SBB', 'BLS' - year (Optional[str]): Jahr, z.B. '2025' - traffic_type (Optional[str]): 'Personenverkehr' oder 'Gueterverkehr' - limit (int): Max. Resultate - offset (int): Paginierung - response_format (str): 'markdown' oder 'json'
Returns: str: Zugzahlen pro Streckenabschnitt mit Operator und Traffiktyp. Schema: {segment, line, operator, year, train_count, traffic_type, track_km}
Inputs: params (required). Returns: A page of raw data.sbb.ch records plus pagination.
sbb_list_datasetsSBB Open Data Datensätze auflistenARead-onlyIdempotent
Listet alle verfügbaren SBB Open Data Datensätze (data.sbb.ch) auf.
Gibt Dataset-ID, Titel, Anzahl Datensätze und Aktualisierungsfrequenz zurück. Nützlich zur Übersicht und Entdeckung neuer Datensätze.
Returns: str: Vollständige Liste aller SBB Open Data Datensätze. Schema: {dataset_id, title, records_count, update_frequency, themes}
Inputs: no named parameters. Returns: datasets, total_count
sbb_search_stationsSBB Haltestellen suchenARead-onlyIdempotent
Sucht Bahnhöfe und Haltestellen der Schweiz (DiDok-Liste des BAV).
Deckt alle öV-Haltestellen ab (nicht nur SBB). Enthält UIC-Nummern, Koordinaten, Kantone und Betreiberinformationen.
Args: params (StationSearchInput): Parameter: - query (str): Suchbegriff (mind. 2 Zeichen), z.B. 'Wädenswil', 'Zürich' - canton (Optional[str]): Kantonskürzel, z.B. 'ZH' - limit (int): Max. Resultate - response_format (str): 'markdown' oder 'json'
Returns: str: Haltestellenliste mit UIC, Kanton und Koordinaten. Schema: {name, uic, canton, operator, coordinates}
Inputs: params (required). Returns: results, total_count
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 9 tools
Each tool targets a distinct dataset or action (passenger frequency, disruptions, real estate, rolling stock, etc.), so most are easy to tell apart. There is mild overlap around station data: search_stations, get_platform_data, get_passenger_frequency, and compare_stations all touch station-level information, though their specific outputs differ.
All tools use the same 'sbb_' prefix followed by a consistent verb_noun pattern (get_, list_, compare_, search_). The convention is uniform throughout with no mixing of styles.
Nine tools is well-scoped for an open-data portal, with each tool mapping to a distinct SBB dataset or a useful aggregation. Nothing feels redundant or padded.
The surface covers the major SBB datasets plus helpful aggregations (compare_stations) and discovery (list_datasets, search_stations). It is read-only by nature, which fits an open-data server, but there is no generic 'get_dataset_by_id' tool to reach datasets beyond the curated set.
Maintenance
Related MCP Connectors
Hosted MCP server for live public-data APIs and Skills for AI agents.
This MCP server provides seamless access to Malaysia's government open data, including datasets, w…
MCP server for OpenAI API (chat completions, image generation, embeddings) via AceDataCloud
MCP server for building and testing AI agents with multi-model experimentation and insights.
Related MCP Servers
- AlicenseAqualityDmaintenanceAn MCP server that enables AI assistants to interact with the Netherlands Railways (NS) API for route planning, pricing, and real-time departure information. It provides tools for searching stations, planning trips with connections, and viewing real-time departure boards.31MIT
- AlicenseAqualityDmaintenanceA zero-authentication MCP server for Swiss public transport, enabling users to query train connections, disruptions, station facilities, and plan journeys using natural language.121MIT
- AlicenseAqualityDmaintenanceMCP server for Swiss public transport — connections, stationboards, real-time delays, and direct booking links for SBB.418 PyPI1MIT
- AlicenseNot gradedqualityBmaintenanceAn MCP server for real-time Italian railway data, enabling natural language queries about train schedules, delays, departures, arrivals, and live tracking via the Viaggiatreno API.7MIT