eolas-data 1.9.1__tar.gz → 1.11.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.1 → eolas_data-1.11.0}/.github/workflows/publish.yml +7 -1
- {eolas_data-1.9.1 → eolas_data-1.11.0}/.github/workflows/smoke.yml +3 -3
- {eolas_data-1.9.1 → eolas_data-1.11.0}/.github/workflows/test.yml +4 -4
- {eolas_data-1.9.1 → eolas_data-1.11.0}/CHANGELOG.md +35 -0
- {eolas_data-1.9.1 → eolas_data-1.11.0}/PKG-INFO +1 -1
- {eolas_data-1.9.1 → eolas_data-1.11.0}/eolas_data/__init__.py +6 -1
- {eolas_data-1.9.1 → eolas_data-1.11.0}/eolas_data/exceptions.py +35 -13
- eolas_data-1.11.0/eolas_data/mcp_server.py +283 -0
- {eolas_data-1.9.1 → eolas_data-1.11.0}/eolas_data/meta.py +9 -0
- eolas_data-1.11.0/eolas_data/reshape.py +425 -0
- {eolas_data-1.9.1 → eolas_data-1.11.0}/pyproject.toml +1 -1
- {eolas_data-1.9.1 → eolas_data-1.11.0}/scripts/check_client_contract.py +12 -0
- {eolas_data-1.9.1 → eolas_data-1.11.0}/tests/test_geometry_param.py +88 -0
- eolas_data-1.11.0/tests/test_mcp_integration.py +68 -0
- eolas_data-1.11.0/tests/test_mcp_protocol.py +89 -0
- eolas_data-1.11.0/tests/test_mcp_server.py +267 -0
- eolas_data-1.11.0/tests/test_reshape.py +403 -0
- eolas_data-1.11.0/tests/test_reshape_integration.py +233 -0
- {eolas_data-1.9.1 → eolas_data-1.11.0}/.github/workflows/catalog-drift.yml +0 -0
- {eolas_data-1.9.1 → eolas_data-1.11.0}/.github/workflows/pre-release.yml +0 -0
- {eolas_data-1.9.1 → eolas_data-1.11.0}/.gitignore +0 -0
- {eolas_data-1.9.1 → eolas_data-1.11.0}/LICENSE +0 -0
- {eolas_data-1.9.1 → eolas_data-1.11.0}/README.md +0 -0
- {eolas_data-1.9.1 → eolas_data-1.11.0}/eolas_data/_dataset_names.py +0 -0
- {eolas_data-1.9.1 → eolas_data-1.11.0}/eolas_data/_regen_names.py +0 -0
- {eolas_data-1.9.1 → eolas_data-1.11.0}/eolas_data/cdc.py +0 -0
- {eolas_data-1.9.1 → eolas_data-1.11.0}/eolas_data/cli.py +0 -0
- {eolas_data-1.9.1 → eolas_data-1.11.0}/eolas_data/client.py +0 -0
- {eolas_data-1.9.1 → eolas_data-1.11.0}/eolas_data/console.py +0 -0
- {eolas_data-1.9.1 → eolas_data-1.11.0}/eolas_data/dataset.py +0 -0
- {eolas_data-1.9.1 → eolas_data-1.11.0}/eolas_data/library.py +0 -0
- {eolas_data-1.9.1 → eolas_data-1.11.0}/eolas_data/rows.py +0 -0
- {eolas_data-1.9.1 → eolas_data-1.11.0}/eolas_data/schedule.py +0 -0
- {eolas_data-1.9.1 → eolas_data-1.11.0}/eolas_data/search.py +0 -0
- {eolas_data-1.9.1 → eolas_data-1.11.0}/scripts/preflight.sh +0 -0
- {eolas_data-1.9.1 → eolas_data-1.11.0}/tests/fixtures/source_helpers.json +0 -0
- {eolas_data-1.9.1 → eolas_data-1.11.0}/tests/test_as_arrow.py +0 -0
- {eolas_data-1.9.1 → eolas_data-1.11.0}/tests/test_cdc_roundtrip.py +0 -0
- {eolas_data-1.9.1 → eolas_data-1.11.0}/tests/test_changes_http.py +0 -0
- {eolas_data-1.9.1 → eolas_data-1.11.0}/tests/test_cli.py +0 -0
- {eolas_data-1.9.1 → eolas_data-1.11.0}/tests/test_client.py +0 -0
- {eolas_data-1.9.1 → eolas_data-1.11.0}/tests/test_date_filter.py +0 -0
- {eolas_data-1.9.1 → eolas_data-1.11.0}/tests/test_get_local.py +0 -0
- {eolas_data-1.9.1 → eolas_data-1.11.0}/tests/test_keyring.py +0 -0
- {eolas_data-1.9.1 → eolas_data-1.11.0}/tests/test_library.py +0 -0
- {eolas_data-1.9.1 → eolas_data-1.11.0}/tests/test_meta.py +0 -0
- {eolas_data-1.9.1 → eolas_data-1.11.0}/tests/test_preview_dimensions.py +0 -0
- {eolas_data-1.9.1 → eolas_data-1.11.0}/tests/test_progress.py +0 -0
- {eolas_data-1.9.1 → eolas_data-1.11.0}/tests/test_resilience.py +0 -0
- {eolas_data-1.9.1 → eolas_data-1.11.0}/tests/test_rows.py +0 -0
- {eolas_data-1.9.1 → eolas_data-1.11.0}/tests/test_schedule.py +0 -0
- {eolas_data-1.9.1 → eolas_data-1.11.0}/tests/test_search.py +0 -0
- {eolas_data-1.9.1 → eolas_data-1.11.0}/tests/test_smoke_live.py +0 -0
- {eolas_data-1.9.1 → eolas_data-1.11.0}/tests/test_source_helpers.py +0 -0
- {eolas_data-1.9.1 → eolas_data-1.11.0}/tests/test_sync_bulk.py +0 -0
- {eolas_data-1.9.1 → eolas_data-1.11.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,41 @@
|
|
|
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.11.0
|
|
7
|
+
|
|
8
|
+
### Added
|
|
9
|
+
|
|
10
|
+
- **`pivot_longer()` / `pivot_wider()` — client-side long/wide reshape.** Explicit,
|
|
11
|
+
module-level functions (never called automatically by `Client.get()`). They read the
|
|
12
|
+
new server-side `layout` metadata (`long`/`wide`/`feature`/`entity` + id/value/measure
|
|
13
|
+
columns) and **refuse rather than guess**: a `ReshapeError` when a table has no layout
|
|
14
|
+
metadata, or a `feature`/`entity` layout, or a geometry column present. `pivot_longer`
|
|
15
|
+
reattaches each measure's `series_id` on the melt; `pivot_wider` raises on non-unique
|
|
16
|
+
keys instead of silently collapsing. Both re-declare the reshaped frame's new layout so
|
|
17
|
+
`longer`↔`wider` round-trips. Re-aligns the version line with `eolas` (R) at 1.11.0.
|
|
18
|
+
|
|
19
|
+
## 1.10.0
|
|
20
|
+
|
|
21
|
+
### Added
|
|
22
|
+
|
|
23
|
+
- **MCP server (`eolas-mcp`) — now actually present.** `eolas_data/mcp_server.py`
|
|
24
|
+
exposes the client as Model Context Protocol tools over stdio for agent hosts
|
|
25
|
+
(Claude Desktop, Cursor, Grok): `eolas_health`, `eolas_search`, `eolas_info`,
|
|
26
|
+
`eolas_get`, `eolas_download`, `eolas_sync`. A thin wrapper — all HTTP, auth,
|
|
27
|
+
CDC routing and error mapping stay in `Client`. Agent-safe caps: `eolas_get`
|
|
28
|
+
is hard-limited to 500 rows and `eolas_search` to 50, so nothing streams a
|
|
29
|
+
multi-million-row table into a model's context. Install with
|
|
30
|
+
`pip install eolas-data[mcp]`; run `eolas-mcp` or `python -m eolas_data.mcp_server`.
|
|
31
|
+
|
|
32
|
+
### Fixed
|
|
33
|
+
|
|
34
|
+
- **The `[mcp]` extra and `eolas-mcp` entry point have been broken since 1.3.22.**
|
|
35
|
+
`pyproject.toml` declared both, but the `eolas_data.mcp_server` module was never
|
|
36
|
+
committed — so `pip install eolas-data[mcp]` created an `eolas-mcp` command that
|
|
37
|
+
failed with `ModuleNotFoundError` on every release from 1.3.22 to 1.9.1.
|
|
38
|
+
Verified against a clean install of the published 1.9.1 wheel. This release
|
|
39
|
+
ships the module the packaging has been promising.
|
|
40
|
+
|
|
6
41
|
## 1.9.1
|
|
7
42
|
|
|
8
43
|
### Changed
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: eolas-data
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.11.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/
|
|
@@ -16,8 +16,10 @@ from .exceptions import (
|
|
|
16
16
|
EolasError,
|
|
17
17
|
NotFoundError,
|
|
18
18
|
RateLimitError,
|
|
19
|
+
ReshapeError,
|
|
19
20
|
WatermarkExpired,
|
|
20
21
|
)
|
|
22
|
+
from .reshape import pivot_longer, pivot_wider
|
|
21
23
|
|
|
22
24
|
# Single source of truth: read the installed distribution's version so
|
|
23
25
|
# __version__, `eolas version`, and the User-Agent can never drift from
|
|
@@ -26,7 +28,7 @@ from .exceptions import (
|
|
|
26
28
|
try:
|
|
27
29
|
__version__ = _pkg_version("eolas-data")
|
|
28
30
|
except PackageNotFoundError: # pragma: no cover - uninstalled source checkout
|
|
29
|
-
__version__ = "1.
|
|
31
|
+
__version__ = "1.11.0"
|
|
30
32
|
|
|
31
33
|
__all__ = [
|
|
32
34
|
"Client",
|
|
@@ -44,4 +46,7 @@ __all__ = [
|
|
|
44
46
|
"ChangesUpgradeRequired",
|
|
45
47
|
"ChangesLicenceRestricted",
|
|
46
48
|
"WatermarkExpired",
|
|
49
|
+
"ReshapeError",
|
|
50
|
+
"pivot_longer",
|
|
51
|
+
"pivot_wider",
|
|
47
52
|
]
|
|
@@ -26,13 +26,17 @@ class APIError(EolasError):
|
|
|
26
26
|
# specifically can match the narrower type).
|
|
27
27
|
# ---------------------------------------------------------------------------
|
|
28
28
|
|
|
29
|
+
|
|
29
30
|
class BulkUpgradeRequired(APIError):
|
|
30
31
|
"""Raised on HTTP 402: the requested freshness level requires a Pro plan."""
|
|
31
32
|
|
|
32
|
-
def __init__(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
def __init__(
|
|
34
|
+
self,
|
|
35
|
+
message: str = (
|
|
36
|
+
"Fresh bulk downloads are a Pro feature. Free accounts get the latest "
|
|
37
|
+
"monthly snapshot — see https://eolas.fyi/pricing."
|
|
38
|
+
),
|
|
39
|
+
):
|
|
36
40
|
super().__init__(402, message)
|
|
37
41
|
|
|
38
42
|
|
|
@@ -50,11 +54,14 @@ class BulkLicenceRestricted(APIError):
|
|
|
50
54
|
class BulkNotYetAvailable(APIError):
|
|
51
55
|
"""Raised on HTTP 503: the monthly snapshot for this dataset does not exist yet."""
|
|
52
56
|
|
|
53
|
-
def __init__(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
def __init__(
|
|
58
|
+
self,
|
|
59
|
+
message: str = (
|
|
60
|
+
"Monthly bulk snapshots are still rolling out for this dataset. "
|
|
61
|
+
"Try again after the 1st of next month, or upgrade to Pro for "
|
|
62
|
+
"on-demand current snapshots — see https://eolas.fyi/pricing."
|
|
63
|
+
),
|
|
64
|
+
):
|
|
58
65
|
super().__init__(503, message)
|
|
59
66
|
|
|
60
67
|
|
|
@@ -62,13 +69,17 @@ class BulkNotYetAvailable(APIError):
|
|
|
62
69
|
# CDC / changelog-specific exceptions
|
|
63
70
|
# ---------------------------------------------------------------------------
|
|
64
71
|
|
|
72
|
+
|
|
65
73
|
class ChangesUpgradeRequired(APIError):
|
|
66
74
|
"""Raised on HTTP 402 from /changes: changelog sync requires Pro or higher."""
|
|
67
75
|
|
|
68
|
-
def __init__(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
76
|
+
def __init__(
|
|
77
|
+
self,
|
|
78
|
+
message: str = (
|
|
79
|
+
"Changelog sync is a Pro feature. "
|
|
80
|
+
"Upgrade at https://eolas.fyi/pricing or use sync_bulk() instead."
|
|
81
|
+
),
|
|
82
|
+
):
|
|
72
83
|
super().__init__(402, message)
|
|
73
84
|
|
|
74
85
|
|
|
@@ -79,6 +90,17 @@ class ChangesLicenceRestricted(APIError):
|
|
|
79
90
|
super().__init__(403, message)
|
|
80
91
|
|
|
81
92
|
|
|
93
|
+
class ReshapeError(EolasError):
|
|
94
|
+
"""Raised by :func:`eolas_data.reshape.pivot_longer`/`pivot_wider`.
|
|
95
|
+
|
|
96
|
+
Deliberate refusal, not a fallback to inference: a dataset with no
|
|
97
|
+
`layout` metadata, a `layout` of `"feature"`/`"entity"`, or a geometry
|
|
98
|
+
column present all raise this rather than guessing a date/period/value
|
|
99
|
+
shape. Mirrors the reasoning behind removing `Dataset.plot_dataset()` /
|
|
100
|
+
R's `eolas_plot()` in v1.3.0 — see `dataset.py`.
|
|
101
|
+
"""
|
|
102
|
+
|
|
103
|
+
|
|
82
104
|
class WatermarkExpired(APIError):
|
|
83
105
|
"""Raised on HTTP 410 from /changes: since_seq predates the retained changelog range.
|
|
84
106
|
|
|
@@ -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()
|
|
@@ -59,6 +59,15 @@ _TABLE_META_KEYS = (
|
|
|
59
59
|
"last_refreshed_at",
|
|
60
60
|
"previous_snapshots",
|
|
61
61
|
"date_filter_column",
|
|
62
|
+
# Long/wide reshape contract (2026-07-27) — consumed by
|
|
63
|
+
# eolas_data.reshape.pivot_longer()/pivot_wider(). Without these in the
|
|
64
|
+
# allowlist they would be silently dropped by split_meta() before ever
|
|
65
|
+
# reaching df.attrs["eolas_meta"], even though the API returns them.
|
|
66
|
+
"layout",
|
|
67
|
+
"time_columns",
|
|
68
|
+
"id_columns",
|
|
69
|
+
"value_columns",
|
|
70
|
+
"measure_name_column",
|
|
62
71
|
)
|
|
63
72
|
|
|
64
73
|
# Mirrors app/streaming.py::detect_date_col — columns that /data?start=&end= filter on.
|