@pipeworx/mcp-datagov-uk 0.1.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/LICENSE +21 -0
- package/README.md +55 -0
- package/package.json +20 -0
- package/server.json +18 -0
- package/src/index.ts +145 -0
- package/tsconfig.json +14 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Pipeworx
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# mcp-datagov-uk
|
|
2
|
+
|
|
3
|
+
data.gov.uk MCP — UK national open-data portal (CKAN API).
|
|
4
|
+
|
|
5
|
+
Part of [Pipeworx](https://pipeworx.io) — an MCP gateway connecting AI agents to 708+ live data sources.
|
|
6
|
+
|
|
7
|
+
## Tools
|
|
8
|
+
|
|
9
|
+
| Tool | Description |
|
|
10
|
+
|------|-------------|
|
|
11
|
+
|
|
12
|
+
## Quick Start
|
|
13
|
+
|
|
14
|
+
Add to your MCP client (Claude Desktop, Cursor, Windsurf, etc.):
|
|
15
|
+
|
|
16
|
+
```json
|
|
17
|
+
{
|
|
18
|
+
"mcpServers": {
|
|
19
|
+
"datagov-uk": {
|
|
20
|
+
"url": "https://gateway.pipeworx.io/datagov-uk/mcp"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Or connect to the full Pipeworx gateway for access to all 708+ data sources:
|
|
27
|
+
|
|
28
|
+
```json
|
|
29
|
+
{
|
|
30
|
+
"mcpServers": {
|
|
31
|
+
"pipeworx": {
|
|
32
|
+
"url": "https://gateway.pipeworx.io/mcp"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Using with ask_pipeworx
|
|
39
|
+
|
|
40
|
+
Instead of calling tools directly, you can ask questions in plain English:
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
ask_pipeworx({ question: "your question about Datagov Uk data" })
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The gateway picks the right tool and fills the arguments automatically.
|
|
47
|
+
|
|
48
|
+
## More
|
|
49
|
+
|
|
50
|
+
- [All tools and guides](https://github.com/pipeworx-io/examples)
|
|
51
|
+
- [pipeworx.io](https://pipeworx.io)
|
|
52
|
+
|
|
53
|
+
## License
|
|
54
|
+
|
|
55
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pipeworx/mcp-datagov-uk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "data.gov.uk MCP — UK national open-data portal (CKAN API).",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/index.ts",
|
|
7
|
+
"types": "src/index.ts",
|
|
8
|
+
"keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "datagov-uk"],
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/pipeworx-io/mcp-datagov-uk"
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"typecheck": "tsc --noEmit"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"typescript": "^5.7.0"
|
|
19
|
+
}
|
|
20
|
+
}
|
package/server.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
|
|
3
|
+
"name": "io.github.pipeworx-io/datagov-uk",
|
|
4
|
+
"title": "Datagov Uk",
|
|
5
|
+
"description": "data.gov.uk MCP — UK national open-data portal (CKAN API).",
|
|
6
|
+
"version": "0.1.0",
|
|
7
|
+
"websiteUrl": "https://pipeworx.io/packs/datagov-uk",
|
|
8
|
+
"repository": {
|
|
9
|
+
"url": "https://github.com/pipeworx-io/mcp-datagov-uk",
|
|
10
|
+
"source": "github"
|
|
11
|
+
},
|
|
12
|
+
"remotes": [
|
|
13
|
+
{
|
|
14
|
+
"type": "streamable-http",
|
|
15
|
+
"url": "https://gateway.pipeworx.io/datagov-uk/mcp"
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
interface McpToolDefinition {
|
|
2
|
+
name: string;
|
|
3
|
+
description: string;
|
|
4
|
+
inputSchema: {
|
|
5
|
+
type: 'object';
|
|
6
|
+
properties: Record<string, unknown>;
|
|
7
|
+
required?: string[];
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface McpToolExport {
|
|
12
|
+
tools: McpToolDefinition[];
|
|
13
|
+
callTool: (name: string, args: Record<string, unknown>) => Promise<unknown>;
|
|
14
|
+
meter?: { credits: number };
|
|
15
|
+
cost?: Record<string, unknown>;
|
|
16
|
+
provider?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* data.gov.uk MCP — UK national open-data portal (CKAN API).
|
|
21
|
+
*
|
|
22
|
+
* Auth: none (keyless). Docs: https://docs.ckan.org/en/latest/api/
|
|
23
|
+
*
|
|
24
|
+
* Notes for callers:
|
|
25
|
+
* - This is UK government open data: central-government departments, executive
|
|
26
|
+
* agencies, devolved administrations, local councils, NHS bodies, ONS, and
|
|
27
|
+
* public-sector publishers. All metadata (dataset titles, descriptions,
|
|
28
|
+
* organization names) is in ENGLISH. Records come back as UTF-8 JSON.
|
|
29
|
+
* - The CKAN backend is served from ckan.publishing.service.gov.uk (the
|
|
30
|
+
* public data.gov.uk/api/3 host returns the HTML site, not JSON). CKAN
|
|
31
|
+
* responses are {success, result}; this pack unwraps to `result`.
|
|
32
|
+
* - This instance does NOT expose CKAN groups (group_list) or the datastore
|
|
33
|
+
* row API (datastore_search) — both return 403. Datasets here are file
|
|
34
|
+
* resources (CSV/XLSX/ZIP/etc.) with download URLs, not queryable tables.
|
|
35
|
+
* Use `dataset_details` to surface each resource's download URL + format.
|
|
36
|
+
* - The publisher taxonomy is the *organization* (e.g. office-for-national-
|
|
37
|
+
* statistics, natural-england). Filter searches by publisher with
|
|
38
|
+
* fq="organization:<name>"; browse publishers via list_organizations.
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
const BASE = 'https://ckan.publishing.service.gov.uk/api/3/action';
|
|
43
|
+
const UA = 'pipeworx-mcp-datagov-uk/1.0 (+https://pipeworx.io)';
|
|
44
|
+
|
|
45
|
+
const tools: McpToolExport['tools'] = [
|
|
46
|
+
{
|
|
47
|
+
name: 'search_datasets',
|
|
48
|
+
description:
|
|
49
|
+
'Search the data.gov.uk catalogue (CKAN package_search) across 57k+ UK government open datasets. Returns matching datasets with titles, descriptions, publishing organization, and resources. Content is English. Pass an empty query to browse everything by relevance/sort.',
|
|
50
|
+
inputSchema: {
|
|
51
|
+
type: 'object',
|
|
52
|
+
properties: {
|
|
53
|
+
query: { type: 'string', description: 'Search terms, e.g. "air quality", "house prices", "covid". Pass "" to list all datasets.' },
|
|
54
|
+
fq: { type: 'string', description: 'Solr filter query, e.g. "organization:office-for-national-statistics", "res_format:CSV", or "tags:gtfs".' },
|
|
55
|
+
rows: { type: 'number', description: 'Max results, 1-1000 (default 25).' },
|
|
56
|
+
start: { type: 'number', description: '0-based offset for paging.' },
|
|
57
|
+
sort: { type: 'string', description: 'Sort spec, e.g. "metadata_modified desc" or "score desc".' },
|
|
58
|
+
},
|
|
59
|
+
required: ['query'],
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: 'dataset_details',
|
|
64
|
+
description:
|
|
65
|
+
'Full dataset record by id or slug (CKAN package_show), including its resources. Each resource exposes a downloadable file: read "url" (the download link), "format" (CSV/XLSX/ZIP/etc.), and "name". data.gov.uk resources are files, not queryable datastore tables.',
|
|
66
|
+
inputSchema: {
|
|
67
|
+
type: 'object',
|
|
68
|
+
properties: { id: { type: 'string', description: 'Dataset id (UUID) or slug, e.g. "nhs-regions-geography-april-20161".' } },
|
|
69
|
+
required: ['id'],
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: 'list_organizations',
|
|
74
|
+
description:
|
|
75
|
+
'List publishing organizations on data.gov.uk (CKAN organization_list) — UK government departments, agencies, councils, NHS bodies, ONS, etc. Use a returned org "name" as fq="organization:<name>" in search_datasets to filter to that publisher.',
|
|
76
|
+
inputSchema: {
|
|
77
|
+
type: 'object',
|
|
78
|
+
properties: { limit: { type: 'number', description: 'Max orgs, 1-1000 (default 100).' } },
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
name: 'organization_details',
|
|
83
|
+
description:
|
|
84
|
+
'Full details for one publishing organization (CKAN organization_show): display name, description, dataset count, and (optionally) a sample of its datasets. Use to learn what a given UK publisher releases.',
|
|
85
|
+
inputSchema: {
|
|
86
|
+
type: 'object',
|
|
87
|
+
properties: {
|
|
88
|
+
id: { type: 'string', description: 'Organization id or slug, e.g. "office-for-national-statistics" or "natural-england".' },
|
|
89
|
+
include_datasets: { type: 'boolean', description: 'If true, include a sample of the org\'s datasets in "packages" (default false).' },
|
|
90
|
+
},
|
|
91
|
+
required: ['id'],
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
];
|
|
95
|
+
|
|
96
|
+
async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
|
|
97
|
+
switch (name) {
|
|
98
|
+
case 'search_datasets': {
|
|
99
|
+
const params = new URLSearchParams({
|
|
100
|
+
q: reqStr(args, 'query', '"air quality" or "" for all'),
|
|
101
|
+
rows: String(clamp(args.rows, 25, 1, 1000)),
|
|
102
|
+
start: String(Math.max(0, (args.start as number) ?? 0)),
|
|
103
|
+
});
|
|
104
|
+
if (args.fq) params.set('fq', String(args.fq));
|
|
105
|
+
if (args.sort) params.set('sort', String(args.sort));
|
|
106
|
+
return ckanGet(`/package_search?${params}`);
|
|
107
|
+
}
|
|
108
|
+
case 'dataset_details':
|
|
109
|
+
return ckanGet(`/package_show?id=${encodeURIComponent(reqStr(args, 'id', '"nhs-regions-geography-april-20161"'))}`);
|
|
110
|
+
case 'list_organizations': {
|
|
111
|
+
const params = new URLSearchParams({ all_fields: 'true', limit: String(clamp(args.limit, 100, 1, 1000)) });
|
|
112
|
+
return ckanGet(`/organization_list?${params}`);
|
|
113
|
+
}
|
|
114
|
+
case 'organization_details': {
|
|
115
|
+
const params = new URLSearchParams({ id: reqStr(args, 'id', '"office-for-national-statistics"') });
|
|
116
|
+
if (args.include_datasets === true) params.set('include_datasets', 'true');
|
|
117
|
+
return ckanGet(`/organization_show?${params}`);
|
|
118
|
+
}
|
|
119
|
+
default:
|
|
120
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
async function ckanGet(path: string): Promise<unknown> {
|
|
125
|
+
const res = await fetch(`${BASE}${path}`, { headers: { Accept: 'application/json', 'User-Agent': UA } });
|
|
126
|
+
if (!res.ok) throw new Error(`data.gov.uk: ${res.status} ${await res.text().then((t) => t.slice(0, 200))}`);
|
|
127
|
+
const json = (await res.json()) as { success?: boolean; error?: { message?: string }; result?: unknown };
|
|
128
|
+
if (json.success === false) throw new Error(`data.gov.uk: ${json.error?.message ?? 'request failed'}`);
|
|
129
|
+
return json.result ?? json;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function clamp(v: unknown, dflt: number, lo: number, hi: number): number {
|
|
133
|
+
const n = typeof v === 'number' ? v : dflt;
|
|
134
|
+
return Math.min(hi, Math.max(lo, n));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function reqStr(args: Record<string, unknown>, key: string, example: string): string {
|
|
138
|
+
const v = args[key];
|
|
139
|
+
if (typeof v !== 'string') {
|
|
140
|
+
throw new Error(`Required argument "${key}" is missing. Pass a string like ${example}.`);
|
|
141
|
+
}
|
|
142
|
+
return v;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export default { tools, callTool, meter: { credits: 1 } } satisfies McpToolExport;
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
"outDir": "dist",
|
|
10
|
+
"rootDir": "src",
|
|
11
|
+
"declaration": true
|
|
12
|
+
},
|
|
13
|
+
"include": ["src"]
|
|
14
|
+
}
|