catastro-gps-mcp 1.2.1 → 1.3.0

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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
1
+ # Changelog
2
+
3
+ ## 1.3.0 (2026-10-05)
4
+
5
+ - `search_address` now uses `GET /api/search/address/candidates`: ranked candidates with confidence in Spain and 26 more countries (`country`, `limit`), instead of the live Spanish street index only. Sweden and Croatia answer `CNV_COVERAGE`.
6
+ - New `get_units`: every unit of a Spanish building (ES, PV, NA) with stair, floor, door, use, area, participation and year, page by page with `cursor`. Costs one quota unit per unit served.
7
+ - New `resolve_reference`: free classification of a text as reference, coordinates or place name per country (`GET /api/resolve`).
8
+ - `get_terrain` returns the ERA5-Land `climate` block. `get_terrain` and `get_ground_motion` accept every reference country except Croatia, with `latitude`/`longitude` outside ES, PV, NA, PT, FR, IT and DE.
9
+ - Every result carries a `quota` object from its own response: monthly quota, prepaid overage balance, units the balance still covers, per-minute headroom and the per-finca cap on `get_units`.
10
+ - `KEY_AUTH_004` says whether to top up the prepaid balance or upgrade; `KEY_RATE_002` says how many seconds to wait.
11
+ - Fixed: the per-minute limiter was read as the monthly quota when `X-Quota-Limit` was missing; `compare_parcels` description now says it costs one unit per parcel found.
12
+ - Directory metadata (server.json, manifest.json, smithery.yaml) at 1.3.0 with the 13 tools.
13
+
14
+ ## 1.2.2
15
+
16
+ - `get_ground_motion` (Copernicus EGMS) and `get_terrain` (Copernicus DEM, Natura 2000).
package/README.md CHANGED
@@ -2,14 +2,15 @@
2
2
 
3
3
  <!-- mcp-name: com.parcelgps/catastro-gps -->
4
4
 
5
- Official cadastral parcels for AI agents, across **29 European countries plus the Basque Country and Navarre** (31 country and region codes), with one API key.
5
+ Official cadastral parcels for AI agents from **26 European cadastres plus the Basque Country and Navarre**, with one API key. Croatia (ARKOD agricultural parcels), Sweden (agricultural blocks) and Scotland (by coordinates) are served too, but they are not full cadastres: 31 country and region codes in total.
6
6
 
7
- Ask your agent for a parcel by its cadastral reference, by a point on the map or, in Spain, by a postal address typed as free text. It gets back the reference, location, area, land use and the parcel outline, and it can estimate solar and agricultural potential, read aggregated market prices, score and compare parcels in Spain, Portugal, France, Italy and Germany.
7
+ Ask your agent for a parcel by its cadastral reference, by a point on the map or by a postal address. It gets back the reference, location, area, land use and the parcel outline; it can list every dwelling of a Spanish building, read relief, protected areas, climate normals and satellite ground motion, estimate solar and agricultural potential, read aggregated market prices, and score and compare parcels.
8
8
 
9
- - **31 codes, one call shape.** `ES`, `PT`, `FR`, `IT`, `DE`, `PL`, `NL`, `CH`… and the two Spanish foral cadastres (`PV`, `NA`) that the central Catastro does not serve.
10
- - **The country is optional.** It is detected from the reference format or from the point. A few references are valid in more than one country (some German and Portuguese numbers look alike): pass `country` to be explicit.
11
- - **Free-text Spanish addresses.** `"Calle Mallorca 213, Barcelona"` becomes a cadastral reference.
12
- - **Geometry included.** Parcel outlines as GeoJSON or `[lat, lng]` rings, with centroid and area.
9
+ - **31 codes, one call shape.** `ES`, `PT`, `FR`, `IT`, `DE`, `PL`, `NL`, `CH`... and the two Spanish foral cadastres (`PV`, `NA`) that the central Catastro does not serve.
10
+ - **The country is optional.** It is detected from the reference format or from the point. When bare digits fit several countries the API says so (`CNV_AMBIGUOUS`) and `resolve_reference` tells you which ones, for free.
11
+ - **Address search in 27 countries.** `"Calle Gran Via 31, Madrid"`, `"8 boulevard du Port, Amiens"` or `"Damrak 1, 1012 LG Amsterdam"` become ranked parcels.
12
+ - **Buildings, not only plots.** `get_units` lists every dwelling, shop and garage of a Spanish building with floor, door, area and participation coefficient.
13
+ - **Your quota in every answer.** Each result carries the monthly quota left, the prepaid balance and the per-minute headroom.
13
14
  - **Free tier for good.** 250 calls a month at no cost, no card. Failed lookups are not charged.
14
15
 
