@opendata.cat/mcp-server 0.0.5 → 0.0.6
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/cido.d.ts +16 -0
- package/dist/clients/cido.js +34 -0
- package/dist/index.js +6 -1
- package/package.json +1 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Consulta l'API JSON:API CIDO de la Diputació de Barcelona (api.diba.cat).
|
|
3
|
+
*
|
|
4
|
+
* Endpoints: contractacions, convenis, normatives-locals, oposicions, subvencions
|
|
5
|
+
*
|
|
6
|
+
* Filtres: filter[camp]=valor (camps d'atributs directes, NO relacions)
|
|
7
|
+
* Ex: filter[institucioDesenvolupat]=Ajuntament de Tiana
|
|
8
|
+
* Ex: filter[any]=2024
|
|
9
|
+
* Ex: filter[estat]=En termini
|
|
10
|
+
*
|
|
11
|
+
* Ordenació: sort=-maxDataPublicacioDocument (descendent)
|
|
12
|
+
*/
|
|
13
|
+
export declare function queryCido(endpoint: string, filters?: Record<string, string>, search?: string, limit?: number, offset?: number): Promise<{
|
|
14
|
+
data: Record<string, unknown>[];
|
|
15
|
+
total: number;
|
|
16
|
+
}>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Consulta l'API JSON:API CIDO de la Diputació de Barcelona (api.diba.cat).
|
|
3
|
+
*
|
|
4
|
+
* Endpoints: contractacions, convenis, normatives-locals, oposicions, subvencions
|
|
5
|
+
*
|
|
6
|
+
* Filtres: filter[camp]=valor (camps d'atributs directes, NO relacions)
|
|
7
|
+
* Ex: filter[institucioDesenvolupat]=Ajuntament de Tiana
|
|
8
|
+
* Ex: filter[any]=2024
|
|
9
|
+
* Ex: filter[estat]=En termini
|
|
10
|
+
*
|
|
11
|
+
* Ordenació: sort=-maxDataPublicacioDocument (descendent)
|
|
12
|
+
*/
|
|
13
|
+
export async function queryCido(endpoint, filters, search, limit = 20, offset = 0) {
|
|
14
|
+
const url = new URL(endpoint);
|
|
15
|
+
if (filters) {
|
|
16
|
+
for (const [key, value] of Object.entries(filters)) {
|
|
17
|
+
url.searchParams.set(`filter[${key}]`, value);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
// CIDO no té cerca de text lliure, però podem filtrar per títol
|
|
21
|
+
if (search) {
|
|
22
|
+
url.searchParams.set("filter[titol]", search);
|
|
23
|
+
}
|
|
24
|
+
url.searchParams.set("sort", "-maxDataPublicacioDocument");
|
|
25
|
+
const resp = await fetch(url.toString());
|
|
26
|
+
if (!resp.ok) {
|
|
27
|
+
const err = await resp.json().catch(() => ({}));
|
|
28
|
+
const detail = err.errors?.[0]?.detail ?? resp.statusText;
|
|
29
|
+
throw new Error(`CIDO error ${resp.status}: ${detail}`);
|
|
30
|
+
}
|
|
31
|
+
const result = await resp.json();
|
|
32
|
+
const data = (result.data ?? []).slice(offset, offset + limit).map((item) => item.attributes ?? {});
|
|
33
|
+
return { data, total: result.data?.length ?? 0 };
|
|
34
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -6,9 +6,10 @@ import { searchDatasets, getDatasetInfo, getCategories } from "./api.js";
|
|
|
6
6
|
import { querySocrata } from "./clients/socrata.js";
|
|
7
7
|
import { queryCkan } from "./clients/ckan.js";
|
|
8
8
|
import { queryDiba } from "./clients/diba.js";
|
|
9
|
+
import { queryCido } from "./clients/cido.js";
|
|
9
10
|
const server = new McpServer({
|
|
10
11
|
name: "opendata-cat",
|
|
11
|
-
version: "0.0.
|
|
12
|
+
version: "0.0.6",
|
|
12
13
|
});
|
|
13
14
|
// Tool 1: search_datasets
|
|
14
15
|
server.tool("search_datasets", "Cerca datasets de dades obertes catalanes per text lliure. Retorna nom, descripció, portal i formats.", {
|
|
@@ -78,6 +79,10 @@ server.tool("query_dataset", "Executa una consulta contra un dataset i retorna f
|
|
|
78
79
|
const data = await queryDiba(dataset.api_endpoint, filters, search, limit, offset);
|
|
79
80
|
results = data.elements;
|
|
80
81
|
}
|
|
82
|
+
else if (dataset.api_type === "diba_cido") {
|
|
83
|
+
const data = await queryCido(dataset.api_endpoint, filters, search, limit, offset);
|
|
84
|
+
results = data.data;
|
|
85
|
+
}
|
|
81
86
|
else if (dataset.api_type === "ckan") {
|
|
82
87
|
const data = await queryCkan(dataset.api_endpoint, filters, search, limit, offset);
|
|
83
88
|
results = data.records;
|