@opendata.cat/mcp-server 0.0.16 → 0.0.17

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.
@@ -15,5 +15,54 @@ export async function querySocrata(endpoint, filters, search, limit = 20, offset
15
15
  const resp = await fetch(url.toString());
16
16
  if (!resp.ok)
17
17
  throw new Error(`Socrata error ${resp.status}: ${resp.statusText}`);
18
- return (await resp.json());
18
+ const rows = (await resp.json());
19
+ // Simplify geo fields: replace heavy polygon coords with centroid
20
+ return rows.map((row) => {
21
+ const simplified = {};
22
+ for (const [key, val] of Object.entries(row)) {
23
+ if (val && typeof val === "object" && "type" in val) {
24
+ const geo = val;
25
+ if (geo.type === "Point") {
26
+ simplified[key] = val;
27
+ }
28
+ else if (geo.type === "MultiPolygon" || geo.type === "Polygon" || geo.type === "MultiLineString" || geo.type === "LineString") {
29
+ // Extract centroid from coordinates
30
+ const coords = _flattenCoords(geo.coordinates);
31
+ if (coords.length > 0) {
32
+ const lats = coords.map((c) => c[1]);
33
+ const lngs = coords.map((c) => c[0]);
34
+ simplified[key] = {
35
+ type: geo.type,
36
+ centroid: { lat: _avg(lats), lng: _avg(lngs) },
37
+ bbox: { min_lat: Math.min(...lats), max_lat: Math.max(...lats), min_lng: Math.min(...lngs), max_lng: Math.max(...lngs) },
38
+ vertex_count: coords.length,
39
+ _note: "Geometria simplificada a centroide+bbox per no saturar el context. Usa l'endpoint .geojson de Socrata per obtenir les coordenades completes.",
40
+ };
41
+ }
42
+ else {
43
+ simplified[key] = val;
44
+ }
45
+ }
46
+ else {
47
+ simplified[key] = val;
48
+ }
49
+ }
50
+ else {
51
+ simplified[key] = val;
52
+ }
53
+ }
54
+ return simplified;
55
+ });
56
+ }
57
+ function _flattenCoords(coords) {
58
+ if (!Array.isArray(coords))
59
+ return [];
60
+ if (coords.length === 0)
61
+ return [];
62
+ if (typeof coords[0] === "number")
63
+ return [coords];
64
+ return coords.flatMap((c) => _flattenCoords(c));
65
+ }
66
+ function _avg(nums) {
67
+ return Math.round((nums.reduce((a, b) => a + b, 0) / nums.length) * 10000) / 10000;
19
68
  }
package/dist/index.js CHANGED
@@ -13,7 +13,7 @@ import { queryOpendatasoft } from "./clients/opendatasoft.js";
13
13
  import { decodeGtfsRt } from "./clients/gtfsrt.js";
14
14
  const server = new McpServer({
15
15
  name: "opendata-cat",
16
- version: "0.0.16",
16
+ version: "0.0.17",
17
17
  });
18
18
  // Tool 1: search_datasets
19
19
  server.tool("search_datasets", "Cerca datasets de dades obertes catalanes per text lliure. Retorna nom, descripció, portal i formats.", {
@@ -471,7 +471,7 @@ async function main() {
471
471
  // Health check
472
472
  if (req.url === "/health") {
473
473
  res.writeHead(200, { "Content-Type": "application/json" });
474
- res.end(JSON.stringify({ status: "ok", name: "opendata-cat", version: "0.0.16" }));
474
+ res.end(JSON.stringify({ status: "ok", name: "opendata-cat", version: "0.0.17" }));
475
475
  return;
476
476
  }
477
477
  // MCP endpoint
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.0.16",
6
+ "version": "0.0.17",
7
7
  "description": "Servidor MCP per consultar les dades obertes públiques de Catalunya",
8
8
  "type": "module",
9
9
  "main": "dist/index.js",