
Sbb Opendata Mcp
io.github.malkreide由 GitHub 账号 malkreide 发布v0.4.0更新于 Oct 24, 2026
SBB Open Data via OpenDataSoft
概览
本地 MCP 服务器,让助手以只读方式访问瑞士联邦铁路开放数据:客运量、实时中断、站台、车辆等信息。
- 可以做什么
- 按车站和年份查询上下车客运量,并用专门的对比工具跨数据集比较最多十个车站。获取实时铁路交通中断消息和按线路区段的年度列车数量。查询站台详情、车辆运力与建造年份,以及 SBB 基础设施和房地产项目。在 DiDok 登记册中搜索瑞士车站,并列出约 89 个 SBB 开放数据集。结果以 Markdown 或 JSON 返回,附带结构化内容和分页。
- 适用场景
- 适合让助手基于官方开放数据回答关于瑞士铁路客流、当前中断、车站设施或 SBB 建设项目的 factual 问题,无需手动调用 API 或复制粘贴。
- 运行要求
- 以 Python 包形式通过 stdio 在本地运行(Python 3.11+),通常用 uvx 或 pip 启动。无需 API 密钥或账户。需要能访问 data.sbb.ch 的网络。可选环境变量用于调整 HTTP 传输、主机允许列表和日志。
安装
在 SourceWeft 中
- 打开 控制台中的 Sbb Opendata Mcp,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
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.
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):
Installation
From PyPI:
Or with uvx (no permanent installation):
For local development, install from a clone in editable mode:
Quickstart
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.
🔒 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
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):
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:
⚠️ 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
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
Architecture
Project Structure
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/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.
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.
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.
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):
来源:README.md,提交 05743e8
工具
0版本历史
2- v0.4.0最新Sep 27, 2026
- v0.3.4Sep 16, 2026
评分
已满足适用检查项的 50%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分