swiss-housing-mcp
swiss-housing-mcp
Teil des Swiss Public Data MCP Portfolio — Open-Source-MCP-Server, die KI-Agenten mit Schweizer öffentlichen Daten verbinden. Privates Projekt, unabhängig von Arbeitgeber oder institutioneller Zugehörigkeit.
MCP-Server für das Schweizerische Gebäude- und Wohnungsregister (GWR/RegBL) — Gebäude, Wohnungen und die Bau-Pipeline
🎯 Anker-Demo-Abfrage
«Wie viele Wohnungen wurden seit 2020 in der Stadt Zürich neu gebaut, wie viele mit 4+ Zimmern — und wie viele sind derzeit im Bau?»
Verifiziert gegen den Live-Dump vom 2026-07-24: 16'164 neue Wohnungen seit 2020 (27,4% mit 4+ Zimmern — der Proxy für Familienwohnungen) und 7'287 Wohnungen derzeit im Bau. Wohnungen, die heute im Bau sind, sind Haushalte in 1–3 Jahren: der Frühindikator für die Schulraumplanung.
Demo
Related MCP server: swiss-apis-mcp
Überblick
Das GWR/RegBL ist für Gebäude das, was Zefix für Unternehmen ist: nicht eine Datenquelle unter vielen, sondern das Bundesregister, dessen Identifikatoren (EGID für Gebäude, EWID für Wohnungen) als Join-Keys über Schweizer Verwaltungsdaten dienen. Dieser Server stellt den öffentlichen Auszug des Registers über MCP-Tools bereit — Gebäudeabfragen, Adress-Geocoding, Baustatistiken pro Gemeinde, Analyse von Teilgemeinden per Bounding-Box und die Planungs-/Bau-Pipeline.
address_to_egid ist der Stecker, der andere Datenquellen EGID-fähig macht: Adresse rein, Bundesidentifikator und LV95-Koordinaten raus.
Architekturentscheidung
Dieser Server verwendet Architektur B (Hybrid: Dump-first, API-Fallback).
Begründung (live verifiziert am 2026-07-24):
Der öffentliche Kantons-Dump (
public.madd.bfs.admin.ch/{canton}.zip) wird täglich (~05:30 CET) aktualisiert und enthält eine fertigedata.sqlitemit den Tabellenbuilding(399'830 Zeilen für ZH),entrance,dwelling(894'631 Zeilen für ZH) undcode. Kein CSV-Parsing, keine Authentifizierung.api3.geo.admin.ch(find / identify / SearchServer) funktioniert zuverlässig ohne Authentifizierung für Einzelabfragen und Geocoding, skaliert aber nicht für flächendeckende Aggregationen (Ergebnislimits).Ein MADD-REST-Endpunkt, getestet unter
/api/buildings/{egid}, lieferte 404; er ist ausgeschlossen, bis Pfad und Auth-Status geklärt sind — kein Blocker, da alle Phase-1-Tools ohne ihn funktionieren.
Konsequenzen:
Kantonale Dumps werden mit einer TTL von 24 h auf der Festplatte zwischengespeichert (konfigurierbar über
SWISS_HOUSING_DUMP_TTL_HOURS).Aggregationen und räumliche Abfragen laufen als schreibgeschütztes SQL gegen das gecachte SQLite; Einzelabfragen und Geocoding nutzen die Live-API.
Jede Antwort enthält
source(Quellenangabe) undprovenance(daily_dump|live_api|cached).
Live-Testergebnisse (2026-07-24)
Endpoint | HTTP | Status | Note |
| 200 | ✅ funktioniert | voller Attributsatz, keine Authentifizierung |
| 200 | ✅ funktioniert | 77 Attribute inkl. EGID/EWID |
| 200 | ✅ funktioniert |
|
| 200 | ✅ funktioniert | 121 MB, tägliche Aktualisierung, enthält |
| 404 | ❌ ausgeschlossen | Pfad/Auth unklar |
Invalid EGID on find | 200 | ⚠️ weicher Fehler | leeres |
Funktionen
lookup_building(egid)— einzelnes Gebäude nach Bundesidentifikator (Live-API)address_to_egid(address)— geokodiert jede Schweizer Adresse zu EGID/EDID + LV95lookup_dwellings(egid)— alle Wohnungen eines Gebäudes mit Zimmern, Fläche, Stockwerknew_construction(municipality_bfs, since_year)— jährlicher Neubau inkl. Anteil Familienwohnungen mit 4+ Zimmernconstruction_pipeline(municipality_bfs)— geplant / bewilligt / im Baubuildings_in_bbox(e_min, n_min, e_max, n_max)— Analyse auf Teilgemeindeebene (z. B. Schulkreise)municipality_housing_stats(municipality_bfs)— Wohnungsbestand und Zimmergrössen-Mixexplain_code(attribute, code)— dekodiert GWR-Codes über die offizielle DE/FR/IT-Codetabelledump_status()— Cache-Frische, Einstiegspunkt für Graceful Degradation
Voraussetzungen
Python 3.10+
~130 MB Speicherplatz pro gecachtem Kantons-Dump (ZH)
Keine API-Schlüssel — Phase 1 ist authentifizierungsfrei
Installation
uvx swiss-housing-mcp # once published on PyPI
# or from source
pip install -e .Verwendung / Schnellstart
Claude Desktop (claude_desktop_config.json):
{
"mcpServers": {
"swiss-housing": {
"command": "uvx",
"args": ["swiss-housing-mcp"]
}
}
}Cloud (Render/Railway):
SWISS_HOUSING_TRANSPORT=streamable-http PORT=8000 swiss-housing-mcpKonfiguration
Variable | Default | Zweck |
|
|
|
|
| Dump-Cache-Verzeichnis |
|
| Dump-Frische-Fenster |
MCP-Protokollversion
Dieser Server spricht zwei Protokoll-Ären über denselben Endpunkt. Die erste Anfrage eines Clients auf einer Verbindung entscheidet, welche gilt; eine spätere Behauptung aus der anderen Ära wird abgelehnt.
Era | Revision | Wer erreicht sie |
|
| Was heutige Clients sprechen. Der Server antwortet mit der angefragten Revision oder mit der |
Per-request envelope |
| Eine Anfrage mit dem |
Beide Revisionen sind in tests/test_protocol_version.py festgelegt und werden gegen das installierte SDK geprüft, sodass ein Dependabot-Update von mcp keine der beiden stillschweigend verschieben kann. Dieser Server baut keine ASGI-App, um ein initialize durchzuschicken, daher prüft das Gate die SDK-Konstanten statt einer gemessenen Antwort — die schwächere Form, benannt statt unausgesprochen.
Beachten Sie, dass LATEST_PROTOCOL_VERSION des SDK ein Alias für die moderne Ära ist, nicht für die Handshake-Ära — wenn man nur dagegen pinnt, würde die Ära, die aktuelle Clients tatsächlich aushandeln, frei driften.
Update-Richtlinie. Wenn das Gate fehlschlägt, bearbeiten Sie die Konstante nicht blind: Lesen Sie das Spec-Changelog zwischen den beiden Revisionen, verifizieren Sie, dass der Server sich weiterhin korrekt verhält, und verschieben Sie dann die Konstante, diesen Abschnitt, README.de.md und CHANGELOG.md gemeinsam.
Testen
PYTHONPATH=src pytest tests/ -m "not live" # CI-safe
PYTHONPATH=src pytest tests/ -m live # against real upstreamProjektstruktur
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 publishBekannte Einschränkungen
Der öffentliche Auszug lässt personenbezogene und einige sensible Attribute des vollständigen GWR aus; offizielle Datenlieferungen an Behörden laufen über den BFS/MADD-Kanal.
Koordinaten sind Gebäude-Referenzpunkte (LV95), keine Grundriss-Polygone — Polygon-Joins (z. B. exakte Schulkreisgrenzen) benötigen externe Geometrien;
buildings_in_bboxdeckt die rechteckige Näherung ab.GBAUJ(Baujahr) fehlt bei einem Teil älterer Gebäude; Periodencodes (GBAUP) existieren als Fallback, sind aber noch nicht freigeschaltet.Die Auflösung Gemeinde→Kanton ist für häufige Fälle vorbefüllt; für andere explizit
cantonangeben.Wohnungsmarktindizes (IMPI, Baukostenindex, Leerstandsquote) leben bewusst in
swiss-statistics-mcp— dieser Server ist die Registerebene, nicht die Statistik-Ebene.
Changelog
Siehe CHANGELOG.md
Mitwirken
Beiträge sind willkommen — siehe CONTRIBUTING.md (Deutsch).
Sicherheit
Nur lesend, keine personenbezogenen Daten, keine Authentifizierung — ein öffentliches Bundesregister, das über eine feste Reihe von Endpunkten abgerufen wird. Siehe SECURITY.md (Deutsch) für die vollständige Haltung und wie Sie eine Schwachstelle melden.
Lizenz
MIT-Lizenz — siehe LICENSE. Daten: GWR/RegBL, Bundesamt für Statistik (BFS), Open Government Data mit Quellenangabe.
Autor
Hayal Oezkan · github.com/malkreide
Danksagungen & verwandte Projekte
Portfolio-Geschwister:
swiss-statistics-mcp(Indizes, STAT-TAB),zurich-opendata-mcp(Daten auf Stadtebene)
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.
CompanyLens is a remote MCP server giving AI agents instant access to official company registry data across 19 jurisdictions in Europe, the Americas, and Asia-Pacific. Eighteen read-only tools let you search companies and people, look up officers and beneficial owners, map corporate networks through shared directors, screen names against the UK disqualified directors register, find every company at a registered address, and pull filing history — all from a single connector. Visit our website: https://companylens.io
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.
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.1325 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.9MIT