swiss-housing-mcp
swiss-housing-mcp
属于 Swiss Public Data MCP Portfolio 的一部分 — 连接 AI 代理与瑞士公共数据的开源 MCP 服务器。私人项目,与任何雇主或机构无关。
用于瑞士联邦建筑与住宅登记册 (GWR/RegBL) 的 MCP 服务器 — 建筑、住宅和建设管线
🎯 锚点演示查询
«自 2020 年以来苏黎世市新建了多少套住宅,其中 4 室及以上的有多少套——目前又有多少套正在建设中?»
已针对 2026-07-24 的实时数据转储进行验证:自 2020 年以来新建住宅 16'164 套(其中 27.4% 为 4 室及以上——家庭住房的代理指标),以及目前正在建设的 7'287 套住宅。今天正在建设的住宅就是 1–3 年后的家庭:这是学校空间规划的早期指标。
演示
Related MCP server: swiss-apis-mcp
概述
GWR/RegBL 之于建筑,正如 Zefix 之于公司:它不是众多数据源之一,而是联邦登记册,其标识符(建筑的 EGID、住宅的 EWID)在瑞士行政数据中充当连接键。该服务器通过 MCP 工具公开登记册的公共提取数据——建筑查询、地址地理编码、按市镇划分的建设统计、市镇以下边界框分析,以及规划/建设管线。
address_to_egid 是使其他数据源具备 EGID 能力的插头:输入地址,输出联邦标识符和 LV95 坐标。
架构决策
该服务器使用架构 B(混合:优先转储,API 回退)。
理由(已于 2026-07-24 实时验证):
公共州级转储(
public.madd.bfs.admin.ch/{canton}.zip)每日刷新(约 05:30 CET),并附带现成的data.sqlite,包含表building(ZH 有 399'830 行)、entrance、dwelling(ZH 有 894'631 行)和code。无需 CSV 解析,无需认证。api3.geo.admin.ch(find / identify / SearchServer)无需认证即可可靠地用于单实体查询和地理编码,但无法扩展到区域级聚合(结果限制)。在
/api/buildings/{egid}探测的 MADD REST 端点返回 404;在路径和认证状态明确之前将其排除——这不是障碍,因为所有第一阶段工具无需它即可工作。
后果:
州级转储在磁盘上缓存,TTL 为 24 小时(可通过
SWISS_HOUSING_DUMP_TTL_HOURS配置)。聚合和空间查询以只读 SQL 方式针对缓存的 SQLite 运行;单次查询和地理编码则访问实时 API。
每个响应都带有
source(归属)和provenance(daily_dump|live_api|cached)。
实时探测结果(2026-07-24)
端点 | HTTP | 状态 | 备注 |
| 200 | ✅ 可用 | 完整属性集,无需认证 |
| 200 | ✅ 可用 | 77 个属性,包括 EGID/EWID |
| 200 | ✅ 可用 |
|
| 200 | ✅ 可用 | 121 MB,每日刷新,包含 |
| 404 | ❌ 已排除 | 路径/认证不明确 |
无效 EGID 的 find 查询 | 200 | ⚠️ 软错误 | 空的 |
功能
lookup_building(egid)— 按联邦标识符查询单个建筑(实时 API)address_to_egid(address)— 将任何瑞士地址地理编码为 EGID/EDID + LV95lookup_dwellings(egid)— 建筑的所有住宅,包含房间数、面积、楼层new_construction(municipality_bfs, since_year)— 年度新建住宅,包括 4 室及以上家庭住房占比construction_pipeline(municipality_bfs)— 已规划 / 已批准 / 正在建设buildings_in_bbox(e_min, n_min, e_max, n_max)— 市镇以下分析(例如学区)municipality_housing_stats(municipality_bfs)— 住房存量和房间大小构成explain_code(attribute, code)— 通过官方 DE/FR/IT 代码表解码 GWR 代码dump_status()— 缓存新鲜度,优雅降级入口点
先决条件
Python 3.10+
每个缓存的州级转储约需 130 MB 磁盘空间(ZH)
无需 API 密钥——第一阶段无需认证
安装
uvx swiss-housing-mcp # once published on PyPI
# or from source
pip install -e .用法 / 快速开始
Claude Desktop(claude_desktop_config.json):
{
"mcpServers": {
"swiss-housing": {
"command": "uvx",
"args": ["swiss-housing-mcp"]
}
}
}云(Render/Railway):
SWISS_HOUSING_TRANSPORT=streamable-http PORT=8000 swiss-housing-mcp配置
变量 | 默认值 | 用途 |
|
|
|
|
| 转储缓存目录 |
|
| 转储新鲜度窗口 |
MCP 协议版本
该服务器在同一端点上支持两个协议时代。客户端在连接上的第一个请求决定适用哪个时代;之后来自另一个时代的声明将被拒绝。
时代 | 修订版本 | 谁使用它 |
|
| 当今客户端使用的版本。服务器以所请求的修订版本应答,或者当请求要求更新版本时,以 |
每请求封套 |
| 携带 |
两个修订版本都固定在 tests/test_protocol_version.py 中,并针对已安装的 SDK 进行断言,因此 Dependabot 对 mcp 的升级不会悄悄移动任何一个。该服务器不构建 ASGI 应用来发送 initialize,因此该门禁断言的是 SDK 常量,而不是实测响应——这是较弱的形式,但明确说明而非含糊其辞。
请注意,SDK 的 LATEST_PROTOCOL_VERSION 是现代时代的别名,而不是握手时代——仅针对它进行固定会让当前客户端实际协商的时代自由漂移。
更新策略。 当门禁失败时,不要盲目编辑常量:阅读两个修订版本之间的规范变更日志,验证服务器仍然正常工作,然后一起移动常量、本节、README.de.md 和 CHANGELOG.md。
测试
PYTHONPATH=src pytest tests/ -m "not live" # CI-safe
PYTHONPATH=src pytest tests/ -m live # against real upstream项目结构
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已知限制
公共提取数据省略了完整 GWR 中与人员相关及部分敏感属性;向官方机构的数据交付通过 BFS/MADD 渠道进行。
坐标是建筑参考点(LV95),而非占地多边形——多边形连接(例如精确的学区边界)需要外部几何数据;
buildings_in_bbox覆盖矩形近似。GBAUJ(建造年份)在部分较旧建筑中缺失;期间代码(GBAUP)作为回退存在,但尚未公开。市镇→州的分辨率已为常见情况预置;其他情况请显式传递
canton。住房市场指数(IMPI、建筑价格指数、空置率)特意放在
swiss-statistics-mcp中——该服务器是登记层,而非统计层。
变更日志
参见 CHANGELOG.md
贡献
欢迎贡献——参见 CONTRIBUTING.md(Deutsch)。
安全
只读、无个人身份信息、无需认证——通过一组固定端点访问的公共联邦登记册。完整的安全态势及如何报告漏洞,请参见 SECURITY.md(Deutsch)。
许可证
MIT 许可证——参见 LICENSE。数据:GWR/RegBL,瑞士联邦统计局(BFS),开放政府数据,需注明出处。
作者
Hayal Oezkan · github.com/malkreide
致谢与相关项目
组合中的姊妹项目:
swiss-statistics-mcp(指数、STAT-TAB)、zurich-opendata-mcp(城市级数据)
Available Tools
9 toolsaddress_to_egidARead-only
Geocode a Swiss address to EGID/EDID and LV95 coordinates.
This is the bridge that makes other data sources EGID-capable: address in → federal building identifier out.
Inputs: address (required), limit. Returns: query, source, matches, provenance
buildings_in_bboxARead-only
Aggregate buildings/dwellings inside an LV95 bounding box.
Enables sub-municipal analysis, e.g. school districts: pass the bounding box of a Schulkreis to count new construction within it. LV95 (EPSG:2056): east ~2'480'000-2'840'000, north ~1'070'000-1'300'000.
Inputs: e_max (required), e_min (required), n_max (required), n_min (required), +2 more. Returns: source, bbox_lv95, buildings, dwellings, +3 more
construction_pipelineBRead-only
Buildings and dwellings in the planning/construction pipeline of a municipality.
Breaks down by status: projected (GSTAT 1001), approved (1002), under construction (1003). Dwellings under construction today are households in 1-3 years — the early indicator for school-space planning.
Inputs: municipality_bfs (required), canton. Returns: note, source, pipeline, provenance, +2 more
dump_statusARead-only
Cache status of the cantonal GWR dumps (graceful-degradation entry point).
Always returns an evaluable status — never silently empty records. If a source is unreachable, this tool tells you when data was last refreshed.
Inputs: no named parameters. Returns: note, dumps, source, ttl_hours, +1 more
explain_codeARead-only
Decode a GWR code value (e.g. GSTAT=1004, GKAT=1020) into human-readable labels.
Uses the official code table shipped with the dump (DE/FR/IT).
Inputs: code (required), attribute (required), canton. Returns: source, provenance, explanations
lookup_buildingARead-only
Look up a single building by its EGID (federal building identifier).
Uses the live geo.admin.ch API — always current, no dump download needed. The EGID is the join key used across Swiss administrative data.
Inputs: egid (required). Returns: found, source, building, provenance
lookup_dwellingsARead-only
List all dwellings (EWID) of a building from the daily cantonal dump.
Includes rooms, floor area, floor and status per dwelling.
Inputs: egid (required), canton. Returns: egid, count, source, dwellings, +1 more
municipality_housing_statsCRead-only
Housing stock overview of a municipality: buildings, dwellings, room-size mix.
Inputs: municipality_bfs (required), canton. Returns: source, provenance, municipality, buildings_total, +4 more
new_constructionBRead-only
New residential construction per year for a municipality (existing buildings).
Returns buildings, dwellings and 4+ room dwellings per year — the 4+ room share is a proxy for family housing and thus for future pupil numbers. Municipality is identified by its BFS number (e.g. 261 = City of Zurich).
Inputs: municipality_bfs (required), canton, since_year. Returns: source, per_year, provenance, since_year, +5 more
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 resource or action: building lookup, dwelling lookup, address geocoding, bbox aggregation, municipal stock, pipeline, code decoding, and cache status. The closest pair, municipality_housing_stats and new_construction, is still clearly differentiated as stock overview vs. time-series construction.
All names are lowercase snake_case and readable, but conventions are mixed: some follow verb_noun (lookup_building, explain_code, dump_status), while others are noun phrases (buildings_in_bbox, municipality_housing_stats, construction_pipeline). There is no single consistent prefix or verb pattern across the set.
Nine tools is well-scoped for a Swiss housing/GWR data server. Each tool covers a meaningful query or utility function without redundancy or bloat.
The tool surface covers key workflows: address-to-EGID resolution, building and dwelling lookup, bounding-box aggregation, municipal stock, pipeline, historical construction, and code explanation. Minor gaps exist, such as no municipality-by-BFS-number search tool and no bulk code-table listing, but agents can work around these.
Maintenance
Related MCP Connectors
Geocoding, routing, isochrones, traffic, weather, and place search for AI agents. 19 MCP tools.
Flat-rate US property/parcel search & CSV export for AI agents via MCP.
Agent-native MCP server over 49M+ US public and government records, privacy-first, always current.
Pay-per-use tool marketplace for AI agents. Search, price-check, and call APIs via MCP.
Related MCP Servers
- AlicenseAqualityBmaintenanceProvides AI-native access to Swiss Federal Statistical Office datasets through 9 tools for querying education, population, and cross-cantonal comparisons without authentication.1542 PyPI2MIT
- AlicenseBqualityDmaintenanceMCP server exposing all major Swiss official public APIs as native tools for any MCP-compatible AI agent.3412 npmMIT
- AlicenseAqualityBmaintenanceMCP server for Switzerland's national metadata catalogue, enabling AI agents to discover datasets, APIs, public services, and publishers through free-text search and structured queries.1337 PyPIMIT
- AlicenseAqualityFmaintenanceMCP server that connects AI models to Swiss federal geodata, offering tools for spatial queries like layer discovery, coordinate identification, building zones, and terrain heights.932 PyPIMIT