@aborruso/ckan-mcp-server 0.4.6 → 0.4.8
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/EXAMPLES.md +10 -0
- package/LOG.md +57 -0
- package/PRD.md +339 -252
- package/README.md +39 -36
- package/dist/index.js +160 -21
- package/dist/worker.js +306 -74
- package/openspec/changes/update-search-parser-config/proposal.md +13 -0
- package/openspec/changes/update-search-parser-config/specs/ckan-insights/spec.md +11 -0
- package/openspec/changes/update-search-parser-config/specs/ckan-search/spec.md +11 -0
- package/openspec/changes/update-search-parser-config/tasks.md +6 -0
- package/openspec/project.md +9 -7
- package/openspec/specs/ckan-insights/spec.md +8 -1
- package/package.json +1 -1
- package/web-gui/PRD.md +158 -0
- package/web-gui/public/index.html +883 -0
- /package/openspec/changes/{add-ckan-find-relevant-datasets → archive/2026-01-10-add-ckan-find-relevant-datasets}/proposal.md +0 -0
- /package/openspec/changes/{add-ckan-find-relevant-datasets → archive/2026-01-10-add-ckan-find-relevant-datasets}/specs/ckan-insights/spec.md +0 -0
- /package/openspec/changes/{add-ckan-find-relevant-datasets → archive/2026-01-10-add-ckan-find-relevant-datasets}/tasks.md +0 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Change: Update CKAN search parser handling per portal
|
|
2
|
+
|
|
3
|
+
## Why
|
|
4
|
+
Some CKAN portals (notably dati.gov.it) use a default edismax parser with restrictive `mm` settings that breaks long OR queries. For those portals, the Lucene standard parser on the `text` field yields correct results.
|
|
5
|
+
|
|
6
|
+
## What Changes
|
|
7
|
+
- Add per-portal search configuration to `src/portals.json` to force `text:(...)` queries where needed.
|
|
8
|
+
- Add an optional tool override to force the text-field parser regardless of portal defaults.
|
|
9
|
+
- Update tool documentation to describe the behavior and override.
|
|
10
|
+
|
|
11
|
+
## Impact
|
|
12
|
+
- Affected specs: `ckan-insights`, new `ckan-search` capability
|
|
13
|
+
- Affected code: `src/portals.json`, `src/tools/package.ts`, `src/utils/*` (if new helper is added)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
## MODIFIED Requirements
|
|
2
|
+
### Requirement: Find relevant datasets
|
|
3
|
+
The system SHALL provide a `ckan_find_relevant_datasets` tool that accepts `server_url`, `query`, `limit`, optional weights for title, notes, tags, and organization, and an optional search parser override, and returns the top N datasets ranked by score with a per-field score breakdown.
|
|
4
|
+
|
|
5
|
+
#### Scenario: Ranked results returned
|
|
6
|
+
- **WHEN** the tool is invoked with a query and limit
|
|
7
|
+
- **THEN** the system uses `package_search` results to return the top N datasets with numeric scores and field contributions
|
|
8
|
+
|
|
9
|
+
#### Scenario: Search parser override applied
|
|
10
|
+
- **WHEN** the tool is invoked with a search parser override
|
|
11
|
+
- **THEN** the system applies the override to the underlying `package_search` query
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
## ADDED Requirements
|
|
2
|
+
### Requirement: Package search parser override
|
|
3
|
+
The system SHALL support a per-portal default and a per-request override to force package search queries through the `text` field when needed.
|
|
4
|
+
|
|
5
|
+
#### Scenario: Portal default applies
|
|
6
|
+
- **WHEN** a portal is configured to force the text-field parser
|
|
7
|
+
- **THEN** `ckan_package_search` uses `text:(...)` for non-fielded queries by default
|
|
8
|
+
|
|
9
|
+
#### Scenario: Request override applies
|
|
10
|
+
- **WHEN** a client explicitly requests the text-field parser
|
|
11
|
+
- **THEN** `ckan_package_search` uses `text:(...)` regardless of portal defaults
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
## 1. Implementation
|
|
2
|
+
- [x] 1.1 Add per-portal search config for forcing text-field parser
|
|
3
|
+
- [x] 1.2 Add tool override input and apply parser selection in package search
|
|
4
|
+
- [x] 1.3 Apply same override logic in find-relevant datasets
|
|
5
|
+
- [x] 1.4 Update tool docs and examples
|
|
6
|
+
- [x] 1.5 Add/adjust tests if present for query handling
|
package/openspec/project.md
CHANGED
|
@@ -22,24 +22,25 @@ Exposes MCP tools for:
|
|
|
22
22
|
|
|
23
23
|
### Code Style
|
|
24
24
|
- TypeScript strict mode enabled
|
|
25
|
-
-
|
|
26
|
-
- Utility functions for reusable operations (makeCkanRequest, truncateText, formatDate
|
|
25
|
+
- Modular tool files in `src/tools/*`
|
|
26
|
+
- Utility functions for reusable operations (makeCkanRequest, truncateText, formatDate)
|
|
27
27
|
- Zod schemas for strict input validation (reject extra parameters)
|
|
28
28
|
- Italian locale for date formatting (it-IT)
|
|
29
29
|
- Markdown output optimized for human readability; JSON available for programmatic use
|
|
30
30
|
|
|
31
31
|
### Architecture Patterns
|
|
32
|
-
- **
|
|
33
|
-
- **Tool-based architecture** -
|
|
34
|
-
- **
|
|
32
|
+
- **Modular MCP server** - registration in `src/server.ts`
|
|
33
|
+
- **Tool-based architecture** - 13 registered MCP tools for CKAN operations
|
|
34
|
+
- **Multiple transport modes**:
|
|
35
35
|
- stdio (default) - for local MCP client integration
|
|
36
36
|
- HTTP - for remote access via POST /mcp endpoint
|
|
37
|
+
- Cloudflare Workers - `/mcp` endpoint in `src/worker.ts`
|
|
37
38
|
- **Read-only operations** - no data modification on CKAN
|
|
38
39
|
- **No caching** - fresh API calls for each request
|
|
39
40
|
- **Error handling** - HTTP errors, timeouts, server validation
|
|
40
41
|
|
|
41
42
|
### Testing Strategy
|
|
42
|
-
- **
|
|
43
|
+
- **Automated tests** with Vitest (integration fixtures)
|
|
43
44
|
- Manual testing:
|
|
44
45
|
- stdio mode: direct integration testing with Claude Desktop
|
|
45
46
|
- HTTP mode: curl-based testing against localhost endpoint
|
|
@@ -67,6 +68,7 @@ Exposes MCP tools for:
|
|
|
67
68
|
- Output truncated to 50000 characters max (hardcoded)
|
|
68
69
|
- Dates formatted in Italian locale
|
|
69
70
|
- File sizes in human-readable format
|
|
71
|
+
- `server_url` for Italy uses `https://dati.gov.it/opendata`
|
|
70
72
|
|
|
71
73
|
## Important Constraints
|
|
72
74
|
|
|
@@ -91,7 +93,7 @@ Exposes MCP tools for:
|
|
|
91
93
|
|
|
92
94
|
### CKAN Portals
|
|
93
95
|
Major supported portals:
|
|
94
|
-
- 🇮🇹 https://dati.gov.it (Italia)
|
|
96
|
+
- 🇮🇹 https://dati.gov.it/opendata (Italia)
|
|
95
97
|
- 🇺🇸 https://catalog.data.gov (United States)
|
|
96
98
|
- 🇨🇦 https://open.canada.ca/data (Canada)
|
|
97
99
|
- 🇬🇧 https://data.gov.uk (United Kingdom)
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
## Purpose
|
|
4
4
|
Describe dataset insight tools (relevance, freshness, structure) once implemented.
|
|
5
|
-
|
|
6
5
|
## Requirements
|
|
7
6
|
### Requirement: Insights capability reserved
|
|
8
7
|
The system SHALL maintain this specification to document dataset insight tools when they are added.
|
|
@@ -10,3 +9,11 @@ The system SHALL maintain this specification to document dataset insight tools w
|
|
|
10
9
|
#### Scenario: Insight tools documented
|
|
11
10
|
- **WHEN** new insight tools are implemented
|
|
12
11
|
- **THEN** their requirements are captured in this specification
|
|
12
|
+
|
|
13
|
+
### Requirement: Find relevant datasets
|
|
14
|
+
The system SHALL provide a `ckan_find_relevant_datasets` tool that accepts `server_url`, `query`, `limit`, and optional weights for title, notes, tags, and organization, and returns the top N datasets ranked by score with a per-field score breakdown.
|
|
15
|
+
|
|
16
|
+
#### Scenario: Ranked results returned
|
|
17
|
+
- **WHEN** the tool is invoked with a query and limit
|
|
18
|
+
- **THEN** the system uses `package_search` results to return the top N datasets with numeric scores and field contributions
|
|
19
|
+
|
package/package.json
CHANGED
package/web-gui/PRD.md
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# CKAN Open Data Explorer
|
|
2
|
+
|
|
3
|
+
**Versione**: 1.0
|
|
4
|
+
**Data**: 25 luglio 2024
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## 1. Introduzione
|
|
9
|
+
|
|
10
|
+
"CKAN Open Data Explorer" è un'applicazione web frontend progettata per facilitare l'interazione con portali Open Data basati su CKAN, sfruttando un'interfaccia di chat in linguaggio naturale potenziata dall'API Gemini. L'obiettivo principale è rendere l'esplorazione dei dataset e delle risorse Open Data più accessibile e intuitiva per gli utenti, eliminando la necessità di navigare direttamente le interfacce complesse dei portali CKAN o di formulare query API specifiche.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## 2. Obiettivi del Prodotto
|
|
15
|
+
|
|
16
|
+
- **Semplificare l'accesso ai dati**: Permettere agli utenti di trovare e comprendere i dataset Open Data utilizzando domande e comandi in linguaggio naturale
|
|
17
|
+
- **Migliorare l'esperienza utente**: Fornire un'interfaccia conversazionale fluida e reattiva che guida l'utente attraverso il processo di ricerca dati
|
|
18
|
+
- **Abilitare l'interazione tool-driven**: Utilizzare il modello Gemini per orchestrare chiamate a un server MCP (Microservice Controller Proxy) che a sua volta interagisce con i portali CKAN
|
|
19
|
+
- **Gestire errori comuni**: Fornire feedback chiari e gestibili per errori di connessione al server MCP o problemi di quota dell'API Gemini
|
|
20
|
+
- **Configurabilità**: Consentire agli utenti di configurare l'endpoint del server MCP per adattarsi a diversi ambienti o istanze
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## 3. Utenti Target / Personas
|
|
25
|
+
|
|
26
|
+
- **Ricercatori e Analisti Dati (Principianti)**: Cercano dati specifici ma non hanno familiarità con le API CKAN o la navigazione approfondita dei portali
|
|
27
|
+
- **Giornalisti o Cittadini Curiosi**: Vogliono esplorare i dati pubblici per storie o interessi personali senza barriere tecniche
|
|
28
|
+
- **Sviluppatori (per testing)**: Potrebbero usarlo per testare il funzionamento del server MCP o per esplorare la capacità di Gemini di interpretare le richieste utente e tradurle in chiamate a tool
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## 4. Funzionalità
|
|
33
|
+
|
|
34
|
+
### 4.1 Interfaccia di Chat in Linguaggio Naturale
|
|
35
|
+
|
|
36
|
+
**Input Messaggi**:
|
|
37
|
+
- Campo di testo per l'utente per digitare domande e comandi
|
|
38
|
+
- Supporta l'invio tramite tasto Invio o un pulsante dedicato
|
|
39
|
+
|
|
40
|
+
**Display Messaggi**:
|
|
41
|
+
- Messaggi dell'utente visualizzati con sfondo grigio chiaro e testo nero
|
|
42
|
+
- Messaggi dell'assistente visualizzati con sfondo bianco
|
|
43
|
+
- Supporto per il rendering Markdown (tramite react-markdown e remark-gfm)
|
|
44
|
+
- Icone chiare (User, Bot) per distinguere il mittente
|
|
45
|
+
|
|
46
|
+
**Comportamenti**:
|
|
47
|
+
- Scroll automatico verso il basso per mostrare l'ultimo messaggio
|
|
48
|
+
- Messaggio di benvenuto iniziale per guidare l'utente
|
|
49
|
+
- Suggerimenti di query iniziali per aiutare gli utenti a iniziare
|
|
50
|
+
|
|
51
|
+
### 4.2 Integrazione con Gemini API per NLU e Tool Calling
|
|
52
|
+
|
|
53
|
+
- **Orchestrazione Gemini**: L'API Gemini (gemini-3-pro-preview) viene utilizzata per comprendere le intenzioni dell'utente e decidere quali tool dell'MCP chiamare
|
|
54
|
+
- **System Instruction**: Istruzione di sistema personalizzata che guida Gemini a comportarsi come "esperto assistente Open Data specializzato in portali CKAN" con regole rigide per l'utilizzo dei tool e la gestione degli errori CKAN
|
|
55
|
+
- **Tool Calling**: Gemini identifica e formatta le chiamate ai tool (search_datasets, get_dataset) basandosi sul inputSchema fornito dal server MCP
|
|
56
|
+
- **Ciclo di Tool Execution**: L'applicazione gestisce un ciclo di esecuzione dei tool, inviando le risposte dei tool a Gemini per ulteriori elaborazioni e generazioni di risposte in linguaggio naturale
|
|
57
|
+
- **Visualizzazione Tool in Uso**: Durante l'esecuzione di un tool, viene visualizzato un messaggio "Utilizzo tool: [nome_tool]" con icona di caricamento e parametri JSON della chiamata tool (con break-all per adattamento a tutti i dispositivi)
|
|
58
|
+
|
|
59
|
+
### 4.3 Integrazione con MCP (Microservice Controller Proxy)
|
|
60
|
+
|
|
61
|
+
- **Endpoint Configurable**: L'URL del server MCP è configurabile tramite interfaccia utente dedicata (sezione "Impostazioni")
|
|
62
|
+
- **Salute del Server**: Indicatore di stato che mostra se il server MCP è online, offline o in fase di verifica (CheckCircle2, XCircle, RefreshCw)
|
|
63
|
+
- **Fallback Tool Definitions**: Se il server MCP non è raggiungibile, l'applicazione usa definizioni di tool di fallback per mantenere funzionalità minima
|
|
64
|
+
- **Chiamate JSON-RPC**: Il servizio mcp.ts gestisce le chiamate JSON-RPC per listare i tool (tools/list) e chiamare i tool specifici (tools/call)
|
|
65
|
+
- **Gestione CORS**: Include logica di fallback utilizzando proxy corsproxy.io se la richiesta diretta fallisce
|
|
66
|
+
- **Output Tool**: L'output JSON dei tool viene parsato e visualizzato nella chat, con rendering specifico per DatasetCard
|
|
67
|
+
|
|
68
|
+
### 4.4 Visualizzazione Dati (DatasetCard)
|
|
69
|
+
|
|
70
|
+
- **Card Dettagli Dataset**: Quando Gemini restituisce risultati di dataset, questi vengono visualizzati come DatasetCard con informazioni chiave: titolo, descrizione, data di creazione, autore, licenza, tag e elenco di risorse (con link esterni)
|
|
71
|
+
- **Formattazione**: Date formattate in modo leggibile, link alle risorse chiaramente distinguibili
|
|
72
|
+
- **Troncamento**: Viene mostrato un numero limitato di risorse con messaggio "Mostrati i primi X risultati" se ce ne sono di più
|
|
73
|
+
|
|
74
|
+
### 4.5 Gestione Errori e Feedback Utente
|
|
75
|
+
|
|
76
|
+
**Errori Gemini API**:
|
|
77
|
+
- Gestione specifica degli errori di quota (RESOURCE_EXHAUSTED, codice 429)
|
|
78
|
+
- Banner di avviso (AlertTriangle) in caso di quota esaurita
|
|
79
|
+
- Istruzione per selezionare chiave API da progetto a pagamento con link alla documentazione di fatturazione
|
|
80
|
+
- Pulsante per aprire il selettore di chiavi API (se window.aistudio.openSelectKey disponibile)
|
|
81
|
+
|
|
82
|
+
**Errori MCP**:
|
|
83
|
+
- Messaggi di errore chiari se il server MCP non è raggiungibile o se una chiamata tool fallisce (es. Status 404)
|
|
84
|
+
- Incoraggiamento a controllare l'URL dell'MCP nelle impostazioni
|
|
85
|
+
|
|
86
|
+
**Stati di Caricamento**:
|
|
87
|
+
- Indicatore "Gemini sta elaborando..." al centro dello schermo quando l'API Gemini è attiva ma non sta chiamando un tool
|
|
88
|
+
- Indicatore "Utilizzo tool: [nome_tool]" quando un tool MCP è in esecuzione
|
|
89
|
+
- Pulsante di invio disabilitato durante il caricamento, se l'input è vuoto, o se l'MCP è offline
|
|
90
|
+
|
|
91
|
+
### 4.6 Configurabilità
|
|
92
|
+
|
|
93
|
+
- **Sezione Impostazioni**: Icona Settings apre un pannello dove l'utente può visualizzare e modificare l'endpoint del server MCP e la propria API key di Gemini
|
|
94
|
+
- **Salvataggio Endpoint**: Pulsante Applica salva il nuovo endpoint e verifica immediatamente la connettività MCP
|
|
95
|
+
- **Gestione API Key**: L'utente inserisce la propria API key di Gemini tramite interfaccia dedicata (campo di input protetto). La chiave viene salvata nel browser storage (localStorage) e rimane disponibile per le sessioni successive
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## 5. Requisiti Tecnici
|
|
100
|
+
|
|
101
|
+
### Frontend
|
|
102
|
+
|
|
103
|
+
- **Framework**: React 19 (tramite react/)
|
|
104
|
+
- **Linguaggio**: TypeScript
|
|
105
|
+
- **Styling**: Tailwind CSS (con plugin typography) per design moderno e responsivo
|
|
106
|
+
- **Icone**: Lucide React (lucide-react) per interfaccia visivamente accattivante
|
|
107
|
+
- **Rendering Markdown**: react-markdown con remark-gfm per rendering robusto del testo generato da Gemini
|
|
108
|
+
- **Gestione Moduli**: Utilizzo di importmap in index.html per caricamento diretto dei moduli ES6
|
|
109
|
+
|
|
110
|
+
### Backend (Implicito)
|
|
111
|
+
|
|
112
|
+
- **Gemini API**: Comunicazione con gemini-3-pro-preview tramite @google/genai SDK
|
|
113
|
+
- **MCP Server**: Interazione con un server MCP (es. ckan-mcp-server.andy-pr.workers.dev/mcp) che espone API JSON-RPC
|
|
114
|
+
- **API Key Management**: L'API key di Gemini è inserita dall'utente tramite l'interfaccia di impostazioni. La chiave viene salvata in localStorage e recuperata in ogni sessione. Supporta anche process.env.API_KEY come fallback per ambienti di sviluppo. Include meccanismo per interagire con window.aistudio.openSelectKey() per selezione di chiave API a pagamento
|
|
115
|
+
- **Error Handling**: Gestione robusta di errori HTTP, errori JSON-RPC e errori specifici dell'API Gemini
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## 6. Requisiti Non Funzionali
|
|
120
|
+
|
|
121
|
+
### Performance
|
|
122
|
+
|
|
123
|
+
- Caricamento rapido dell'interfaccia utente
|
|
124
|
+
- Risposte della chat ottimizzate per la velocità, minimizzando la latenza delle chiamate API
|
|
125
|
+
- Scroll fluido della chat, anche con molti messaggi
|
|
126
|
+
|
|
127
|
+
### Usabilità (UX)
|
|
128
|
+
|
|
129
|
+
- Interfaccia intuitiva e facile da usare per utenti di tutti i livelli tecnici
|
|
130
|
+
- Feedback visivo chiaro per stati di caricamento, errori e successo delle operazioni
|
|
131
|
+
- Messaggi di errore comprensibili e azioni suggerite
|
|
132
|
+
|
|
133
|
+
### Reattività
|
|
134
|
+
|
|
135
|
+
L'applicazione deve essere completamente responsiva e funzionare bene su desktop, tablet e dispositivi mobili
|
|
136
|
+
|
|
137
|
+
### Accessibilità (A11Y)
|
|
138
|
+
|
|
139
|
+
- Utilizzo di elementi HTML semantici
|
|
140
|
+
- Contrasto colori adeguato
|
|
141
|
+
- Navigazione da tastiera e supporto per lettori di schermo (da verificare e migliorare)
|
|
142
|
+
|
|
143
|
+
### Compatibilità Cross-browser
|
|
144
|
+
|
|
145
|
+
Funzionalità e aspetto devono essere coerenti sui principali browser moderni (Chrome, Firefox, Safari, Edge)
|
|
146
|
+
|
|
147
|
+
### Sicurezza
|
|
148
|
+
|
|
149
|
+
- La chiave API di Gemini è gestita tramite variabili d'ambiente e non esposta nel codice sorgente lato client
|
|
150
|
+
- Il CORS proxy è usato come fallback, ma si raccomanda che il server MCP gestisca il CORS direttamente per maggiore sicurezza
|
|
151
|
+
|
|
152
|
+
### Internazionalizzazione
|
|
153
|
+
|
|
154
|
+
Attualmente l'interfaccia è interamente in italiano
|
|
155
|
+
|
|
156
|
+
### Offline Functionality
|
|
157
|
+
|
|
158
|
+
L'applicazione richiede una connessione internet attiva sia per l'API Gemini che per il server MCP, quindi non supporta la funzionalità offline
|