Sbb Opendata Mcp

io.github.malkreide由 GitHub 帳號 malkreide 發布v0.4.0更新於 Oct 24, 2026

SBB Open Data via OpenDataSoft

已驗證STDIO僅桌面位置與生活資料與分析

概覽

AI 產生的概覽

本機 MCP 伺服器,讓助理以唯讀方式存取瑞士聯邦鐵路開放資料:客運量、即時中斷、月台、車輛等資訊。

可以做什麼
依車站與年份查詢上下車客運量,並用專門的比較工具跨資料集比較最多十個車站。取得即時鐵路交通中斷訊息與各路線區段的年度列車數量。查詢月台細節、車輛運能與建造年份,以及 SBB 基礎建設與房地產專案。在 DiDok 登記冊中搜尋瑞士車站,並列出約 89 個 SBB 開放資料集。結果以 Markdown 或 JSON 回傳,附帶結構化內容與分頁。
適用情境
適合讓助理根據官方開放資料回答關於瑞士鐵路客流、目前中斷、車站設施或 SBB 建設專案的事實性問題,不必手動呼叫 API 或複製貼上。
執行需求
以 Python 套件形式透過 stdio 在本機執行(Python 3.11+),通常以 uvx 或 pip 啟動。不需要 API 金鑰或帳號。需要能連線至 data.sbb.ch 的網路。選用環境變數可調整 HTTP 傳輸、主機允許清單與日誌。
安裝前請注意
所有工具皆為唯讀 HTTP GET 請求,不儲存個人資料。資料依 data.sbb.ch 授權公開,要求標示出處並允許商業使用。若啟用 HTTP 傳輸,請維持預設的 localhost 綁定,並將公開部署置於具備身分驗證的限流反向代理之後;伺服器本身沒有流量限制。這是與 SBB 無關的社群專案,可用性取決於上游 API。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 Sbb Opendata Mcp,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

🚆 sbb-opendata-mcp

🇨🇭 Part of the Swiss Public Data MCP Portfolio

[PyPI] [License: MIT] [Python 3.11+] [MCP] [Data Source] [CI]

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.

🇩🇪 Deutsche Version

Demo

[Demo: Claude queries SBB passenger frequency]


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):

bash
curl -LsSf https://astral.sh/uv/install.sh | sh

Installation

From PyPI:

bash
pip install sbb-opendata-mcp

Or with uvx (no permanent installation):

bash
uvx sbb-opendata-mcp

For local development, install from a clone in editable mode:

bash
git clone https://github.com/malkreide/sbb-opendata-mcp.gitcd sbb-opendata-mcppip install -e ".[dev]"

Quickstart

bash
# 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.

VariableEffectDefault
MCP_HOSTBind 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_PORTPort for the HTTP transport.8000
MCP_ALLOWED_HOSTSComma-separated host allow-list for DNS-rebinding protection (e.g. your-app.onrender.com,your-app.onrender.com:*).localhost only
MCP_ALLOWED_ORIGINSComma-separated browser-origin allow-list (e.g. https://your-app.onrender.com).(none)
LOG_LEVELLog verbosity (DEBUG/INFO/WARNING/…).INFO
LOG_FORMATjson 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

json
{  "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):

bash
# 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:

bash
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.0export 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.1 by default so a locally started server is not exposed to your whole network. Set MCP_HOST=0.0.0.0 only 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). See SECURITY.md.


Available Tools

ToolDescriptionData Update
sbb_get_passenger_frequencyBoardings/alightings by station and year (daily avg.)Annual
sbb_get_rail_disruptionsLive rail traffic messagesEvery 5 min.
sbb_get_real_estate_projectsSBB real estate development projectsDaily
sbb_get_trains_per_segmentTrain counts per route segment (SBB, BLS, SOB …)Annual
sbb_get_platform_dataPlatform data (length, type, area)Ongoing
sbb_get_rolling_stockRolling stock (capacity, year built)Ongoing
sbb_compare_stationsCompare up to 10 stations (multi-dataset)–
sbb_search_stationsSearch stops (Swiss DiDok register, all CH)Ongoing
sbb_list_datasetsList 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

QueryTool
"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


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 version

Safety & 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/canton are regex-validated and every value interpolated into an ODSQL where clause 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 limit and 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.

EraRevisionWho reaches it
initialize handshake2024-11-05 … 2025-11-25What 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 envelope2026-07-28A 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.


Testing

No API key is required.

bash
# 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_waedenswil and test_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

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):

json
{  "mcpServers": {    "sbb-opendata-mcp": {      "command": "uvx",      "args": [        "sbb-opendata-mcp"      ]    }  }}

來源:README.md,提交 05743e8

工具

0
SourceWeft 尚未在沙箱中啟動過該軟體包,因此其工具未知。

版本歷史

2
  1. v0.4.0最新Sep 27, 2026
  2. v0.3.4Sep 16, 2026

評分

已滿足適用檢查項的 50%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分

    請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。

  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具15 分

    請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。

  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分