@opendata.cat/mcp-server 0.1.1 → 0.1.2
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/dist/clients/idescat.js +11 -2
- package/dist/index.js +10 -4
- package/package.json +1 -1
package/dist/clients/idescat.js
CHANGED
|
@@ -3,14 +3,23 @@
|
|
|
3
3
|
* Consulta indicadors estadístics de Catalunya amb sèries temporals.
|
|
4
4
|
*/
|
|
5
5
|
export async function queryIdescat(endpoint) {
|
|
6
|
-
|
|
6
|
+
// Extract indicator ID from endpoint (n=XXXXX or n=mXXXXX)
|
|
7
|
+
const idMatch = endpoint.match(/[?&]n=m?(\d+)/);
|
|
8
|
+
const targetId = idMatch ? `m${idMatch[1]}` : null;
|
|
9
|
+
// Fetch ALL indicators (max=200) and filter client-side
|
|
10
|
+
const allUrl = endpoint.replace(/&?n=m?\d+/, "").replace(/&?max=\d+/, "") + "&max=200";
|
|
11
|
+
const resp = await fetch(allUrl);
|
|
7
12
|
if (!resp.ok)
|
|
8
13
|
throw new Error(`Idescat error ${resp.status}: ${resp.statusText}`);
|
|
9
14
|
const data = (await resp.json());
|
|
10
15
|
const raw = data?.indicadors?.i;
|
|
11
16
|
if (!raw)
|
|
12
17
|
return { indicators: [], count: 0 };
|
|
13
|
-
|
|
18
|
+
let items = Array.isArray(raw) ? raw : [raw];
|
|
19
|
+
// Filter by target indicator if specified
|
|
20
|
+
if (targetId) {
|
|
21
|
+
items = items.filter((item) => item.id === targetId);
|
|
22
|
+
}
|
|
14
23
|
const indicators = items
|
|
15
24
|
.filter((item) => item.id)
|
|
16
25
|
.map((item) => {
|
package/dist/index.js
CHANGED
|
@@ -15,7 +15,7 @@ import { queryIdescat } from "./clients/idescat.js";
|
|
|
15
15
|
const INSTRUCTIONS = `Servidor MCP de dades obertes de Catalunya. Pots consultar dades reals directament amb query_dataset si coneixes el dataset_id.
|
|
16
16
|
|
|
17
17
|
DATASETS DESTACATS (pots fer query_dataset directament sense cercar):
|
|
18
|
-
- generalitat:gn9e-3qhr → Embassaments:
|
|
18
|
+
- generalitat:gn9e-3qhr → Embassaments: camps dia, estaci, volum_embassat, percentatge_volum_embassat, nivell_absolut
|
|
19
19
|
- generalitat:i5n8-43cw → Estat de sequera per municipi
|
|
20
20
|
- generalitat:rmgc-ncpb → Accidents de trànsit amb morts o ferits greus
|
|
21
21
|
- generalitat:jq8m-d7cw → Incidents operatius gestionats pel CAT 112
|
|
@@ -37,8 +37,14 @@ DADES MUNICIPALS (filtra per NOM_ENS amb query_dataset):
|
|
|
37
37
|
- aoc:ge-ge-termini-pagament-proveidors → Termini pagament a proveïdors
|
|
38
38
|
|
|
39
39
|
PORTALS: generalitat (Socrata), barcelona (CKAN), diba (REST), aoc (CKAN), reus (CKAN), girona (CKAN), fgc (Opendatasoft+GTFS-RT), idescat (API indicadors)
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
|
|
41
|
+
NOTES:
|
|
42
|
+
- Socrata: pots filtrar per qualsevol camp. Ex: filters: {"estaci": "Embassament de Sau"}
|
|
43
|
+
- CKAN AOC municipals: filtra per NOM_ENS (ex: "Ajuntament de Tiana"). Camps sovint en castellà.
|
|
44
|
+
- Idescat: cada dataset_id retorna 1 indicador específic amb valor, unitat, període i sèrie temporal.
|
|
45
|
+
- FGC GTFS-RT: decodificat automàticament. vehicle-positions dona GPS, alerts dona alertes en català.
|
|
46
|
+
- Usa search_datasets només quan no saps quin dataset necessites.`;
|
|
47
|
+
const server = new McpServer({ name: "opendata-cat", version: "0.1.2" }, { instructions: INSTRUCTIONS });
|
|
42
48
|
// Tool 1: search_datasets
|
|
43
49
|
server.tool("search_datasets", "Cerca datasets per text lliure. Mira primer les instructions del servidor: molts datasets es poden consultar directament amb query_dataset sense cercar. Usa search_datasets només quan no saps quin dataset necessites.", {
|
|
44
50
|
query: z.string().describe("Text de cerca (ex: 'qualitat aire', 'pressupostos')"),
|
|
@@ -518,7 +524,7 @@ async function main() {
|
|
|
518
524
|
// Health check
|
|
519
525
|
if (req.url === "/health") {
|
|
520
526
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
521
|
-
res.end(JSON.stringify({ status: "ok", name: "opendata-cat", version: "0.1.
|
|
527
|
+
res.end(JSON.stringify({ status: "ok", name: "opendata-cat", version: "0.1.2" }));
|
|
522
528
|
return;
|
|
523
529
|
}
|
|
524
530
|
// MCP endpoint
|