Swiss Housing Mcp

io.github.malkreide由 GitHub 账号 malkreide 发布v0.2.0更新于 Oct 24, 2026

Swiss Register of Buildings and Dwellings (GWR/RegBL): EGID/EWID lookup, geocoding, housing stats

概览

AI 生成的概览

面向瑞士联邦建筑物与住宅登记册(GWR/RegBL)的只读 MCP 服务器,支持 EGID/EWID 查询、地址地理编码与市政住房统计。

可以做什么
  • 按联邦 EGID 查询单栋建筑,并列出其住宅的房间数、面积与楼层
  • 将任意瑞士地址地理编码为 EGID/EDID 及 LV95 坐标
  • 按市政统计某年以来的新建住宅数量(含 4 间及以上户型占比),并查看规划、审批与在建项目
  • 汇总某市政的住房存量与户型面积构成,或按矩形范围列出建筑以做分区分析
  • 用官方德/法/意代码表解读 GWR 属性代码,并查看缓存新鲜度
适用场景
当助手需要以联邦标识符关联的瑞士建筑或住宅数据时适用,例如某市政的住房供给问题、用于规划的在建项目指标,或把其他瑞士数据关联到 EGID。它属于登记册层,而非统计或市场指数来源。
运行要求
本地 Python 3.10+ 进程,通常通过 uvx 从 PyPI 运行。无需 API 密钥或账号。需要访问公开的州级数据转储与 geo.admin.ch 的网络。每个缓存的州转储约占 130 MB 磁盘;缓存目录与 24 小时有效期可通过 SWISS_HOUSING_CACHE 和 SWISS_HOUSING_DUMP_TTL_HOURS 配置。
安装前请注意
只读且无需认证,公开数据摘录不含个人数据。它会将较大的州级转储(ZH 约 121 MB)下载到本地磁盘并查询瑞士公开接口,因此请求会离开本机。坐标为建筑参考点而非轮廓多边形,部分老建筑缺少建造年份。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Swiss Housing Mcp,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

swiss-housing-mcp

Part of the Swiss Public Data MCP Portfolio — open-source MCP servers connecting AI agents to Swiss public data. Private project, independent of any employer or institutional affiliation.

[Version] [License: MIT] [Python] [MCP]

MCP server for the Swiss Federal Register of Buildings and Dwellings (GWR/RegBL) — buildings, dwellings, and the construction pipeline

🇩🇪 Deutsche Version


🎯 Anchor Demo Query

«How many dwellings were newly built in the City of Zurich since 2020, how many with 4+ rooms — and how many are currently under construction?»

Verified against the live dump on 2026-07-24: 16'164 new dwellings since 2020 (27.4% with 4+ rooms — the family-housing proxy), and 7'287 dwellings currently under construction. Dwellings under construction today are households in 1–3 years: the early indicator for school-space planning.

Demo

[Demo: Claude using new_construction and construction_pipeline]


Overview

The GWR/RegBL is to buildings what Zefix is to companies: not one data source among many, but the federal register whose identifiers (EGID for buildings, EWID for dwellings) serve as join keys across Swiss administrative data. This server exposes the register's public extract through MCP tools — building lookups, address geocoding, per-municipality construction statistics, sub-municipal bounding-box analysis, and the planning/construction pipeline.

address_to_egid is the plug that makes other data sources EGID-capable: address in, federal identifier and LV95 coordinates out.

Architecture decision

This server uses Architecture B (Hybrid: Dump-first, API-fallback).

Rationale (verified live on 2026-07-24):

  • The public cantonal dump (public.madd.bfs.admin.ch/{canton}.zip) is refreshed daily (~05:30 CET) and ships a ready-made data.sqlite with tables building (399'830 rows for ZH), entrance, dwelling (894'631 rows for ZH), and code. No CSV parsing, no auth.
  • api3.geo.admin.ch (find / identify / SearchServer) works reliably without authentication for single-entity lookups and geocoding, but does not scale to area-wide aggregations (result limits).
  • A MADD REST endpoint probed at /api/buildings/{egid} returned 404; it is excluded until path and auth status are clarified — no blocker, since all Phase-1 tools work without it.

Consequences:

  • Cantonal dumps are cached on disk with a 24 h TTL (configurable via SWISS_HOUSING_DUMP_TTL_HOURS).
  • Aggregations and spatial queries run as read-only SQL against the cached SQLite; single lookups and geocoding hit the live API.
  • Every response carries source (attribution) and provenance (daily_dump | live_api | cached).

Live probe findings (2026-07-24)