15
16
  Get a key at **[parcelgps.com/developers](https://www.parcelgps.com/developers)**.
@@ -44,17 +45,27 @@ Use the same `npx -y catastro-gps-mcp` command with `CATASTROGPS_API_KEY` in the
44
45
 
45
46
  | Tool | What it does | Countries |
46
47
  |------|--------------|-----------|
47
- | `get_parcel` | Parcel by cadastral reference **or** WGS84 coordinates: reference, location, address, municipality, area, land use, outline | All 31 codes (UK: coordinates only) |
48
- | `search_address` | Spanish postal address in free text → cadastral reference | Spain, central Catastro |
48
+ | `get_parcel` | Parcel by cadastral reference **or** WGS84 coordinates: reference, location, address, municipality, area, land use, outline | All 31 codes (UK and HR: coordinates only) |
49
+ | `search_address` | Postal address in free text to ranked parcels, with confidence and whether the number and municipality match | ES (with PV and NA entrances) and FR, IT, DE, AT, NL, BE, PL, CH, CZ, DK, NO, FI, EE, LV, LT, SI, SK, BG, GR, CY, LU, LI, IS, IE, UK, PT |
50
+ | `get_units` | Every unit (dwelling, shop, garage, storage) of a Spanish building: stair, floor, door, use, area, participation, year. Paginated, 200 per page | ES, PV, NA |
51
+ | `resolve_reference` | Free, no quota: is this text a reference, coordinates or a place name, and of which country | All |
49
52
  | `get_boundaries` | Parcel outline as GeoJSON / `[lat, lng]` ring, centroid and area | 30 codes (all but UK) |
50
- | `get_solar_potential` | PVGIS photovoltaic estimate: kWp, kWh/year, savings, payback, CO₂, tilt | ES, PV, NA, PT, FR, IT, DE |
53
+ | `get_terrain` | Relief over the parcel outline (Copernicus DEM GLO-30), Natura 2000 / protected areas (EEA) and ERA5-Land climate normals with the recent change | Every reference country but HR; outside ES, PV, NA, PT, FR, IT, DE pass `latitude`/`longitude` |
54
+ | `get_ground_motion` | Ground motion measured by satellite (Copernicus EGMS, 2020-2024): subsidence or uplift in mm/year, fastest-sinking cell, east-west motion, yearly displacement; says so when there are no radar reflectors | Same as `get_terrain` |
55
+ | `get_solar_potential` | PVGIS photovoltaic estimate: kWp, kWh/year, savings, payback, CO2, tilt | ES, PV, NA, PT, FR, IT, DE |
51
56
  | `get_agriculture` | Land use, main crop, NDVI and a reference crop price (SIGPAC detail in Spain) | ES, PV, NA, PT, FR, IT, DE |
52
57
  | `get_market_data` | Aggregated price reference for the parcel's area. Never individual sales | Figures: FR, IT, DE (NRW only). ES, PV, NA, PT: note without figures |
53
- | `get_investment_score` | Score 0–100 with a rating and qualitative factor levels (high / medium / low / not available) | ES, PV, NA, PT, FR, IT, DE |
58
+ | `get_investment_score` | Score 0-100 with a rating and qualitative factor levels (high / medium / low / not available) | ES, PV, NA, PT, FR, IT, DE |
54
59
  | `get_value_history` | Area and land-use snapshots of the parcel over time | ES, PV, NA, PT, FR, IT, DE, AT |
55
60
  | `compare_parcels` | Two or three parcels side by side: location, solar, agriculture, score | ES, PT, FR, IT, DE (not PV or NA) |
56
61
 
57
- Every tool call is one API call against your monthly quota, including calls that end in "not found". `compare_parcels` is one call for the whole comparison.
62
+ ## Quota, prepaid balance and limits
63
+
64
+ - Only successful answers with data spend quota: a not found, a validation error, `CNV_COVERAGE`, `CNV_AMBIGUOUS`, a 5xx and an answer without data (`available: false`) are free. `resolve_reference` never spends.
65
+ - Each successful call costs 1 unit, except `get_units` (one unit per unit served in the page, minimum 1) and `compare_parcels` (one per parcel found).
66
+ - Every result carries a `quota` object read from that same response: `remaining`, `limit`, `resets_at`, `plan`, and when they apply `prepaid_overage`, `prepaid_balance_eur`, `overage_units_left`, `per_minute_remaining`, and on `get_units` with a contract per-finca cap `finca_cap` / `finca_cap_used`.
67
+ - When the monthly quota runs out the API does not cut you off if you have prepaid balance: each extra unit is paid from it (top up at [parcelgps.com/app/developer](https://parcelgps.com/app/developer)). With the quota used up and no balance the call fails with `KEY_AUTH_004` (HTTP 429, never 402) and the error says whether to top up or upgrade, and when the quota resets.
68
+ - A separate per-minute limit depends on the plan (Free 10, Developer 60, Startup 120, Growth 300 calls per minute; a global per-IP guard also applies). Going over it answers `KEY_RATE_002` with the seconds to wait.
58
69
 
59
70
  ### What the market, score and history tools can and cannot tell
60
71
 
@@ -65,43 +76,34 @@ Every tool call is one API call against your monthly quota, including calls that
65
76
 
66
77
  ## Coverage
67
78
 
68
- What each code answers today. "Partial" means the official source does not cover the whole territory.
69
-
70
- | Code | Country / region | By reference | By coordinates | Geometry | Notes |
71
- |------|------------------|:---:|:---:|:---:|-------|
72
- | `ES` | Spain (central Catastro) | ✅ | ✅ | ✅ | Free-text address search too |
73
- | `PV` | Basque Country (Álava, Bizkaia, Gipuzkoa) | ✅ | ✅ | ✅ | Foral cadastres, separate from the central Catastro |
74
- | `NA` | Navarre | ✅ | ✅ | ✅ | Foral cadastre |
75
- | `PT` | Portugal | Partial | ✅ | Partial | Digital cadastre does not cover the whole country |
76
- | `FR` | France | ✅ | ✅ | ✅ | |
77
- | `IT` | Italy | ✅ | ✅ | ✅ | |
78
- | `DE` | Germany | Partial | Partial | Partial | Every Land except Bavaria |
79
- | `AT` | Austria | ✅ | ✅ | ✅ | |
80
- | `CH` | Switzerland | ✅ | ✅ | ✅ | E-GRID references |
81
- | `LI` | Liechtenstein | ✅ | ✅ | ✅ | |
82
- | `BE` | Belgium | ✅ | ✅ | ✅ | |
83
- | `NL` | Netherlands | ✅ | ✅ | ✅ | |
84
- | `LU` | Luxembourg | ✅ | ✅ | ✅ | |
85
- | `PL` | Poland | ✅ | ✅ | ✅ | TERYT parcel IDs |
86
- | `CZ` | Czechia | ✅ | ✅ | ✅ | |
87
- | `SK` | Slovakia | ✅ | ✅ | ✅ | |
88
- | `SI` | Slovenia | ✅ | ✅ | ✅ | |
89
- | `HR` | Croatia | ✅ | ✅ | ✅ | |
90
- | `BG` | Bulgaria | ✅ | ✅ | ✅ | |
91
- | `GR` | Greece | ✅ | ✅ | ✅ | |
92
- | `CY` | Cyprus | ✅ | ✅ | ✅ | |
93
- | `DK` | Denmark | ✅ | ✅ | ✅ | |
94
- | `SE` | Sweden | ✅ | ✅ | ✅ | Agricultural blocks (Jordbruksverket), not property units |
95
- | `NO` | Norway | ✅ | ✅ | ✅ | |
96
- | `FI` | Finland | ✅ | ✅ | ✅ | |
97
- | `IS` | Iceland | ✅ | ✅ | ✅ | |
98
- | `EE` | Estonia | ✅ | ✅ | ✅ | |
99
- | `LV` | Latvia | ✅ | ✅ | ✅ | |
100
- | `LT` | Lithuania | ✅ | ✅ | ✅ | |
101
- | `IE` | Ireland | ✅ | ✅ | ✅ | |
102
- | `UK` | United Kingdom | — | Scotland | Scotland | Registers of Scotland; England, Wales and Northern Ireland not yet |
103
-
104
- Data comes live from each country's official cadastre or INSPIRE service, so availability follows theirs: some national services are slow, and the server raises a clear `SERVICE_UNAVAILABLE` when one is down. Outside the table, a point or reference answers `CNV_COVERAGE`.
79
+ What each code answers today (measured against production on 1 October 2026). "Partial" means the official source does not cover the whole territory.
80
+
81
+ | Code | Country / region | By reference | By coordinates | Address search | Notes |
82
+ |------|------------------|---|---|---|-------|
83
+ | `ES` | Spain (central Catastro) | yes | yes | yes | Buildings and dwellings with `get_units` |
84
+ | `PV` | Basque Country (Araba, Bizkaia, Gipuzkoa) | yes | yes | with `country: ES` | Foral cadastres; `get_units` without participation coefficient |
85
+ | `NA` | Navarre | yes | yes | with `country: ES` | Foral cadastre; `get_units` |
86
+ | `FR` | France | yes | yes | yes | |
87
+ | `IT` | Italy | yes | yes | yes | |
88
+ | `DE` | Germany | partial | partial | partial | 15 of 16 Lander: **not Bavaria** |
89
+ | `AT` | Austria | yes | yes | yes | |
90
+ | `NL` | Netherlands | yes | yes | yes | |
91
+ | `BE` | Belgium | yes | yes (slow source) | yes | |
92
+ | `PL` | Poland | yes | yes | yes | TERYT parcel IDs |
93
+ | `CH` | Switzerland | yes | partial | yes | Not in cantons that publish no parcels (e.g. Vaud) |
94
+ | `CZ` `DK` `NO` `FI` `EE` | Czechia, Denmark, Norway, Finland, Estonia | yes | yes | yes | |
95
+ | `LT` `SI` `SK` `BG` | Lithuania, Slovenia, Slovakia, Bulgaria | yes | yes | yes | |
96
+ | `LU` `LI` `IS` | Luxembourg, Liechtenstein, Iceland | yes | yes | yes | |
97
+ | `CY` | Cyprus | yes | yes | yes, low confidence | Few house numbers mapped |
98
+ | `LV` | Latvia | with `country: LV` | yes | yes | |
99
+ | `GR` | Greece | with `country: GR` | yes | yes | |
100
+ | `PT` | Portugal | yes | partial | partial | The cadastre does not cover Lisbon, Porto or Coimbra; the DGT source is often down |
101
+ | `IE` | Ireland | with `country: IE` (SP_ID) | partial | partial | |
102
+ | `UK` | United Kingdom | no | Scotland only | Scotland only | England, Wales and Northern Ireland not yet |
103
+ | `HR` | Croatia | no | ARKOD agricultural parcels only | no | No open cadastre; not Zagreb or Rijeka |
104
+ | `SE` | Sweden | agricultural blocks | agricultural blocks | no | Not property units |
105
+
106
+ Hungary, Romania and the rest of Europe are not covered: a reference or point there answers `CNV_COVERAGE`. Data comes from each country's official cadastre or INSPIRE service (Spain from our copy of the Catastro), so availability follows theirs; when one is down the server answers `SERVICE_UNAVAILABLE`, which is free.
105
107
 
106
108
  Official registry documents (Spanish *nota simple*, Italian *visura*, Portuguese *certidão permanente* and others) can be ordered at [catastrogps.es](https://www.catastrogps.es). They are not exposed through the API or this server yet.
107
109
 
@@ -111,6 +113,10 @@ Ask your agent:
111
113
 
112
114
  > Find the cadastral parcel at Calle Mallorca 213, Barcelona, and give me its area and outline.
113
115
 
116
+ > List every flat of the building at Avenida Jose Rodriguez de la Borbolla 10, Dos Hermanas, with floor, door and area.
117
+
118
+ > Is the ground sinking under parcel 30024A16000286? Is it inside a Natura 2000 site?
119
+
114
120
  > What is the parcel at 52.2297, 21.0122? What's its area?
115
121
 
116
122
  > Look up the Polish parcel 146510_8.0502.1/3 and tell me its area.
@@ -144,7 +150,7 @@ Errors come back as a code plus a sentence the agent can act on, for example:
144
150
  ```text
145
151
  CNV_COVERAGE: That reference or point is in a country that is not covered yet.
146
152
  SERVICE_UNAVAILABLE: The official cadastre for this country is not responding. Try again in a few minutes.
147
- KEY_AUTH_004: Monthly quota exhausted. Upgrade at https://www.parcelgps.com/developers
153
+ KEY_AUTH_004: Monthly quota used up and prepaid balance empty: top up at https://parcelgps.com/app/developer (or upgrade at https://www.parcelgps.com/developers).
148
154
  ```
149
155
 
150
156
  ## Pricing
@@ -175,6 +181,7 @@ Details and sign-up: [parcelgps.com/developers](https://www.parcelgps.com/develo
175
181
  npm install
176
182
  npm run lint
177
183
  npm test
184
+ npm run test:coverage
178
185
  npm run build
179
186
  CATASTROGPS_API_KEY=pk_live_xxx node build/index.js
180
187
  ```
@@ -1,24 +1,43 @@
1
- import type { ServerConfig, ApiResponse, ParcelData, PolygonData, SolarData, AgroData, MarketData, ScoreData, ValueHistoryData, CompareData, CoordinatesSearchData, AddressSearchData } from "../types/index.js";
1
+ import type { Quota, ServerConfig, ApiResponse, ParcelData, PolygonData, SolarData, TerrainData, GroundMotionData, AgroData, MarketData, ScoreData, ValueHistoryData, CompareData, CoordinatesSearchData, AddressCandidatesData, UnitsPageData, ResolveData } from "../types/index.js";
2
+ export interface ApiErrorExtras {
3
+ quota?: Quota;
4
+ retryAfterSeconds?: number;
5
+ }
2
6
  export declare class CatastroGPSApiError extends Error {
3
7
  readonly code: string;
4
8
  readonly status: number;
5
9
  readonly details?: unknown | undefined;
6
- readonly resetsAt?: string | undefined;
7
- constructor(code: string, message: string, status: number, details?: unknown | undefined, resetsAt?: string | undefined);
10
+ readonly quota?: Quota;
11
+ readonly retryAfterSeconds?: number;
12
+ constructor(code: string, message: string, status: number, details?: unknown | undefined, extras?: ApiErrorExtras);
13
+ get resetsAt(): string | undefined;
8
14
  }
15
+ export type { Quota };
16
+ export declare function readQuota(headers: Headers): Quota | undefined;
9
17
  export declare class CatastroGPSClient {
10
18
  private readonly apiKey;
11
19
  private readonly baseUrl;
12
20
  private readonly timeout;
21
+ lastQuota?: Quota;
13
22
  constructor(config: ServerConfig);
14
23
  private buildUrl;
15
24
  private send;
16
25
  private parcelPath;
17
26
  getParcelByReference(reference: string, country?: string): Promise<ApiResponse<ParcelData>>;
18
27
  getParcelByCoordinates(lat: number, lng: number, country?: string): Promise<ApiResponse<CoordinatesSearchData>>;
19
- searchAddress(address: string): Promise<ApiResponse<AddressSearchData>>;
28
+ searchAddressCandidates(address: string, country?: string, limit?: number): Promise<ApiResponse<AddressCandidatesData>>;
29
+ getUnits(reference: string, country?: string, cursor?: string): Promise<ApiResponse<UnitsPageData>>;
30
+ resolve(text: string, hint?: string): Promise<ApiResponse<ResolveData>>;
20
31
  getPolygon(reference: string, country?: string): Promise<ApiResponse<PolygonData>>;
21
32
  getSolarPotential(reference: string, country?: string): Promise<ApiResponse<SolarData>>;
33
+ getTerrain(reference: string, country?: string, point?: {
34
+ lat: number;
35
+ lng: number;
36
+ }): Promise<ApiResponse<TerrainData>>;
37
+ getGroundMotion(reference: string, country?: string, point?: {
38
+ lat: number;
39
+ lng: number;
40
+ }): Promise<ApiResponse<GroundMotionData>>;
22
41
  getAgriculture(reference: string, country?: string): Promise<ApiResponse<AgroData>>;
23
42
  getMarketData(reference: string, country?: string): Promise<ApiResponse<MarketData>>;
24
43
  getInvestmentScore(reference: string, country?: string): Promise<ApiResponse<ScoreData>>;
@@ -3,20 +3,88 @@ export class CatastroGPSApiError extends Error {
3
3
  code;
4
4
  status;
5
5
  details;
6
- resetsAt;
7
- constructor(code, message, status, details, resetsAt) {
6
+ quota;
7
+ retryAfterSeconds;
8
+ constructor(code, message, status, details, extras = {}) {
8
9
  super(message);
9
10
  this.code = code;
10
11
  this.status = status;
11
12
  this.details = details;
12
- this.resetsAt = resetsAt;
13
13
  this.name = "CatastroGPSApiError";
14
+ this.quota = extras.quota;
15
+ this.retryAfterSeconds = extras.retryAfterSeconds;
14
16
  }
17
+ get resetsAt() {
18
+ return this.quota?.resetsAt;
19
+ }
20
+ }
21
+ function numberHeader(headers, name) {
22
+ const raw = headers.get(name);
23
+ if (raw === null || raw.trim() === "")
24
+ return undefined;
25
+ const value = Number(raw);
26
+ return Number.isFinite(value) ? value : undefined;
27
+ }
28
+ function readOverage(headers) {
29
+ const flag = headers.get("X-Quota-Overage");
30
+ if (flag === null)
31
+ return undefined;
32
+ return {
33
+ enabled: flag.trim().toLowerCase() === "on",
34
+ balanceEur: numberHeader(headers, "X-Quota-Balance"),
35
+ unitPriceEur: numberHeader(headers, "X-Quota-Overage-Unit-Price"),
36
+ unitsLeft: numberHeader(headers, "X-Quota-Overage-Remaining"),
37
+ };
38
+ }
39
+ function readPerMinute(headers) {
40
+ if (!headers.has("X-RateLimit-Limit") && !headers.has("X-RateLimit-Remaining"))
41
+ return undefined;
42
+ return {
43
+ limit: numberHeader(headers, "X-RateLimit-Limit"),
44
+ remaining: numberHeader(headers, "X-RateLimit-Remaining"),
45
+ resetSeconds: numberHeader(headers, "X-RateLimit-Reset"),
46
+ };
47
+ }
48
+ function readFincaCap(headers) {
49
+ const cap = numberHeader(headers, "X-Quota-Finca-Cap");
50
+ if (cap === undefined)
51
+ return undefined;
52
+ return { cap, used: numberHeader(headers, "X-Quota-Finca-Cap-Used") };
53
+ }
54
+ export function readQuota(headers) {
55
+ const quota = {};
56
+ const plan = headers.get("X-Quota-Tier");
57
+ if (plan !== null)
58
+ quota.plan = plan;
59
+ const limit = numberHeader(headers, "X-Quota-Limit");
60
+ if (limit !== undefined)
61
+ quota.limit = limit;
62
+ const remaining = numberHeader(headers, "X-Quota-Remaining");
63
+ if (remaining !== undefined)
64
+ quota.remaining = remaining;
65
+ const resetsAt = headers.get("X-Quota-Reset");
66
+ if (resetsAt !== null)
67
+ quota.resetsAt = resetsAt;
68
+ const overage = readOverage(headers);
69
+ if (overage)
70
+ quota.overage = overage;
71
+ const perMinute = readPerMinute(headers);
72
+ if (perMinute)
73
+ quota.perMinute = perMinute;
74
+ const fincaCap = readFincaCap(headers);
75
+ if (fincaCap)
76
+ quota.fincaCap = fincaCap;
77
+ return Object.keys(quota).length > 0 ? quota : undefined;
78
+ }
79
+ function retryAfterSeconds(headers) {
80
+ const value = numberHeader(headers, "Retry-After");
81
+ return value !== undefined && value > 0 ? value : undefined;
15
82
  }
16
83
  export class CatastroGPSClient {
17
84
  apiKey;
18
85
  baseUrl;
19
86
  timeout;
87
+ lastQuota;
20
88
  constructor(config) {
21
89
  this.apiKey = config.apiKey;
22
90
  this.baseUrl = config.apiUrl.replace(/\/$/, "");
@@ -49,11 +117,18 @@ export class CatastroGPSClient {
49
117
  body: body === undefined ? undefined : JSON.stringify(body),
50
118
  signal: controller.signal,
51
119
  });
120
+ const quota = readQuota(response.headers);
121
+ if (quota)
122
+ this.lastQuota = quota;
52
123
  if (!response.ok) {
53
124
  const errorBody = (await response.json().catch(() => ({})));
54
- throw new CatastroGPSApiError(errorBody.code || `HTTP_${response.status}`, errorBody.error || errorBody.message || `API returned ${response.status}`, response.status, errorBody.data ?? errorBody.parsed, response.headers.get("X-RateLimit-Reset") ?? undefined);
125
+ throw new CatastroGPSApiError(errorBody.code || `HTTP_${response.status}`, errorBody.error || errorBody.message || `API returned ${response.status}`, response.status, errorBody.data ?? errorBody.parsed, { quota, retryAfterSeconds: retryAfterSeconds(response.headers) });
126
+ }
127
+ const payload = (await response.json());
128
+ if (quota && payload && typeof payload === "object") {
129
+ return { ...payload, quota };
55
130
  }
56
- return (await response.json());
131
+ return payload;
57
132
  }
58
133
  catch (error) {
59
134
  if (error instanceof CatastroGPSApiError)
@@ -76,8 +151,14 @@ export class CatastroGPSClient {
76
151
  async getParcelByCoordinates(lat, lng, country) {
77
152
  return this.send("GET", "/api/search/coordinates", { lat, lng, country });
78
153
  }
79
- async searchAddress(address) {
80
- return this.send("POST", "/api/search/address/parse", undefined, { direccion: address });
154
+ async searchAddressCandidates(address, country, limit) {
155
+ return this.send("GET", "/api/search/address/candidates", { q: address, country, limit });
156
+ }
157
+ async getUnits(reference, country, cursor) {
158
+ return this.send("GET", this.parcelPath(reference, "/units"), { country, cursor });
159
+ }
160
+ async resolve(text, hint) {
161
+ return this.send("GET", "/api/resolve", { q: text, hint });
81
162
  }
82
163
  async getPolygon(reference, country) {
83
164
  return this.send("GET", this.parcelPath(reference, "/polygon"), { country });
@@ -85,6 +166,12 @@ export class CatastroGPSClient {
85
166
  async getSolarPotential(reference, country) {
86
167
  return this.send("GET", this.parcelPath(reference, "/solar"), { country });
87
168
  }
169
+ async getTerrain(reference, country, point) {
170
+ return this.send("GET", this.parcelPath(reference, "/terrain"), { country, lat: point?.lat, lng: point?.lng });
171
+ }
172
+ async getGroundMotion(reference, country, point) {
173
+ return this.send("GET", this.parcelPath(reference, "/ground-motion"), { country, lat: point?.lat, lng: point?.lng });
174
+ }
88
175
  async getAgriculture(reference, country) {
89
176
  return this.send("GET", this.parcelPath(reference, "/agro"), { country });
90
177
  }
package/build/server.d.ts CHANGED
@@ -3,5 +3,8 @@ import type { ServerConfig } from "./types/index.js";
3
3
  export declare const DEFAULT_API_URL = "https://api.parcelgps.com";
4
4
  export declare const DEFAULT_TIMEOUT_MS = 20000;
5
5
  export declare function createServer(config: ServerConfig): McpServer;
6
+ export type EndpointConfig = Omit<ServerConfig, "apiKey">;
7
+ export declare function loadEndpointConfig(): EndpointConfig;
6
8
  export declare function loadConfig(): ServerConfig;
9
+ export declare function sessionConfig(endpoint: EndpointConfig, apiKeyHeader: string | string[] | undefined): ServerConfig | null;
7
10
  //# sourceMappingURL=server.d.ts.map
package/build/server.js CHANGED
@@ -4,11 +4,15 @@ import { registerGetParcel } from "./tools/get-parcel.js";
4
4
  import { registerSearchAddress } from "./tools/search-address.js";
5
5
  import { registerGetBoundaries } from "./tools/get-boundaries.js";
6
6
  import { registerGetSolar } from "./tools/get-solar.js";
7
+ import { registerGetTerrain } from "./tools/get-terrain.js";
8
+ import { registerGetGroundMotion } from "./tools/get-ground-motion.js";
7
9
  import { registerGetAgriculture } from "./tools/get-agriculture.js";
8
10
  import { registerGetMarket } from "./tools/get-market.js";
9
11
  import { registerGetScore } from "./tools/get-score.js";
10
12
  import { registerGetValueHistory } from "./tools/get-value-history.js";
11
13
  import { registerCompareParcels } from "./tools/compare-parcels.js";
14
+ import { registerGetUnits } from "./tools/get-units.js";
15
+ import { registerResolveReference } from "./tools/resolve-reference.js";
12
16
  import { SERVER_VERSION } from "./version.js";
13
17
  export const DEFAULT_API_URL = "https://api.parcelgps.com";
14
18
  export const DEFAULT_TIMEOUT_MS = 20000;
@@ -22,13 +26,24 @@ export function createServer(config) {
22
26
  registerSearchAddress(server, client);
23
27
  registerGetBoundaries(server, client);
24
28
  registerGetSolar(server, client);
29
+ registerGetTerrain(server, client);
30
+ registerGetGroundMotion(server, client);
25
31
  registerGetAgriculture(server, client);
26
32
  registerGetMarket(server, client);
27
33
  registerGetScore(server, client);
28
34
  registerGetValueHistory(server, client);
29
35
  registerCompareParcels(server, client);
36
+ registerGetUnits(server, client);
37
+ registerResolveReference(server, client);
30
38
  return server;
31
39
  }
40
+ export function loadEndpointConfig() {
41
+ const timeout = parseInt(process.env.CATASTROGPS_TIMEOUT || "", 10);
42
+ return {
43
+ apiUrl: process.env.CATASTROGPS_API_URL || DEFAULT_API_URL,
44
+ timeout: Number.isFinite(timeout) && timeout > 0 ? timeout : DEFAULT_TIMEOUT_MS,
45
+ };
46
+ }
32
47
  export function loadConfig() {
33
48
  const apiKey = process.env.CATASTROGPS_API_KEY;
34
49
  if (!apiKey) {
@@ -36,11 +51,12 @@ export function loadConfig() {
36
51
  "Get a free key (250 calls/month, failed lookups are free) at https://www.parcelgps.com/developers");
37
52
  process.exit(1);
38
53
  }
39
- const timeout = parseInt(process.env.CATASTROGPS_TIMEOUT || "", 10);
40
- return {
41
- apiKey,
42
- apiUrl: process.env.CATASTROGPS_API_URL || DEFAULT_API_URL,
43
- timeout: Number.isFinite(timeout) && timeout > 0 ? timeout : DEFAULT_TIMEOUT_MS,
44
- };
54
+ return { apiKey, ...loadEndpointConfig() };
55
+ }
56
+ export function sessionConfig(endpoint, apiKeyHeader) {
57
+ const apiKey = (Array.isArray(apiKeyHeader) ? apiKeyHeader[0] : apiKeyHeader)?.trim();
58
+ if (!apiKey)
59
+ return null;
60
+ return { apiKey, ...endpoint };
45
61
  }
46
62
  //# sourceMappingURL=server.js.map
package/build/sse.js CHANGED
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
  import { createServer as createHttpServer } from "node:http";
3
3
  import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js";
4
- import { createServer, loadConfig } from "./server.js";
4
+ import { createServer, loadEndpointConfig, sessionConfig } from "./server.js";
5
5
  import { SERVER_NAME, SERVER_VERSION } from "./version.js";
6
6
  const log = (msg) => console.error(`[catastro-gps-mcp] ${msg}`);
7
7
  async function main() {
8
- const config = loadConfig();
8
+ const endpoint = loadEndpointConfig();
9
9
  const port = parseInt(process.env.MCP_PORT || "3001", 10);
10
10
  const transports = new Map();
11
11
  const httpServer = createHttpServer(async (req, res) => {
@@ -24,6 +24,12 @@ async function main() {
24
24
  return;
25
25
  }
26
26
  if (url.pathname === "/sse" && req.method === "GET") {
27
+ const config = sessionConfig(endpoint, req.headers["x-api-key"]);
28
+ if (!config) {
29
+ res.writeHead(401, { "Content-Type": "application/json" });
30
+ res.end(JSON.stringify({ error: "X-API-Key header with your own Catastro GPS key is required" }));
31
+ return;
32
+ }
27
33
  const transport = new SSEServerTransport("/message", res);
28
34
  const sessionId = transport.sessionId;
29
35
  transports.set(sessionId, transport);
@@ -33,7 +33,7 @@ export function registerCompareParcels(server, client) {
33
33
  "common regime), PT, FR, IT and DE. The Basque Country and Navarre are not supported here " +
34
34
  "(use the single-parcel tools). Area, land use and municipality are only filled for Spain. " +
35
35
  "No market prices. A parcel that is not found comes back with an error and the others are " +
36
- "still compared. One API call for the whole comparison.",
36
+ "still compared. Costs one quota unit per parcel found (0 to 3).",
37
37
  inputSchema: {
38
38
  parcels: z
39
39
  .array(z.object({
@@ -46,9 +46,9 @@ export function registerCompareParcels(server, client) {
46
46
  },
47
47
  }, async ({ parcels }) => {
48
48
  try {
49
- const { data } = await client.compareParcels(parcels);
49
+ const { data, quota } = await client.compareParcels(parcels);
50
50
  const items = data.comparacion ?? [];
51
- return jsonResult({ total: data.total ?? items.length, parcels: items.map(summarize) });
51
+ return jsonResult({ total: data.total ?? items.length, parcels: items.map(summarize) }, quota);
52
52
  }
53
53
  catch (error) {
54
54
  return handleToolError(error);
@@ -17,8 +17,8 @@ export function registerGetAgriculture(server, client) {
17
17
  },
18
18
  }, async ({ reference, country }) => {
19
19
  try {
20
- const { data } = await client.getAgriculture(reference, country);
21
- return jsonResult({ reference, country: country ?? null, agriculture: data.agro ?? data });
20
+ const { data, quota } = await client.getAgriculture(reference, country);
21
+ return jsonResult({ reference, country: country ?? null, agriculture: data.agro ?? data }, quota);
22
22
  }
23
23
  catch (error) {
24
24
  return handleToolError(error);
@@ -16,7 +16,7 @@ export function registerGetBoundaries(server, client) {
16
16
  },
17
17
  }, async ({ reference, country }) => {
18
18
  try {
19
- const { data: d } = await client.getPolygon(reference, country);
19
+ const { data: d, quota } = await client.getPolygon(reference, country);
20
20
  return jsonResult(compact({
21
21
  reference: d.refCatastral || d.refcat || reference,
22
22
  country: d.pais || country,
@@ -25,7 +25,7 @@ export function registerGetBoundaries(server, client) {
25
25
  area_m2: d.area || d.superficieParcela,
26
26
  outline_lat_lng: d.poligono,
27
27
  geojson: d.geojson,
28
- }));
28
+ }), quota);
29
29
  }
30
30
  catch (error) {
31
31
  return handleToolError(error);
@@ -0,0 +1,4 @@
1
+ import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import type { CatastroGPSClient } from "../client/catastrogps-api.js";
3
+ export declare function registerGetGroundMotion(server: McpServer, client: CatastroGPSClient): void;
4
+ //# sourceMappingURL=get-ground-motion.d.ts.map
@@ -0,0 +1,48 @@
1
+ import { z } from "zod";
2
+ import { SITE_ANALYSIS_COUNTRIES } from "../types/index.js";
3
+ import { handleToolError, jsonResult, sitePoint } from "./shared.js";
4
+ export function registerGetGroundMotion(server, client) {
5
+ server.registerTool("get_ground_motion", {
6
+ title: "Get Ground Motion (Subsidence)",
7
+ description: "Whether the ground under the parcel sinks or rises and how fast, measured by satellite radar " +
8
+ "(Copernicus European Ground Motion Service, EGMS L3 Ortho, Sentinel-1 InSAR, 100 m grid, 2020-2024): " +
9
+ "mean vertical velocity in mm/year over the parcel outline (negative = sinking), fastest-sinking cell, " +
10
+ "east-west velocity, class from stable to severe_subsidence, cells with data and the mean displacement " +
11
+ "of each year. status no_data with reason no_reflectors means the satellite found nothing stable to " +
12
+ "measure (fields, forest, water): there is no figure, not a zero. Carries the source, licence and the " +
13
+ "attribution to show. Every covered country inside EGMS coverage: in ES, PV, NA, PT, FR, IT and DE the " +
14
+ "reference is enough; elsewhere also pass latitude and longitude (from get_parcel). Costs 1 quota unit.",
15
+ inputSchema: {
16
+ reference: z.string().min(1).describe("Official cadastral reference"),
17
+ country: z
18
+ .enum(SITE_ANALYSIS_COUNTRIES)
19
+ .optional()
20
+ .describe("Optional country code. Omit to auto-detect from the reference."),
21
+ latitude: z.number().min(-90).max(90).optional()
22
+ .describe("Latitude of the parcel point (WGS84). Required outside ES, PV, NA, PT, FR, IT and DE"),
23
+ longitude: z.number().min(-180).max(180).optional()
24
+ .describe("Longitude of the parcel point (WGS84). Required outside ES, PV, NA, PT, FR, IT and DE"),
25
+ },
26
+ }, async ({ reference, country, latitude, longitude }) => {
27
+ const { point, error } = sitePoint(country, latitude, longitude);
28
+ if (error)
29
+ return error;
30
+ try {
31
+ const { data, quota } = await client.getGroundMotion(reference, country, point);
32
+ return jsonResult({
33
+ reference: data.refcat,
34
+ country: data.country,
35
+ status: data.status,
36
+ reason: data.reason,
37
+ period: data.period?.label,
38
+ ground_motion: data.ground_motion,
39
+ source: data.source,
40
+ calculated_at: data.calculated_at,
41
+ }, quota);
42
+ }
43
+ catch (caught) {
44
+ return handleToolError(caught);
45
+ }
46
+ });
47
+ }
48
+ //# sourceMappingURL=get-ground-motion.js.map
@@ -20,7 +20,7 @@ export function registerGetMarket(server, client) {
20
20
  },
21
21
  }, async ({ reference, country }) => {
22
22
  try {
23
- const { data: d } = await client.getMarketData(reference, country);
23
+ const { data: d, quota } = await client.getMarketData(reference, country);
24
24
  const hasFigures = (d.precio_m2_eur ?? 0) > 0 || (d.precio_estimado_eur ?? 0) > 0;
25
25
  return jsonResult({
26
26
  reference,
@@ -36,7 +36,7 @@ export function registerGetMarket(server, client) {
36
36
  updated: d.fecha_actualizacion || null,
37
37
  source: d.fuente ?? null,
38
38
  note: d.mensaje_usuario ?? null,
39
- });
39
+ }, quota);
40
40
  }
41
41
  catch (error) {
42
42
  return handleToolError(error);
@@ -28,7 +28,7 @@ export function registerGetParcel(server, client) {
28
28
  if (country === "UK") {
29
29
  return errorResult("MCP_002", "United Kingdom parcels can only be looked up by coordinates.");
30
30
  }
31
- const { data: d } = await client.getParcelByReference(reference, country);
31
+ const { data: d, quota } = await client.getParcelByReference(reference, country);
32
32
  return jsonResult(compact({
33
33
  reference: d.refCatastral,
34
34
  country: d.pais || country,
@@ -46,12 +46,12 @@ export function registerGetParcel(server, client) {
46
46
  source: d.fuenteDatos,
47
47
  outline_lat_lng: d.poligono,
48
48
  google_maps_url: d.googleMapsUrl,
49
- }));
49
+ }), quota);
50
50
  }
51
51
  if (latitude === undefined || longitude === undefined) {
52
52
  return errorResult("MCP_001", "Provide either 'reference' or both 'latitude' and 'longitude'.");
53
53
  }
54
- const { data: d } = await client.getParcelByCoordinates(latitude, longitude, country);
54
+ const { data: d, quota } = await client.getParcelByCoordinates(latitude, longitude, country);
55
55
  return jsonResult(compact({
56
56
  reference: d.referenciaCatastral || d.refCatastral,
57
57
  country: d.pais || country,
@@ -64,7 +64,7 @@ export function registerGetParcel(server, client) {
64
64
  area_m2: d.superficieParcela,
65
65
  property_type: d.tipoInmueble,
66
66
  google_maps_url: d.googleMapsUrl,
67
- }));
67
+ }), quota);
68
68
  }
69
69
  catch (error) {
70
70
  return handleToolError(error);