eolas-data 1.9.0__tar.gz → 1.10.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.
- {eolas_data-1.9.0 → eolas_data-1.10.0}/.github/workflows/publish.yml +7 -1
- {eolas_data-1.9.0 → eolas_data-1.10.0}/.github/workflows/smoke.yml +3 -3
- {eolas_data-1.9.0 → eolas_data-1.10.0}/.github/workflows/test.yml +4 -4
- {eolas_data-1.9.0 → eolas_data-1.10.0}/CHANGELOG.md +47 -0
- {eolas_data-1.9.0 → eolas_data-1.10.0}/PKG-INFO +1 -1
- {eolas_data-1.9.0 → eolas_data-1.10.0}/eolas_data/__init__.py +1 -1
- {eolas_data-1.9.0 → eolas_data-1.10.0}/eolas_data/client.py +56 -12
- eolas_data-1.10.0/eolas_data/mcp_server.py +283 -0
- {eolas_data-1.9.0 → eolas_data-1.10.0}/pyproject.toml +1 -1
- {eolas_data-1.9.0 → eolas_data-1.10.0}/scripts/check_client_contract.py +12 -0
- {eolas_data-1.9.0 → eolas_data-1.10.0}/tests/test_geometry_param.py +176 -24
- eolas_data-1.10.0/tests/test_mcp_integration.py +68 -0
- eolas_data-1.10.0/tests/test_mcp_protocol.py +89 -0
- eolas_data-1.10.0/tests/test_mcp_server.py +267 -0
- {eolas_data-1.9.0 → eolas_data-1.10.0}/.github/workflows/catalog-drift.yml +0 -0
- {eolas_data-1.9.0 → eolas_data-1.10.0}/.github/workflows/pre-release.yml +0 -0
- {eolas_data-1.9.0 → eolas_data-1.10.0}/.gitignore +0 -0
- {eolas_data-1.9.0 → eolas_data-1.10.0}/LICENSE +0 -0
- {eolas_data-1.9.0 → eolas_data-1.10.0}/README.md +0 -0
- {eolas_data-1.9.0 → eolas_data-1.10.0}/eolas_data/_dataset_names.py +0 -0
- {eolas_data-1.9.0 → eolas_data-1.10.0}/eolas_data/_regen_names.py +0 -0
- {eolas_data-1.9.0 → eolas_data-1.10.0}/eolas_data/cdc.py +0 -0
- {eolas_data-1.9.0 → eolas_data-1.10.0}/eolas_data/cli.py +0 -0
- {eolas_data-1.9.0 → eolas_data-1.10.0}/eolas_data/console.py +0 -0
- {eolas_data-1.9.0 → eolas_data-1.10.0}/eolas_data/dataset.py +0 -0
- {eolas_data-1.9.0 → eolas_data-1.10.0}/eolas_data/exceptions.py +0 -0
- {eolas_data-1.9.0 → eolas_data-1.10.0}/eolas_data/library.py +0 -0
- {eolas_data-1.9.0 → eolas_data-1.10.0}/eolas_data/meta.py +0 -0
- {eolas_data-1.9.0 → eolas_data-1.10.0}/eolas_data/rows.py +0 -0
- {eolas_data-1.9.0 → eolas_data-1.10.0}/eolas_data/schedule.py +0 -0
- {eolas_data-1.9.0 → eolas_data-1.10.0}/eolas_data/search.py +0 -0
- {eolas_data-1.9.0 → eolas_data-1.10.0}/scripts/preflight.sh +0 -0
- {eolas_data-1.9.0 → eolas_data-1.10.0}/tests/fixtures/source_helpers.json +0 -0
- {eolas_data-1.9.0 → eolas_data-1.10.0}/tests/test_as_arrow.py +0 -0
- {eolas_data-1.9.0 → eolas_data-1.10.0}/tests/test_cdc_roundtrip.py +0 -0
- {eolas_data-1.9.0 → eolas_data-1.10.0}/tests/test_changes_http.py +0 -0
- {eolas_data-1.9.0 → eolas_data-1.10.0}/tests/test_cli.py +0 -0
- {eolas_data-1.9.0 → eolas_data-1.10.0}/tests/test_client.py +0 -0
- {eolas_data-1.9.0 → eolas_data-1.10.0}/tests/test_date_filter.py +0 -0
- {eolas_data-1.9.0 → eolas_data-1.10.0}/tests/test_get_local.py +0 -0
- {eolas_data-1.9.0 → eolas_data-1.10.0}/tests/test_keyring.py +0 -0
- {eolas_data-1.9.0 → eolas_data-1.10.0}/tests/test_library.py +0 -0
- {eolas_data-1.9.0 → eolas_data-1.10.0}/tests/test_meta.py +0 -0
- {eolas_data-1.9.0 → eolas_data-1.10.0}/tests/test_preview_dimensions.py +0 -0
- {eolas_data-1.9.0 → eolas_data-1.10.0}/tests/test_progress.py +0 -0
- {eolas_data-1.9.0 → eolas_data-1.10.0}/tests/test_resilience.py +0 -0
- {eolas_data-1.9.0 → eolas_data-1.10.0}/tests/test_rows.py +0 -0
- {eolas_data-1.9.0 → eolas_data-1.10.0}/tests/test_schedule.py +0 -0
- {eolas_data-1.9.0 → eolas_data-1.10.0}/tests/test_search.py +0 -0
- {eolas_data-1.9.0 → eolas_data-1.10.0}/tests/test_smoke_live.py +0 -0
- {eolas_data-1.9.0 → eolas_data-1.10.0}/tests/test_source_helpers.py +0 -0
- {eolas_data-1.9.0 → eolas_data-1.10.0}/tests/test_sync_bulk.py +0 -0
- {eolas_data-1.9.0 → eolas_data-1.10.0}/tests/test_sync_changes.py +0 -0
|
@@ -69,7 +69,13 @@ jobs:
|
|
|
69
69
|
- name: Install wheel + test deps
|
|
70
70
|
run: |
|
|
71
71
|
WHL=$(ls -1 dist/*.whl | head -1)
|
|
72
|
-
|
|
72
|
+
# Install the wheel WITH its [mcp] extra, so this gate actually
|
|
73
|
+
# resolves and imports the optional surface it ships. Installing the
|
|
74
|
+
# bare wheel let the mcp test files fail to collect (No module named
|
|
75
|
+
# 'mcp') on the 1.10.0 tag — and, more importantly, would have let the
|
|
76
|
+
# [mcp] extra ship broken (declared entry point, missing module) on
|
|
77
|
+
# every release from 1.3.22 to 1.9.1 without this gate noticing.
|
|
78
|
+
pip install "$WHL[mcp]"
|
|
73
79
|
pip install pytest responses geopandas shapely pandas pyarrow typer rich keyring
|
|
74
80
|
|
|
75
81
|
- name: Version self-report parity (REL-1)
|
|
@@ -25,8 +25,8 @@ jobs:
|
|
|
25
25
|
exit 1
|
|
26
26
|
fi
|
|
27
27
|
|
|
28
|
-
- name: Install package + dev/geo deps (as users would)
|
|
29
|
-
run: pip install ".[dev,geo]"
|
|
28
|
+
- name: Install package + dev/geo/mcp deps (as users would)
|
|
29
|
+
run: pip install ".[dev,geo,mcp]"
|
|
30
30
|
|
|
31
31
|
- name: Live smoke tests
|
|
32
32
|
env:
|
|
@@ -36,4 +36,4 @@ jobs:
|
|
|
36
36
|
echo "EOLAS_API_KEY secret not configured — skipping scheduled smoke tests."
|
|
37
37
|
exit 0
|
|
38
38
|
fi
|
|
39
|
-
pytest -q -m integration tests/test_smoke_live.py
|
|
39
|
+
pytest -q -m integration tests/test_smoke_live.py tests/test_mcp_integration.py
|
|
@@ -32,8 +32,8 @@ jobs:
|
|
|
32
32
|
with:
|
|
33
33
|
python-version: ${{ matrix.python-version }}
|
|
34
34
|
|
|
35
|
-
- name: Install package + dev + geo + secure (editable)
|
|
36
|
-
run: pip install -e ".[dev,geo,secure]"
|
|
35
|
+
- name: Install package + dev + geo + secure + mcp (editable)
|
|
36
|
+
run: pip install -e ".[dev,geo,secure,mcp]"
|
|
37
37
|
|
|
38
38
|
- name: pytest (unit suite)
|
|
39
39
|
run: pytest -q -m "not integration"
|
|
@@ -57,7 +57,7 @@ jobs:
|
|
|
57
57
|
run: |
|
|
58
58
|
WHL=$(ls -1 dist/*.whl | head -1)
|
|
59
59
|
pip install "$WHL"
|
|
60
|
-
pip install pytest responses geopandas shapely pandas pyarrow typer rich keyring
|
|
60
|
+
pip install pytest responses geopandas shapely pandas pyarrow typer rich keyring "mcp>=1.0"
|
|
61
61
|
|
|
62
62
|
- name: pytest on installed package
|
|
63
63
|
run: pytest -q -m "not integration"
|
|
@@ -74,7 +74,7 @@ jobs:
|
|
|
74
74
|
- uses: actions/setup-python@v5
|
|
75
75
|
with:
|
|
76
76
|
python-version: "3.12"
|
|
77
|
-
- run: pip install -e ".[dev,geo,secure]" pytest-cov
|
|
77
|
+
- run: pip install -e ".[dev,geo,secure,mcp]" pytest-cov
|
|
78
78
|
- run: pytest -q -m "not integration" --cov=eolas_data --cov-report=xml
|
|
79
79
|
- name: Upload coverage
|
|
80
80
|
uses: codecov/codecov-action@v5
|
|
@@ -3,6 +3,53 @@
|
|
|
3
3
|
All notable changes to `eolas-data` are recorded here. This project follows
|
|
4
4
|
[Semantic Versioning](https://semver.org/).
|
|
5
5
|
|
|
6
|
+
## 1.10.0
|
|
7
|
+
|
|
8
|
+
### Added
|
|
9
|
+
|
|
10
|
+
- **MCP server (`eolas-mcp`) — now actually present.** `eolas_data/mcp_server.py`
|
|
11
|
+
exposes the client as Model Context Protocol tools over stdio for agent hosts
|
|
12
|
+
(Claude Desktop, Cursor, Grok): `eolas_health`, `eolas_search`, `eolas_info`,
|
|
13
|
+
`eolas_get`, `eolas_download`, `eolas_sync`. A thin wrapper — all HTTP, auth,
|
|
14
|
+
CDC routing and error mapping stay in `Client`. Agent-safe caps: `eolas_get`
|
|
15
|
+
is hard-limited to 500 rows and `eolas_search` to 50, so nothing streams a
|
|
16
|
+
multi-million-row table into a model's context. Install with
|
|
17
|
+
`pip install eolas-data[mcp]`; run `eolas-mcp` or `python -m eolas_data.mcp_server`.
|
|
18
|
+
|
|
19
|
+
### Fixed
|
|
20
|
+
|
|
21
|
+
- **The `[mcp]` extra and `eolas-mcp` entry point have been broken since 1.3.22.**
|
|
22
|
+
`pyproject.toml` declared both, but the `eolas_data.mcp_server` module was never
|
|
23
|
+
committed — so `pip install eolas-data[mcp]` created an `eolas-mcp` command that
|
|
24
|
+
failed with `ModuleNotFoundError` on every release from 1.3.22 to 1.9.1.
|
|
25
|
+
Verified against a clean install of the published 1.9.1 wheel. This release
|
|
26
|
+
ships the module the packaging has been promising.
|
|
27
|
+
|
|
28
|
+
## 1.9.1
|
|
29
|
+
|
|
30
|
+
### Changed
|
|
31
|
+
|
|
32
|
+
- **`geometry=False` now skips the column at READ time, not after.** 1.9.0 read
|
|
33
|
+
the whole Parquet — WKT included — and dropped the column afterwards, paying
|
|
34
|
+
the full parse and peak memory for data discarded a line later. `get_local()`
|
|
35
|
+
now passes `columns=` to `pd.read_parquet()`, so those column chunks are never
|
|
36
|
+
decoded, and it deliberately avoids `gpd.read_parquet()` (which would
|
|
37
|
+
materialise shapely geometry we are about to throw away). `get()` passes the
|
|
38
|
+
flag down rather than applying it to the result.
|
|
39
|
+
|
|
40
|
+
Geometry is typically ~95% of a spatial layer's bytes: `geometry_wkt` is 262 of
|
|
41
|
+
275 MB in `linz.nz_building_outlines`.
|
|
42
|
+
|
|
43
|
+
- `get_local()` gains a `geometry` argument, mirroring `get()`.
|
|
44
|
+
|
|
45
|
+
### Unchanged (deliberately)
|
|
46
|
+
|
|
47
|
+
- What gets downloaded. One cached artifact still serves both variants, so
|
|
48
|
+
upgrading a non-spatial read back to spatial re-reads the same local file with
|
|
49
|
+
no re-download. A test asserts the cache file is byte-identical after a
|
|
50
|
+
`geometry=False` read. Reducing the *download* is a separate design question —
|
|
51
|
+
see `docs/geometry-fetch-design-2026-07-22.md` in the eolas repo.
|
|
52
|
+
|
|
6
53
|
## 1.9.0
|
|
7
54
|
|
|
8
55
|
> Version jumps 1.4.0 -> 1.9.0. PyPI versions 1.5.0-1.8.0 were uploaded in May
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: eolas-data
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.10.0
|
|
4
4
|
Summary: Python client for the eolas.fyi statistical data API (NZ + OECD; Australia on roadmap)
|
|
5
5
|
Project-URL: Homepage, https://eolas.fyi
|
|
6
6
|
Project-URL: Documentation, https://docs.eolas.fyi/
|
|
@@ -75,6 +75,11 @@ class _TimeoutSession(requests.Session):
|
|
|
75
75
|
raise EolasError(f"Network error talking to api.eolas.fyi: {exc}") from exc
|
|
76
76
|
|
|
77
77
|
|
|
78
|
+
# Geometry columns excluded when a caller passes geometry=False. `geometry_wkt`
|
|
79
|
+
# is the eolas convention (data-conventions.md §3, always that name); `geometry`
|
|
80
|
+
# is what GeoParquet bulk artifacts carry as their WKB column.
|
|
81
|
+
_GEOMETRY_COLUMNS = frozenset({"geometry_wkt", "geometry"})
|
|
82
|
+
|
|
78
83
|
_SIDECAR_SCHEMA_VERSION = 1
|
|
79
84
|
_SIDECAR_SCHEMA_VERSION_CDC = 2
|
|
80
85
|
|
|
@@ -2112,6 +2117,7 @@ class Client:
|
|
|
2112
2117
|
meta: bool = True,
|
|
2113
2118
|
progress: ProgressControl = None,
|
|
2114
2119
|
force: bool = False,
|
|
2120
|
+
geometry: bool = True,
|
|
2115
2121
|
) -> "pd.DataFrame":
|
|
2116
2122
|
"""Download (or serve from cache) a whole dataset as a local DataFrame.
|
|
2117
2123
|
|
|
@@ -2179,7 +2185,13 @@ class Client:
|
|
|
2179
2185
|
"Choose one."
|
|
2180
2186
|
)
|
|
2181
2187
|
# Resolve as_geo: None → True (auto) unless as_arrow overrides.
|
|
2182
|
-
|
|
2188
|
+
# geometry=False forces it off — there will be no geometry column to
|
|
2189
|
+
# convert, and auto-converting would be the opposite of what was asked.
|
|
2190
|
+
resolved_as_geo = (
|
|
2191
|
+
False
|
|
2192
|
+
if not geometry
|
|
2193
|
+
else (as_geo if as_geo is not None else (not as_arrow))
|
|
2194
|
+
)
|
|
2183
2195
|
self._apply_force(name, force)
|
|
2184
2196
|
|
|
2185
2197
|
# ---- resolve cache_dir -----------------------------------------------
|
|
@@ -2250,13 +2262,46 @@ class Client:
|
|
|
2250
2262
|
import pyarrow as _pa
|
|
2251
2263
|
|
|
2252
2264
|
return _pa.Table.from_pandas(
|
|
2253
|
-
pd.read_csv(
|
|
2265
|
+
pd.read_csv(
|
|
2266
|
+
file_path,
|
|
2267
|
+
usecols=(
|
|
2268
|
+
(lambda c: c not in _GEOMETRY_COLUMNS)
|
|
2269
|
+
if not geometry
|
|
2270
|
+
else None
|
|
2271
|
+
),
|
|
2272
|
+
),
|
|
2254
2273
|
preserve_index=False,
|
|
2255
2274
|
)
|
|
2275
|
+
if not geometry:
|
|
2276
|
+
names = _pq.ParquetFile(file_path).schema_arrow.names
|
|
2277
|
+
return _pq.read_table(
|
|
2278
|
+
file_path,
|
|
2279
|
+
columns=[c for c in names if c not in _GEOMETRY_COLUMNS],
|
|
2280
|
+
)
|
|
2256
2281
|
return _pq.read_table(file_path)
|
|
2257
2282
|
|
|
2258
2283
|
def _read_bulk_file(path: pathlib.Path, bulk_fmt: str):
|
|
2259
2284
|
with self._with_read_progress(read_label, show_read):
|
|
2285
|
+
# geometry=False: project the geometry column away AT READ TIME.
|
|
2286
|
+
# The cached artifact is unchanged (one file serves both variants
|
|
2287
|
+
# — no cache duplication), but Parquet is columnar, so an
|
|
2288
|
+
# unselected column is never decoded and its pages are never even
|
|
2289
|
+
# read off disk. Dropping the column after a full read would pay
|
|
2290
|
+
# the whole WKB/WKT parse and peak memory for data we discard,
|
|
2291
|
+
# which on a large boundary layer is most of the cost.
|
|
2292
|
+
if not geometry:
|
|
2293
|
+
if bulk_fmt == "csv_gz":
|
|
2294
|
+
return pd.read_csv(
|
|
2295
|
+
path, usecols=lambda c: c not in _GEOMETRY_COLUMNS
|
|
2296
|
+
)
|
|
2297
|
+
import pyarrow.parquet as _pq
|
|
2298
|
+
|
|
2299
|
+
names = _pq.ParquetFile(path).schema_arrow.names
|
|
2300
|
+
keep = [c for c in names if c not in _GEOMETRY_COLUMNS]
|
|
2301
|
+
# Deliberately pandas, not geopandas, even for geoparquet:
|
|
2302
|
+
# gpd.read_parquet would materialise shapely geometry we are
|
|
2303
|
+
# about to discard.
|
|
2304
|
+
return pd.read_parquet(path, columns=keep)
|
|
2260
2305
|
if bulk_fmt == "csv_gz":
|
|
2261
2306
|
return pd.read_csv(path)
|
|
2262
2307
|
if bulk_fmt == "geoparquet" and resolved_as_geo:
|
|
@@ -2486,23 +2531,22 @@ class Client:
|
|
|
2486
2531
|
except Exception:
|
|
2487
2532
|
should_route = False # metadata/routing failed → live path
|
|
2488
2533
|
if should_route:
|
|
2489
|
-
# The bulk artifact always carries
|
|
2490
|
-
# server-side projection on
|
|
2491
|
-
#
|
|
2492
|
-
#
|
|
2493
|
-
#
|
|
2494
|
-
#
|
|
2495
|
-
#
|
|
2534
|
+
# The bulk artifact always carries geometry — there is no
|
|
2535
|
+
# server-side projection on this path — so geometry=False must be
|
|
2536
|
+
# honoured locally. It is passed DOWN to get_local() rather than
|
|
2537
|
+
# applied after: get_local projects the column away at read time,
|
|
2538
|
+
# so the WKB/WKT is never decoded (see _read_bulk_file). The
|
|
2539
|
+
# cached file itself is untouched, so one artifact still serves
|
|
2540
|
+
# both variants.
|
|
2496
2541
|
result = self.get_local(
|
|
2497
2542
|
name,
|
|
2498
|
-
as_geo=
|
|
2543
|
+
as_geo=as_geo,
|
|
2499
2544
|
as_arrow=False,
|
|
2500
2545
|
meta=meta,
|
|
2501
2546
|
force=force,
|
|
2502
2547
|
progress=progress,
|
|
2548
|
+
geometry=geometry,
|
|
2503
2549
|
)
|
|
2504
|
-
if not geometry:
|
|
2505
|
-
result = self._drop_geometry_column(result)
|
|
2506
2550
|
if engine == "polars":
|
|
2507
2551
|
try:
|
|
2508
2552
|
import polars as pl
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
"""eolas MCP server — stdio transport for Claude Desktop, Cursor, Grok, etc.
|
|
2
|
+
|
|
3
|
+
Thin wrapper over :class:`eolas_data.Client`. All HTTP, auth, CDC routing, and
|
|
4
|
+
error mapping stay in the Python client; this module only exposes typed tools
|
|
5
|
+
for agent hosts.
|
|
6
|
+
|
|
7
|
+
Run::
|
|
8
|
+
|
|
9
|
+
eolas-mcp # after pip install eolas-data[mcp]
|
|
10
|
+
python -m eolas_data.mcp_server
|
|
11
|
+
|
|
12
|
+
Auth resolves the same way as the CLI: ``EOLAS_API_KEY`` env var, OS keyring
|
|
13
|
+
(``pip install eolas-data[secure]``), or ``~/.eolas/config.json``.
|
|
14
|
+
"""
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import json
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
from typing import Any, Optional
|
|
20
|
+
|
|
21
|
+
from mcp.server.fastmcp import FastMCP
|
|
22
|
+
|
|
23
|
+
from .client import Client, SyncResult
|
|
24
|
+
from .exceptions import EolasError
|
|
25
|
+
from .meta import _TABLE_META_KEYS
|
|
26
|
+
|
|
27
|
+
# Hard caps — never stream multi-million-row tables into model context.
|
|
28
|
+
_MCP_GET_ROW_CAP = 500
|
|
29
|
+
_MCP_SEARCH_CAP = 50
|
|
30
|
+
|
|
31
|
+
mcp = FastMCP(
|
|
32
|
+
"eolas",
|
|
33
|
+
instructions=(
|
|
34
|
+
"Tools for the eolas.fyi statistical & geospatial data API (NZ + OECD). "
|
|
35
|
+
"Use eolas_search then eolas_info before fetching unknown dataset names. "
|
|
36
|
+
"For whole datasets prefer eolas_sync (keeps a local file current) or "
|
|
37
|
+
"eolas_download (one-shot bulk file). Use eolas_get only for small slices."
|
|
38
|
+
),
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
_client: Optional[Client] = None
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _get_client() -> Client:
|
|
45
|
+
global _client
|
|
46
|
+
if _client is None:
|
|
47
|
+
_client = Client()
|
|
48
|
+
return _client
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _set_client(client: Optional[Client]) -> None:
|
|
52
|
+
"""Test hook — inject a mock client."""
|
|
53
|
+
global _client
|
|
54
|
+
_client = client
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _json_safe(value: Any) -> Any:
|
|
58
|
+
if value is None or isinstance(value, (bool, int, float, str)):
|
|
59
|
+
return value
|
|
60
|
+
if isinstance(value, Path):
|
|
61
|
+
return str(value)
|
|
62
|
+
if isinstance(value, dict):
|
|
63
|
+
return {str(k): _json_safe(v) for k, v in value.items()}
|
|
64
|
+
if isinstance(value, (list, tuple)):
|
|
65
|
+
return [_json_safe(v) for v in value]
|
|
66
|
+
return str(value)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def _df_records(df, *, max_rows: int) -> list[dict]:
|
|
70
|
+
import pandas as pd
|
|
71
|
+
|
|
72
|
+
if df is None or (hasattr(df, "empty") and df.empty):
|
|
73
|
+
return []
|
|
74
|
+
subset = df.head(max_rows)
|
|
75
|
+
records = json.loads(
|
|
76
|
+
subset.to_json(orient="records", date_format="iso", default_handler=str)
|
|
77
|
+
)
|
|
78
|
+
return records
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _compact_info(meta: dict) -> dict:
|
|
82
|
+
out = {k: meta[k] for k in _TABLE_META_KEYS if k in meta}
|
|
83
|
+
for extra in ("table", "replication_mode", "cdc_serving_tier", "pk_columns"):
|
|
84
|
+
if extra in meta and extra not in out:
|
|
85
|
+
out[extra] = meta[extra]
|
|
86
|
+
return _json_safe(out)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _sync_payload(result: SyncResult, *, freshness: str, fmt: str) -> dict:
|
|
90
|
+
payload: dict[str, Any] = {
|
|
91
|
+
"status": result.status,
|
|
92
|
+
"path": str(result.path),
|
|
93
|
+
"bytes_downloaded": result.bytes_downloaded,
|
|
94
|
+
"sync_mode": result.sync_mode or "snapshot",
|
|
95
|
+
"format": fmt,
|
|
96
|
+
"freshness": freshness,
|
|
97
|
+
"previous_snapshot_id": result.previous_snapshot_id,
|
|
98
|
+
"current_snapshot_id": result.current_snapshot_id,
|
|
99
|
+
}
|
|
100
|
+
if result.sync_mode == "changelog":
|
|
101
|
+
payload["previous_seq"] = result.previous_seq
|
|
102
|
+
payload["current_seq"] = result.current_seq
|
|
103
|
+
payload["ops_applied"] = result.ops_applied
|
|
104
|
+
return _json_safe(payload)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def _map_error(exc: Exception) -> str:
|
|
108
|
+
if isinstance(exc, EolasError):
|
|
109
|
+
return str(exc)
|
|
110
|
+
return f"{type(exc).__name__}: {exc}"
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
@mcp.tool()
|
|
114
|
+
def eolas_health() -> dict:
|
|
115
|
+
"""Check api.eolas.fyi reachability (no API key required)."""
|
|
116
|
+
import requests
|
|
117
|
+
|
|
118
|
+
try:
|
|
119
|
+
r = requests.get("https://api.eolas.fyi/health", timeout=10)
|
|
120
|
+
r.raise_for_status()
|
|
121
|
+
body = r.json()
|
|
122
|
+
return {"ok": True, "status_code": r.status_code, "body": _json_safe(body)}
|
|
123
|
+
except Exception as exc:
|
|
124
|
+
return {"ok": False, "error": _map_error(exc)}
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
@mcp.tool()
|
|
128
|
+
def eolas_search(
|
|
129
|
+
query: str,
|
|
130
|
+
source: Optional[str] = None,
|
|
131
|
+
limit: int = 25,
|
|
132
|
+
) -> dict:
|
|
133
|
+
"""Search datasets by name, title, or description (alias-aware).
|
|
134
|
+
|
|
135
|
+
Returns compact rows: name, title, source. Use eolas_info for full metadata.
|
|
136
|
+
"""
|
|
137
|
+
limit = max(1, min(int(limit), _MCP_SEARCH_CAP))
|
|
138
|
+
try:
|
|
139
|
+
df = _get_client().search(query, source=source)
|
|
140
|
+
except EolasError as exc:
|
|
141
|
+
return {"error": _map_error(exc), "datasets": []}
|
|
142
|
+
|
|
143
|
+
cols = [c for c in ("name", "title", "source", "namespace") if c in df.columns]
|
|
144
|
+
if cols:
|
|
145
|
+
df = df[cols]
|
|
146
|
+
return {
|
|
147
|
+
"query": query,
|
|
148
|
+
"count": int(len(df)),
|
|
149
|
+
"datasets": _df_records(df, max_rows=limit),
|
|
150
|
+
"truncated": len(df) > limit,
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
@mcp.tool()
|
|
155
|
+
def eolas_info(name: str) -> dict:
|
|
156
|
+
"""Dataset metadata — includes cdc_serving_tier, bulk_export_class, row counts."""
|
|
157
|
+
try:
|
|
158
|
+
meta = _get_client().info(name)
|
|
159
|
+
except EolasError as exc:
|
|
160
|
+
return {"error": _map_error(exc), "name": name}
|
|
161
|
+
return {"name": name, **_compact_info(meta)}
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
@mcp.tool()
|
|
165
|
+
def eolas_get(
|
|
166
|
+
name: str,
|
|
167
|
+
start: Optional[str] = None,
|
|
168
|
+
end: Optional[str] = None,
|
|
169
|
+
limit: int = 100,
|
|
170
|
+
) -> dict:
|
|
171
|
+
"""Fetch a small row slice via the live /data API.
|
|
172
|
+
|
|
173
|
+
Hard-capped at 500 rows. For whole datasets use eolas_download or eolas_sync.
|
|
174
|
+
"""
|
|
175
|
+
cap = max(1, min(int(limit), _MCP_GET_ROW_CAP))
|
|
176
|
+
try:
|
|
177
|
+
df = _get_client().get(name, start=start, end=end, limit=cap)
|
|
178
|
+
except EolasError as exc:
|
|
179
|
+
return {"error": _map_error(exc), "name": name, "rows": []}
|
|
180
|
+
|
|
181
|
+
# Client.get returns a Dataset (DataFrame subclass).
|
|
182
|
+
row_count = len(df)
|
|
183
|
+
return {
|
|
184
|
+
"name": name,
|
|
185
|
+
"row_count": row_count,
|
|
186
|
+
"limit_applied": cap,
|
|
187
|
+
"truncated": row_count >= cap,
|
|
188
|
+
"rows": _df_records(df, max_rows=cap),
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
@mcp.tool()
|
|
193
|
+
def eolas_download(
|
|
194
|
+
name: str,
|
|
195
|
+
path: str,
|
|
196
|
+
format: str = "parquet",
|
|
197
|
+
freshness: str = "auto",
|
|
198
|
+
) -> dict:
|
|
199
|
+
"""One-shot bulk download to a local file (returns path + bytes, not file contents).
|
|
200
|
+
|
|
201
|
+
format: parquet | csv_gz | geoparquet. freshness: auto | monthly | current.
|
|
202
|
+
"""
|
|
203
|
+
fmt = format.lower()
|
|
204
|
+
if fmt == "csv":
|
|
205
|
+
fmt = "csv_gz"
|
|
206
|
+
allowed = {"parquet", "csv_gz", "geoparquet"}
|
|
207
|
+
if fmt not in allowed:
|
|
208
|
+
return {
|
|
209
|
+
"error": f"unsupported format {format!r}; expected parquet, csv, or geoparquet",
|
|
210
|
+
"name": name,
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
out = Path(path).expanduser().resolve()
|
|
214
|
+
try:
|
|
215
|
+
result_path = _get_client().download_bulk(
|
|
216
|
+
name,
|
|
217
|
+
path=out,
|
|
218
|
+
format=fmt,
|
|
219
|
+
freshness=freshness,
|
|
220
|
+
progress=False,
|
|
221
|
+
)
|
|
222
|
+
except EolasError as exc:
|
|
223
|
+
return {"error": _map_error(exc), "name": name, "path": str(out)}
|
|
224
|
+
|
|
225
|
+
size = out.stat().st_size if out.exists() else 0
|
|
226
|
+
return _json_safe({
|
|
227
|
+
"name": name,
|
|
228
|
+
"path": str(result_path),
|
|
229
|
+
"bytes": size,
|
|
230
|
+
"format": fmt,
|
|
231
|
+
"freshness": freshness,
|
|
232
|
+
})
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
@mcp.tool()
|
|
236
|
+
def eolas_sync(
|
|
237
|
+
name: str,
|
|
238
|
+
path: str,
|
|
239
|
+
format: str = "parquet",
|
|
240
|
+
freshness: str = "auto",
|
|
241
|
+
) -> dict:
|
|
242
|
+
"""Keep a local file current — routes on cdc_serving_tier (snapshot or changelog CDC).
|
|
243
|
+
|
|
244
|
+
First call downloads; later calls are cheap (HEAD check or incremental /changes).
|
|
245
|
+
"""
|
|
246
|
+
fmt = format.lower()
|
|
247
|
+
if fmt == "csv":
|
|
248
|
+
fmt = "csv_gz"
|
|
249
|
+
if fmt != "parquet":
|
|
250
|
+
meta = {}
|
|
251
|
+
try:
|
|
252
|
+
meta = _get_client().info(name)
|
|
253
|
+
except EolasError:
|
|
254
|
+
pass
|
|
255
|
+
tier = (meta.get("cdc_serving_tier") or "snapshot") if meta else "snapshot"
|
|
256
|
+
if tier == "changelog":
|
|
257
|
+
return {
|
|
258
|
+
"error": "changelog-tier datasets only support format='parquet'",
|
|
259
|
+
"name": name,
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
out = Path(path).expanduser().resolve()
|
|
263
|
+
try:
|
|
264
|
+
result = _get_client().sync(
|
|
265
|
+
name,
|
|
266
|
+
path=out,
|
|
267
|
+
format=fmt,
|
|
268
|
+
freshness=freshness,
|
|
269
|
+
progress=False,
|
|
270
|
+
)
|
|
271
|
+
except (EolasError, ValueError) as exc:
|
|
272
|
+
return {"error": _map_error(exc), "name": name, "path": str(out)}
|
|
273
|
+
|
|
274
|
+
return _sync_payload(result, freshness=freshness, fmt=fmt)
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
def main() -> None:
|
|
278
|
+
"""Console entry point — stdio transport for MCP hosts."""
|
|
279
|
+
mcp.run(transport="stdio")
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
if __name__ == "__main__":
|
|
283
|
+
main()
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "eolas-data"
|
|
7
|
-
version = "1.
|
|
7
|
+
version = "1.10.0"
|
|
8
8
|
description = "Python client for the eolas.fyi statistical data API (NZ + OECD; Australia on roadmap)"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = { text = "MIT" }
|
|
@@ -32,6 +32,18 @@ REQUIRED: dict[str, list[str]] = {
|
|
|
32
32
|
"test_linz_nz_addresses_bulk_route_and_head",
|
|
33
33
|
"test_client_exports_cache_clear",
|
|
34
34
|
],
|
|
35
|
+
"test_mcp_server.py": [
|
|
36
|
+
"test_eolas_sync_changelog_mode",
|
|
37
|
+
"test_eolas_get_caps_rows",
|
|
38
|
+
],
|
|
39
|
+
"test_mcp_protocol.py": [
|
|
40
|
+
"test_stdio_lists_six_tools",
|
|
41
|
+
"test_stdio_eolas_health_over_wire",
|
|
42
|
+
],
|
|
43
|
+
"test_mcp_integration.py": [
|
|
44
|
+
"test_mcp_info_nz_cpi_live",
|
|
45
|
+
"test_mcp_get_nz_cpi_slice_live",
|
|
46
|
+
],
|
|
35
47
|
}
|
|
36
48
|
|
|
37
49
|
|