EndpointHTTPStatusNote
api3.geo.admin.ch …/find (EGID lookup)200✅ worksfull attribute set, no auth
api3.geo.admin.ch …/identify (coordinates)200✅ works77 attributes incl. EGID/EWID
…/SearchServer (address → EGID)200✅ worksfeatureId = {EGID}_{EDID}; axis swap: y=east, x=north
public.madd.bfs.admin.ch/zh.zip200✅ works121 MB, daily refresh, contains data.sqlite
madd.bfs.admin.ch/api/buildings/{egid}404❌ excludedpath/auth unclear
Invalid EGID on find200⚠️ soft errorempty results array — not an HTTP error

Features

  • lookup_building(egid) — single building by federal identifier (live API)
  • address_to_egid(address) — geocode any Swiss address to EGID/EDID + LV95
  • lookup_dwellings(egid) — all dwellings of a building with rooms, area, floor
  • new_construction(municipality_bfs, since_year) — yearly new construction incl. 4+ room family-housing share
  • construction_pipeline(municipality_bfs) — projected / approved / under construction
  • buildings_in_bbox(e_min, n_min, e_max, n_max) — sub-municipal analysis (e.g. school districts)
  • municipality_housing_stats(municipality_bfs) — housing stock and room-size mix
  • explain_code(attribute, code) — decode GWR codes via the official DE/FR/IT code table
  • dump_status() — cache freshness, graceful-degradation entry point

Prerequisites

  • Python 3.10+
  • ~130 MB disk per cached cantonal dump (ZH)
  • No API keys — Phase 1 is authentication-free

Installation

bash
uvx swiss-housing-mcp        # once published on PyPI
# or from sourcepip install -e .

Usage / Quickstart

Claude Desktop (claude_desktop_config.json):

json
{  "mcpServers": {    "swiss-housing": {      "command": "uvx",      "args": ["swiss-housing-mcp"]    }  }}

Cloud (Render/Railway):

bash
SWISS_HOUSING_TRANSPORT=streamable-http PORT=8000 swiss-housing-mcp

Configuration

VariableDefaultPurpose
SWISS_HOUSING_TRANSPORTstdiostdio | streamable-http | sse
SWISS_HOUSING_CACHE~/.cache/swiss-housing-mcpDump cache directory
SWISS_HOUSING_DUMP_TTL_HOURS24Dump freshness window

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 eras are measured, not inferred: tests/test_modern_era.py drives real requests of each era through this server's own ASGI app — the one __main__.py serves under SWISS_HOUSING_TRANSPORT=streamable-http — and reads the negotiated revision off the response body. Alongside it, tests/test_protocol_version.py pins both revisions against the installed SDK, so a Dependabot bump of mcp breaks the build before anyone reads the measurement.

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.

Identity on the modern era. The 2026-07-28 era has no initialize handshake: a connection is a single request carrying a _meta envelope. So server/discover is the only channel through which a modern client learns anything about this server, and the serverInfo block the SDK stamps into every result is the only place its identity appears. This server therefore declares version, title, description, websiteUrl and instructions. description and websiteUrl are read from the package metadata rather than repeated as literals — the SDK fills none of them in, and an unversioned server announces an empty version on every single response.

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

bash
PYTHONPATH=src pytest tests/ -m "not live"   # CI-safePYTHONPATH=src pytest tests/ -m live         # against real upstream

Project Structure

swiss-housing-mcp/├── src/swiss_housing_mcp/│   ├── server.py      # FastMCP tools (9)│   ├── gwr.py         # Dump store + geo.admin.ch client + retry│   ├── models.py      # Pydantic v2 envelopes (source + provenance)│   └── __main__.py    # Dual-transport entry point├── tests/             # respx-mocked + @pytest.mark.live└── .github/workflows/ # CI + OIDC PyPI publish

Known Limitations

  • The public extract omits person-related and some sensitive attributes of the full GWR; official data deliveries to authorities go through the BFS/MADD channel.
  • Coordinates are building reference points (LV95), not footprint polygons — polygon joins (e.g. exact school-district boundaries) need external geometries; buildings_in_bbox covers the rectangular approximation.
  • GBAUJ (construction year) is missing for a share of older buildings; period codes (GBAUP) exist as fallback but are not yet exposed.
  • Municipality→canton resolution is seeded for common cases; pass canton explicitly for others.
  • Housing-market indices (IMPI, construction price index, vacancy rate) deliberately live in swiss-statistics-mcp — this server is the register layer, not the statistics layer.

Changelog

See CHANGELOG.md

Contributing

Contributions are welcome — see CONTRIBUTING.md (Deutsch).

Security

Read-only, no PII, no authentication — a public federal register accessed through a fixed set of endpoints. See SECURITY.md (Deutsch) for the full posture and how to report a vulnerability.

License

MIT License — see LICENSE. Data: GWR/RegBL, Swiss Federal Statistical Office (BFS), open government data with attribution.

Author

Hayal Oezkan · github.com/malkreide

Credits & Related Projects

来源:README.md,提交 cece646

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

2
  1. v0.2.0最新Sep 20, 2026
  2. v0.1.0Sep 16, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分