bbr-mcp 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+ .env
2
+ .git
3
+ .venv
4
+ **/__pycache__
5
+ .pytest_cache
6
+ .ruff_cache
@@ -0,0 +1,3 @@
1
+ # Datafordeler API key (IT-system in https://portal.datafordeler.dk)
2
+ DATAFORDELER_API_KEY=' '# Adressevælger token (KDS asks everyone to use this shared value until user accounts arrive)
3
+ ADRESSEVAELGER_TOKEN=adressevaelger123
@@ -0,0 +1,26 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ test:
13
+ runs-on: ubuntu-latest
14
+ strategy:
15
+ matrix:
16
+ python: ["3.11", "3.13"]
17
+ steps:
18
+ - uses: actions/checkout@v4
19
+ - uses: astral-sh/setup-uv@v6
20
+ with:
21
+ python-version: ${{ matrix.python }}
22
+ - run: uv sync --locked
23
+ - run: uv run ruff check
24
+ - run: uv run ruff format --check
25
+ - run: uv run pytest
26
+ - run: uv run bbr-mcp --self-test
@@ -0,0 +1,37 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ tags: ["v*"]
6
+
7
+ permissions:
8
+ contents: read
9
+
10
+ jobs:
11
+ build:
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+ - uses: astral-sh/setup-uv@v6
16
+ - run: uv sync --locked
17
+ - run: uv run pytest
18
+ - name: The tag matches the version in pyproject.toml
19
+ run: test "v$(uv version --short)" = "$GITHUB_REF_NAME"
20
+ - run: uv build
21
+ - uses: actions/upload-artifact@v4
22
+ with:
23
+ name: dist
24
+ path: dist/
25
+
26
+ publish:
27
+ needs: build
28
+ runs-on: ubuntu-latest
29
+ environment: pypi
30
+ permissions:
31
+ id-token: write
32
+ steps:
33
+ - uses: actions/download-artifact@v4
34
+ with:
35
+ name: dist
36
+ path: dist/
37
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,7 @@
1
+ .env
2
+ .venv/
3
+ __pycache__/
4
+ *.egg-info/
5
+ dist/
6
+ .pytest_cache/
7
+ .ruff_cache/
@@ -0,0 +1,9 @@
1
+ # Runs the server over stdio. Listing the tools needs no key; set DATAFORDELER_API_KEY for the BBR tools.
2
+ FROM python:3.13-slim
3
+ COPY --from=ghcr.io/astral-sh/uv:0.8.17 /uv /bin/uv
4
+ WORKDIR /app
5
+ COPY pyproject.toml uv.lock README.md LICENSE ./
6
+ COPY src ./src
7
+ RUN uv sync --locked --no-dev --no-editable && .venv/bin/bbr-mcp --self-test
8
+ USER nobody
9
+ ENTRYPOINT ["/app/.venv/bin/bbr-mcp"]
bbr_mcp-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 JulianUmbhau
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
bbr_mcp-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,134 @@
1
+ Metadata-Version: 2.5
2
+ Name: bbr-mcp
3
+ Version: 0.1.0
4
+ Summary: MCP server for Danish buildings (BBR) and addresses (DAR) from Datafordeler and Adressevælger
5
+ Project-URL: Repository, https://github.com/JulianUmbhau/bbr-mcp
6
+ License-Expression: MIT
7
+ License-File: LICENSE
8
+ Keywords: addresses,bbr,buildings,dar,datafordeler,denmark,mcp
9
+ Requires-Python: >=3.11
10
+ Requires-Dist: httpx>=0.28
11
+ Requires-Dist: mcp<3,>=2.3.0
12
+ Description-Content-Type: text/markdown
13
+
14
+ # bbr-mcp
15
+
16
+ An [MCP](https://modelcontextprotocol.io) server for Danish buildings and addresses. It lets a model:
17
+
18
+ - find an address from free text,
19
+ - look up the address's details and coordinates,
20
+ - read the BBR buildings and units registered there: use, year built, areas, materials, heating installation and
21
+ medium, housing type, rooms, and more. Code values come with their official Danish text.
22
+
23
+ It calls the official services live on each request:
24
+
25
+ | Data | Service | Credential |
26
+ |---|---|---|
27
+ | Addresses (DAR) | [Adressevælger](https://confluence.kds.dk/pages/viewpage.action?pageId=234782998), Klimadatastyrelsen's replacement for DAWA autocomplete | none |
28
+ | Buildings and units (BBR) | [Datafordeler GraphQL](https://confluence.kds.dk/display/DML/GraphQL), `BBR/v3` | `DATAFORDELER_API_KEY` |
29
+
30
+ It uses no DAWA (closed in 2026) and no legacy Datafordeler REST or username/password login (both end 15 January 2027).
31
+
32
+ ## Tools
33
+
34
+ | Tool | Input | Returns |
35
+ |---|---|---|
36
+ | `address_search` | `text`, `level` (`adresse` or `husnummer`), `limit` | DAR ids and labels of the matching addresses |
37
+ | `address_get` | `id` of a unit address or a husnummer | full address, postcode, municipality and road code, husnummer id, coordinates |
38
+ | `buildings` | one of `husnummer_id`, `address_id`, `building_id`, `jordstykke_id`; `limit` | BBR buildings (`byg0xx` fields) |
39
+ | `units` | one of `address_id`, `building_id`, `unit_id`; `limit` | BBR units (`enh0xx` fields) |
40
+ | `buildings_in_area` | an area (`bbox`, `polygon_wkt`, `center` + `radius_m`, or `around_address_id` + `radius_m`), `crs` (`25832` or `4326`); filters `uses`, `heating`, `heating_medium`; `include_not_existing`; `limit` | a summary of the buildings (by use, heating installation, heating medium, supplementary heat and year built, total areas) and a compact list |
41
+ | `buildings_for_addresses` | `addresses` (free text) or `husnummer_ids`, at most 200; `include_units` | each address's match (with `exact` and alternatives) and buildings, plus a summary over all of them |
42
+
43
+ Area and list notes:
44
+
45
+ - **Size limits.** An area may be up to 25 km² and up to 10,000 buildings. A radius may be up to 2.5 km.
46
+ - **Coordinates.** WGS84 longitude/latitude is converted to EPSG:25832 locally, because BBR's spatial filter takes
47
+ only its own coordinate system.
48
+ - **Filters.** BBR can filter on use and status itself. It has no heating filter, so `heating` and `heating_medium`
49
+ apply to the fetched buildings. A building whose heating is registered on its units (code 99) doesn't match them.
50
+ - **Address matching.** Free-text addresses go through Adressevælger, and `exact` says whether the match is the
51
+ same address written differently. Check non-exact matches before relying on them.
52
+
53
+ - Coded fields come as `{"code": "1", "text": "Fjernvarme/blokvarme"}`, and empty fields are left out.
54
+ - Coordinates are EPSG:25832 (ETRS89 / UTM 32N, metres).
55
+ - Every BBR query asks for the data as registered and valid now.
56
+ - `results` and `count` hold only buildings and units that stand now (status `6 Opført`). BBR keeps demolished buildings
57
+ (status `10 Historisk`), and also holds planned, under-construction and shelved ones. These are listed apart in
58
+ `not_existing`, each with a `state`. Objects registered by mistake (`11 Fejlregistreret`) are only counted.
59
+
60
+ ### Building states
61
+
62
+ BBR's own values are never changed. Every row keeps its `status` code and official text. `state` and the grouping
63
+ are this server's reading:
64
+
65
+ | Status | `state` | Basis |
66
+ |---|---|---|
67
+ | 6 Opført | in `results` | BBR [D0130 Logisk Intern Datamodel](https://teknik.bbr.dk/file/666026/d0130-logisk-intern-datamodel-bbr-1_8.docx), section 3.2 |
68
+ | 2 Projekteret | planned | D0130 |
69
+ | 3 Under opførsel | under construction | D0130 |
70
+ | 10 Historisk | demolished or otherwise ceased | D0130: "ved nedrivning af en bygning sættes status til historisk" |
71
+ | 14 Henlagt | shelved, never built | D0130 |
72
+ | 11 Fejlregistreret | only counted | D0130: registered by mistake |
73
+ | 9 Afsluttet | closed without being built | inferred: in a November 2026 sample, no status-9 building had a year built |
74
+ | 13 Delvis afsluttet | partly completed, may be partly in use | inferred: most have a year built and heating. D0130 does not list this status for buildings, but BBR uses it. |
75
+ | 12 Midlertidig afsluttet | status unclear | not defined in D0130, and mixed in the data |
76
+
77
+ ## Setup
78
+
79
+ 1. Create an IT-system with an API key in [Datafordeler Administration](https://portal.datafordeler.dk). A new key
80
+ takes about 15 minutes to become active.
81
+ 2. Install [uv](https://docs.astral.sh/uv/).
82
+ 3. Add the server to your MCP client, for example Claude Code:
83
+
84
+ ```sh
85
+ claude mcp add bbr -e DATAFORDELER_API_KEY=<key> -- uvx bbr-mcp
86
+ ```
87
+
88
+ Or in a JSON client config:
89
+
90
+ ```json
91
+ {
92
+ "mcpServers": {
93
+ "bbr": {
94
+ "command": "uvx",
95
+ "args": ["bbr-mcp"],
96
+ "env": { "DATAFORDELER_API_KEY": "<key>" }
97
+ }
98
+ }
99
+ }
100
+ ```
101
+
102
+ | Environment variable | |
103
+ |---|---|
104
+ | `DATAFORDELER_API_KEY` | required for the BBR tools |
105
+ | `ADRESSEVAELGER_TOKEN` | optional. Adressevælger has no user accounts yet and asks everyone to send `adressevaelger123`, the default. Set your own token once accounts arrive. |
106
+
107
+ `bbr-mcp --self-test` checks the installation offline: the tools are registered and the code lists translate.
108
+
109
+ ## Development
110
+
111
+ ```sh
112
+ uv sync
113
+ uv run ruff check
114
+ uv run ruff format --check
115
+ uv run pytest # offline, HTTP mocked
116
+ cp .example.env .env # then fill in DATAFORDELER_API_KEY
117
+ set -a; . ./.env; set +a; uv run pytest -m live
118
+ uv run scripts/update_codes.py # refresh src/bbr_mcp/codes.json from teknik.bbr.dk
119
+ ```
120
+
121
+ ## Data and licences
122
+
123
+ The code is MIT-licensed. The data keeps its own terms:
124
+
125
+ - **BBR:** Bygnings- og Boligregistret (BBR), [CC BY 4.0](https://datafordeler.dk/vejledning/brugervilkaar/bygnings-og-boligregistret-bbr/).
126
+ The code lists come from [teknik.bbr.dk/kodelister](https://teknik.bbr.dk/kodelister).
127
+ - **DAR:** Danmarks Adresseregister, Klimadatastyrelsen, [CC BY 4.0](https://datafordeler.dk/vejledning/brugervilkaar/danmarks-adresseregister-dar/).
128
+
129
+ Credit these sources when you share results. Every tool result carries a `source` line for this.
130
+
131
+ ## Related
132
+
133
+ [boligmcp](https://github.com/flyngaa/boligmcp) (MIT) is a much broader property-report MCP server over the same
134
+ services: ownership, valuation, sales, plans and more. This project covers only addresses, buildings and units.
@@ -0,0 +1,121 @@
1
+ # bbr-mcp
2
+
3
+ An [MCP](https://modelcontextprotocol.io) server for Danish buildings and addresses. It lets a model:
4
+
5
+ - find an address from free text,
6
+ - look up the address's details and coordinates,
7
+ - read the BBR buildings and units registered there: use, year built, areas, materials, heating installation and
8
+ medium, housing type, rooms, and more. Code values come with their official Danish text.
9
+
10
+ It calls the official services live on each request:
11
+
12
+ | Data | Service | Credential |
13
+ |---|---|---|
14
+ | Addresses (DAR) | [Adressevælger](https://confluence.kds.dk/pages/viewpage.action?pageId=234782998), Klimadatastyrelsen's replacement for DAWA autocomplete | none |
15
+ | Buildings and units (BBR) | [Datafordeler GraphQL](https://confluence.kds.dk/display/DML/GraphQL), `BBR/v3` | `DATAFORDELER_API_KEY` |
16
+
17
+ It uses no DAWA (closed in 2026) and no legacy Datafordeler REST or username/password login (both end 15 January 2027).
18
+
19
+ ## Tools
20
+
21
+ | Tool | Input | Returns |
22
+ |---|---|---|
23
+ | `address_search` | `text`, `level` (`adresse` or `husnummer`), `limit` | DAR ids and labels of the matching addresses |
24
+ | `address_get` | `id` of a unit address or a husnummer | full address, postcode, municipality and road code, husnummer id, coordinates |
25
+ | `buildings` | one of `husnummer_id`, `address_id`, `building_id`, `jordstykke_id`; `limit` | BBR buildings (`byg0xx` fields) |
26
+ | `units` | one of `address_id`, `building_id`, `unit_id`; `limit` | BBR units (`enh0xx` fields) |
27
+ | `buildings_in_area` | an area (`bbox`, `polygon_wkt`, `center` + `radius_m`, or `around_address_id` + `radius_m`), `crs` (`25832` or `4326`); filters `uses`, `heating`, `heating_medium`; `include_not_existing`; `limit` | a summary of the buildings (by use, heating installation, heating medium, supplementary heat and year built, total areas) and a compact list |
28
+ | `buildings_for_addresses` | `addresses` (free text) or `husnummer_ids`, at most 200; `include_units` | each address's match (with `exact` and alternatives) and buildings, plus a summary over all of them |
29
+
30
+ Area and list notes:
31
+
32
+ - **Size limits.** An area may be up to 25 km² and up to 10,000 buildings. A radius may be up to 2.5 km.
33
+ - **Coordinates.** WGS84 longitude/latitude is converted to EPSG:25832 locally, because BBR's spatial filter takes
34
+ only its own coordinate system.
35
+ - **Filters.** BBR can filter on use and status itself. It has no heating filter, so `heating` and `heating_medium`
36
+ apply to the fetched buildings. A building whose heating is registered on its units (code 99) doesn't match them.
37
+ - **Address matching.** Free-text addresses go through Adressevælger, and `exact` says whether the match is the
38
+ same address written differently. Check non-exact matches before relying on them.
39
+
40
+ - Coded fields come as `{"code": "1", "text": "Fjernvarme/blokvarme"}`, and empty fields are left out.
41
+ - Coordinates are EPSG:25832 (ETRS89 / UTM 32N, metres).
42
+ - Every BBR query asks for the data as registered and valid now.
43
+ - `results` and `count` hold only buildings and units that stand now (status `6 Opført`). BBR keeps demolished buildings
44
+ (status `10 Historisk`), and also holds planned, under-construction and shelved ones. These are listed apart in
45
+ `not_existing`, each with a `state`. Objects registered by mistake (`11 Fejlregistreret`) are only counted.
46
+
47
+ ### Building states
48
+
49
+ BBR's own values are never changed. Every row keeps its `status` code and official text. `state` and the grouping
50
+ are this server's reading:
51
+
52
+ | Status | `state` | Basis |
53
+ |---|---|---|
54
+ | 6 Opført | in `results` | BBR [D0130 Logisk Intern Datamodel](https://teknik.bbr.dk/file/666026/d0130-logisk-intern-datamodel-bbr-1_8.docx), section 3.2 |
55
+ | 2 Projekteret | planned | D0130 |
56
+ | 3 Under opførsel | under construction | D0130 |
57
+ | 10 Historisk | demolished or otherwise ceased | D0130: "ved nedrivning af en bygning sættes status til historisk" |
58
+ | 14 Henlagt | shelved, never built | D0130 |
59
+ | 11 Fejlregistreret | only counted | D0130: registered by mistake |
60
+ | 9 Afsluttet | closed without being built | inferred: in a November 2026 sample, no status-9 building had a year built |
61
+ | 13 Delvis afsluttet | partly completed, may be partly in use | inferred: most have a year built and heating. D0130 does not list this status for buildings, but BBR uses it. |
62
+ | 12 Midlertidig afsluttet | status unclear | not defined in D0130, and mixed in the data |
63
+
64
+ ## Setup
65
+
66
+ 1. Create an IT-system with an API key in [Datafordeler Administration](https://portal.datafordeler.dk). A new key
67
+ takes about 15 minutes to become active.
68
+ 2. Install [uv](https://docs.astral.sh/uv/).
69
+ 3. Add the server to your MCP client, for example Claude Code:
70
+
71
+ ```sh
72
+ claude mcp add bbr -e DATAFORDELER_API_KEY=<key> -- uvx bbr-mcp
73
+ ```
74
+
75
+ Or in a JSON client config:
76
+
77
+ ```json
78
+ {
79
+ "mcpServers": {
80
+ "bbr": {
81
+ "command": "uvx",
82
+ "args": ["bbr-mcp"],
83
+ "env": { "DATAFORDELER_API_KEY": "<key>" }
84
+ }
85
+ }
86
+ }
87
+ ```
88
+
89
+ | Environment variable | |
90
+ |---|---|
91
+ | `DATAFORDELER_API_KEY` | required for the BBR tools |
92
+ | `ADRESSEVAELGER_TOKEN` | optional. Adressevælger has no user accounts yet and asks everyone to send `adressevaelger123`, the default. Set your own token once accounts arrive. |
93
+
94
+ `bbr-mcp --self-test` checks the installation offline: the tools are registered and the code lists translate.
95
+
96
+ ## Development
97
+
98
+ ```sh
99
+ uv sync
100
+ uv run ruff check
101
+ uv run ruff format --check
102
+ uv run pytest # offline, HTTP mocked
103
+ cp .example.env .env # then fill in DATAFORDELER_API_KEY
104
+ set -a; . ./.env; set +a; uv run pytest -m live
105
+ uv run scripts/update_codes.py # refresh src/bbr_mcp/codes.json from teknik.bbr.dk
106
+ ```
107
+
108
+ ## Data and licences
109
+
110
+ The code is MIT-licensed. The data keeps its own terms:
111
+
112
+ - **BBR:** Bygnings- og Boligregistret (BBR), [CC BY 4.0](https://datafordeler.dk/vejledning/brugervilkaar/bygnings-og-boligregistret-bbr/).
113
+ The code lists come from [teknik.bbr.dk/kodelister](https://teknik.bbr.dk/kodelister).
114
+ - **DAR:** Danmarks Adresseregister, Klimadatastyrelsen, [CC BY 4.0](https://datafordeler.dk/vejledning/brugervilkaar/danmarks-adresseregister-dar/).
115
+
116
+ Credit these sources when you share results. Every tool result carries a `source` line for this.
117
+
118
+ ## Related
119
+
120
+ [boligmcp](https://github.com/flyngaa/boligmcp) (MIT) is a much broader property-report MCP server over the same
121
+ services: ownership, valuation, sales, plans and more. This project covers only addresses, buildings and units.
@@ -0,0 +1,4 @@
1
+ {
2
+ "$schema": "https://glama.ai/mcp/schemas/server.json",
3
+ "maintainers": ["JulianUmbhau"]
4
+ }
@@ -0,0 +1,42 @@
1
+ [project]
2
+ name = "bbr-mcp"
3
+ version = "0.1.0"
4
+ description = "MCP server for Danish buildings (BBR) and addresses (DAR) from Datafordeler and Adressevælger"
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ license-files = ["LICENSE"]
8
+ requires-python = ">=3.11"
9
+ dependencies = [
10
+ "httpx>=0.28",
11
+ "mcp>=2.3.0,<3",
12
+ ]
13
+ keywords = ["mcp", "bbr", "dar", "datafordeler", "denmark", "addresses", "buildings"]
14
+
15
+ [project.scripts]
16
+ bbr-mcp = "bbr_mcp.server:main"
17
+
18
+ [project.urls]
19
+ Repository = "https://github.com/JulianUmbhau/bbr-mcp"
20
+
21
+ [dependency-groups]
22
+ dev = [
23
+ "pyproj>=3.6",
24
+ "pytest>=8",
25
+ "respx>=0.22",
26
+ "ruff>=0.8",
27
+ ]
28
+
29
+ [build-system]
30
+ requires = ["hatchling"]
31
+ build-backend = "hatchling.build"
32
+
33
+ [tool.ruff]
34
+ line-length = 120
35
+ target-version = "py311"
36
+
37
+ [tool.ruff.lint]
38
+ select = ["E", "F", "I", "B", "UP"]
39
+
40
+ [tool.pytest.ini_options]
41
+ addopts = "-m 'not live'"
42
+ markers = ["live: calls the real Datafordeler and Adressevælger services (needs DATAFORDELER_API_KEY)"]
@@ -0,0 +1,54 @@
1
+ """Regenerate src/bbr_mcp/codes.json from the official BBR code lists at teknik.bbr.dk.
2
+
3
+ uv run scripts/update_codes.py
4
+
5
+ Each list is an HTML page with one <li>CODE - Text</li> per code inside a `kodeliste-list` block. The script fails if
6
+ a page has no such block or no codes, so a change on the site shows up here, not as missing texts at run time.
7
+ """
8
+
9
+ import html
10
+ import json
11
+ import re
12
+ import sys
13
+ from datetime import date
14
+
15
+ import httpx
16
+
17
+ from bbr_mcp.codes import CODES_FILE, FIELD_LISTS
18
+
19
+ SOURCE = "https://teknik.bbr.dk/kodelister"
20
+ ITEM = re.compile(r"<li[^>]*>(.*?)</li>", re.S)
21
+ CODE = re.compile(r"^([0-9A-Za-z]{1,6})\s+-\s+(.+)$", re.S)
22
+
23
+
24
+ def fetch_list(client: httpx.Client, name: str) -> dict[str, str]:
25
+ response = client.get(f"{SOURCE}/0/1/0/{name}")
26
+ response.raise_for_status()
27
+ start = response.text.find("kodeliste-list")
28
+ if start < 0:
29
+ sys.exit(f"{name}: no kodeliste-list block on the page")
30
+ end = response.text.find("</ul>", start)
31
+ codes = {}
32
+ for item in ITEM.findall(response.text[start:end]):
33
+ text = " ".join(html.unescape(re.sub(r"<[^>]+>", "", item)).split())
34
+ match = CODE.match(text)
35
+ if match:
36
+ codes[match.group(1)] = match.group(2)
37
+ if not codes:
38
+ sys.exit(f"{name}: no codes found")
39
+ return codes
40
+
41
+
42
+ def main() -> None:
43
+ lists = {}
44
+ with httpx.Client(timeout=30, follow_redirects=True) as client:
45
+ for name in sorted(set(FIELD_LISTS.values())):
46
+ lists[name] = fetch_list(client, name)
47
+ print(f"{name}: {len(lists[name])} codes")
48
+ data = {"_source": SOURCE, "_fetched": date.today().isoformat(), **lists}
49
+ CODES_FILE.write_text(json.dumps(data, ensure_ascii=False, indent=1, sort_keys=False) + "\n", encoding="utf-8")
50
+ print(f"wrote {CODES_FILE}")
51
+
52
+
53
+ if __name__ == "__main__":
54
+ main()
@@ -0,0 +1 @@
1
+ """MCP server for Danish buildings (BBR) and addresses (DAR)."""
@@ -0,0 +1,48 @@
1
+ """Client for Adressevælger (https://adressevaelger.dk), Klimadatastyrelsen's replacement for DAWA autocomplete."""
2
+
3
+ import os
4
+ from typing import Any
5
+
6
+ import httpx
7
+
8
+ BASE_URL = os.environ.get("ADRESSEVAELGER_URL", "https://adressevaelger.dk")
9
+ # Adressevælger has no user accounts yet; Klimadatastyrelsen asks everyone to send this shared token.
10
+ DEFAULT_TOKEN = "adressevaelger123"
11
+ TIMEOUT = 20.0
12
+
13
+ LEVELS = {"adresse": "adresser", "husnummer": "husnumre"}
14
+
15
+
16
+ class AdressevaelgerError(Exception):
17
+ pass
18
+
19
+
20
+ def _token() -> str:
21
+ return os.environ.get("ADRESSEVAELGER_TOKEN", "").strip() or DEFAULT_TOKEN
22
+
23
+
24
+ async def _get(client: httpx.AsyncClient, path: str, params: dict[str, Any] | None = None) -> dict[str, Any] | None:
25
+ try:
26
+ response = await client.get(f"{BASE_URL}/{path}", params={**(params or {}), "token": _token()}, timeout=TIMEOUT)
27
+ except httpx.TransportError as e:
28
+ raise AdressevaelgerError(f"Adressevælger unreachable: {e!r}") from None
29
+ if response.status_code == 404:
30
+ return None
31
+ try:
32
+ payload = response.json()
33
+ except ValueError:
34
+ raise AdressevaelgerError(f"Adressevælger answered {response.status_code} with no JSON") from None
35
+ if response.status_code != 200 or payload.get("status") != "ok":
36
+ detail = payload.get("beskrivelse") or payload.get("status") or response.status_code
37
+ raise AdressevaelgerError(f"Adressevælger: {detail}")
38
+ return payload
39
+
40
+
41
+ async def search(client: httpx.AsyncClient, text: str, level: str, limit: int) -> list[dict[str, Any]]:
42
+ payload = await _get(client, f"{LEVELS[level]}/soeg", {"tekst": text, "maksimum": limit})
43
+ return (payload or {}).get("fund") or []
44
+
45
+
46
+ async def get(client: httpx.AsyncClient, level: str, id: str) -> dict[str, Any] | None:
47
+ payload = await _get(client, f"{LEVELS[level]}/{id}")
48
+ return None if payload is None else payload.get(level)