Skip to main content
Glama
swiss-housing-mcp

swiss-housing-mcp

by malkreide

swiss-housing-mcp

Swiss Public Data MCP Portfolio の一部 — AIエージェントをスイスの公開データに接続するオープンソースMCPサーバー。個人プロジェクトであり、雇用主や機関との関係はありません。

Version License: MIT Python MCP

スイス連邦建物・住居登録簿(GWR/RegBL)のためのMCPサーバー — 建物、住居、そして建設パイプライン

🇩🇪 Deutsche Version


🎯 アンカーデモクエリ

「2020年以降、チューリッヒ市で新築された住居は何戸か、そのうち4室以上は何戸か — そして現在建設中の住居は何戸か?」

2026-07-24にライブダンプで検証済み: 2020年以降の新築住居16,164戸(うち4室以上は27.4% — 家族向け住宅の代理指標)、そして現在建設中の住居7,287戸。現在建設中の住居は1〜3年後の世帯数であり、学校スペース計画の早期指標です。

デモ

Demo: Claude using new_construction and construction_pipeline


Related MCP server: swiss-apis-mcp

概要

GWR/RegBLは、建物にとってZefixが企業にとってそうであるような存在です。つまり、多くのデータソースの1つではなく、連邦登録簿であり、その識別子(建物のEGID、住居のEWID)はスイスの行政データ全体で結合キーとして機能します。このサーバーは、登録簿の公開抽出データをMCPツールを通じて公開します — 建物検索、住所ジオコーディング、自治体ごとの建設統計、自治体以下の境界ボックス分析、そして計画・建設パイプラインです。

address_to_egid は、他のデータソースをEGID対応にするプラグです。住所を入力すると、連邦識別子とLV95座標を出力します。

アーキテクチャの決定

このサーバーは**アーキテクチャB(ハイブリッド: ダンプ優先、APIフォールバック)**を使用します。

根拠(2026-07-24にライブ検証済み):

  • 公開カントンダンプ(public.madd.bfs.admin.ch/{canton}.zip)は毎日(~05:30 CET)更新され、building(ZHで399,830行)、entrance、dwelling(ZHで894,631行)、code のテーブルを持つ既製の data.sqlite を提供します。CSV解析も認証も不要です。

  • api3.geo.admin.ch(find / identify / SearchServer)は、単一エンティティの検索とジオコーディングに対して認証なしで確実に動作しますが、広域集計にはスケールしません(結果制限)。

  • /api/buildings/{egid} でプローブしたMADD RESTエンドポイントは404を返しました。パスと認証ステータスが明確になるまで除外されます — すべてのフェーズ1ツールがそれなしで動作するため、ブロッカーにはなりません。

結果:

  • カントンダンプは24時間のTTL(SWISS_HOUSING_DUMP_TTL_HOURS で設定可能)でディスクにキャッシュされます。

  • 集計と空間クエリは、キャッシュされたSQLiteに対する読み取り専用SQLとして実行されます。単一検索とジオコーディングはライブAPIにアクセスします。

  • すべてのレスポンスには source(帰属)と provenance(daily_dump | live_api | cached)が含まれます。

ライブプローブの調査結果(2026-07-24)

エンドポイント

HTTP

ステータス

注記

api3.geo.admin.ch …/find (EGID検索)

200

✅ 動作

完全な属性セット、認証不要

api3.geo.admin.ch …/identify (座標)

200

✅ 動作

EGID/EWIDを含む77属性

…/SearchServer (住所 → EGID)

200

✅ 動作

featureId = {EGID}_{EDID}; 軸の入れ替え: y=東, x=北

public.madd.bfs.admin.ch/zh.zip

200

✅ 動作

121 MB、毎日更新、data.sqlite を含む

madd.bfs.admin.ch/api/buildings/{egid}

404

❌ 除外

パス/認証が不明

findでの無効なEGID

200

⚠️ ソフトエラー

空の results 配列 — HTTPエラーではない

機能

  • lookup_building(egid) — 連邦識別子による単一建物の検索(ライブAPI)

  • address_to_egid(address) — スイスの住所をEGID/EDID + LV95にジオコーディング

  • lookup_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キー不要 — フェーズ1は認証不要

インストール

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

設定

変数

デフォルト

目的

SWISS_HOUSING_TRANSPORT

stdio

stdio | streamable-http | sse

SWISS_HOUSING_CACHE

~/.cache/swiss-housing-mcp

ダンプキャッシュディレクトリ

SWISS_HOUSING_DUMP_TTL_HOURS

24

ダンプの鮮度ウィンドウ

MCPプロトコルバージョン

このサーバーは、同じエンドポイント上で2つのプロトコル時代を話します。接続時のクライアントの最初のリクエストがどちらが適用されるかを決定します。もう一方の時代からの後続の主張は拒否されます。

時代

リビジョン

誰が到達するか

initialize ハンドシェイク

2024-11-05 … 2025-11-25

今日のクライアントが話すもの。サーバーは要求されたリビジョンで応答するか、要求がより新しいものを求める場合は 2025-11-25 の上限で応答します。

リクエストごとのエンベロープ

2026-07-28

2026-07-28 の _meta エンベロープを運ぶリクエストは、モダンな接続を開きます。

両方のリビジョンは tests/test_protocol_version.py に固定され、 インストールされたSDKに対して検証されます。したがって、mcp のDependabotによるバンプがどちらかを静かに動かすことはできません。このサーバーは initialize を送信するためのASGIアプリを構築しないため、ゲートは測定された応答ではなくSDK定数を検証します — 弱い形式ですが、言及されないままよりも明確です。

SDKの LATEST_PROTOCOL_VERSION はモダンな時代のエイリアスであり、ハンドシェイク時代のものではないことに注意してください。それだけに固定すると、現在のクライアントが実際に交渉する時代が自由に漂流する可能性があります。

更新ポリシー。 ゲートが失敗した場合、定数を盲目的に編集しないでください。2つのリビジョン間の仕様変更ログを読み、サーバーがまだ正しく動作することを確認してから、定数、このセクション、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

クレジットと関連プロジェクト

Available Tools

9 tools
address_to_egidA
Read-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_bboxA
Read-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_pipelineB
Read-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_statusA
Read-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_codeA
Read-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_buildingA
Read-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_dwellingsA
Read-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_statsC
Read-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_constructionB
Read-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

    A3.5/5.0

    Scored across 9 tools

    Disambiguation5/5

    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.

    Naming Consistency3/5

    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.

    Tool Count5/5

    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.

    Completeness4/5

    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

    ActivityMaintained
    ResponsivenessLimited data

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      B
      maintenance
      Provides AI-native access to Swiss Federal Statistical Office datasets through 9 tools for querying education, population, and cross-cantonal comparisons without authentication.
      15
      42 PyPI
      2
      MIT
    • A
      license
      A
      quality
      B
      maintenance
      MCP 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.
      13
      25 PyPI
      MIT