@pipeworx/mcp-legislation-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 +231 -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-legislation-uk
|
|
2
|
+
|
|
3
|
+
legislation.gov.uk MCP — the UK's official legislation database.
|
|
4
|
+
|
|
5
|
+
Part of [Pipeworx](https://pipeworx.io) — an MCP gateway connecting AI agents to 965+ 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
|
+
"legislation-uk": {
|
|
20
|
+
"url": "https://gateway.pipeworx.io/legislation-uk/mcp"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Or connect to the full Pipeworx gateway for access to all 965+ 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 Legislation 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-legislation-uk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "legislation.gov.uk MCP — the UK's official legislation database.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/index.ts",
|
|
7
|
+
"types": "src/index.ts",
|
|
8
|
+
"keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "legislation-uk"],
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/pipeworx-io/mcp-legislation-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/legislation-uk",
|
|
4
|
+
"title": "Legislation Uk",
|
|
5
|
+
"description": "legislation.gov.uk MCP — the UK's official legislation database.",
|
|
6
|
+
"version": "0.1.0",
|
|
7
|
+
"websiteUrl": "https://pipeworx.io/packs/legislation-uk",
|
|
8
|
+
"repository": {
|
|
9
|
+
"url": "https://github.com/pipeworx-io/mcp-legislation-uk",
|
|
10
|
+
"source": "github"
|
|
11
|
+
},
|
|
12
|
+
"remotes": [
|
|
13
|
+
{
|
|
14
|
+
"type": "streamable-http",
|
|
15
|
+
"url": "https://gateway.pipeworx.io/legislation-uk/mcp"
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
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
|
+
* legislation.gov.uk MCP — the UK's official legislation database.
|
|
21
|
+
*
|
|
22
|
+
* UK legislation ONLY (England/Wales/Scotland/Northern Ireland). Keyless.
|
|
23
|
+
* The API serves XML/Atom, not JSON. No XML parser is available in the Worker,
|
|
24
|
+
* so fields are extracted with regex on a best-effort basis; every response
|
|
25
|
+
* includes the canonical full-text URL and a raw XML excerpt for verification.
|
|
26
|
+
*
|
|
27
|
+
* Document types: ukpga (UK Public General Acts), uksi (UK Statutory
|
|
28
|
+
* Instruments), asp (Acts of the Scottish Parliament), anaw / asc (Wales),
|
|
29
|
+
* nia (Northern Ireland Acts), ukla (UK Local Acts).
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
const BASE = 'https://www.legislation.gov.uk';
|
|
34
|
+
const UA = 'pipeworx-mcp-legislation-uk/1.0 (+https://pipeworx.io)';
|
|
35
|
+
|
|
36
|
+
const TYPES =
|
|
37
|
+
'ukpga (UK Public General Acts), uksi (UK Statutory Instruments), asp (Scottish Parliament Acts), anaw/asc (Wales), nia (Northern Ireland), ukla (UK Local Acts)';
|
|
38
|
+
|
|
39
|
+
const tools: McpToolExport['tools'] = [
|
|
40
|
+
{
|
|
41
|
+
name: 'search_legislation',
|
|
42
|
+
description:
|
|
43
|
+
'Search UK legislation by title words (and optional year), returning matching Acts/instruments with their full-text URLs. ' +
|
|
44
|
+
`UK legislation only. Source: legislation.gov.uk Atom feed. Document types: ${TYPES}.`,
|
|
45
|
+
inputSchema: {
|
|
46
|
+
type: 'object',
|
|
47
|
+
properties: {
|
|
48
|
+
type: {
|
|
49
|
+
type: 'string',
|
|
50
|
+
description: `Document type, e.g. "ukpga". One of: ${TYPES}.`,
|
|
51
|
+
},
|
|
52
|
+
title: { type: 'string', description: 'Words to match in the title, e.g. "equality".' },
|
|
53
|
+
year: { type: 'number', description: 'Optional year to restrict results, e.g. 2010.' },
|
|
54
|
+
page: { type: 'number', description: 'Results page (default 1). 20 results per page.' },
|
|
55
|
+
},
|
|
56
|
+
required: ['type', 'title'],
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
name: 'get_legislation',
|
|
61
|
+
description:
|
|
62
|
+
'Get metadata for one specific piece of UK legislation by type + year + number (e.g. ukpga/2010/15 = Equality Act 2010). ' +
|
|
63
|
+
'Returns title, type, year, number, status, extent, enactment date, a long-title summary, and the full-text URL. ' +
|
|
64
|
+
'Content is XML; fields are best-effort parsed and a raw excerpt is included.',
|
|
65
|
+
inputSchema: {
|
|
66
|
+
type: 'object',
|
|
67
|
+
properties: {
|
|
68
|
+
type: { type: 'string', description: `Document type, e.g. "ukpga". One of: ${TYPES}.` },
|
|
69
|
+
year: { type: 'number', description: 'Year, e.g. 2010.' },
|
|
70
|
+
number: { type: 'number', description: 'Item number within that year/type, e.g. 15.' },
|
|
71
|
+
},
|
|
72
|
+
required: ['type', 'year', 'number'],
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
|
|
78
|
+
switch (name) {
|
|
79
|
+
case 'search_legislation':
|
|
80
|
+
return searchLegislation(args);
|
|
81
|
+
case 'get_legislation':
|
|
82
|
+
return getLegislation(args);
|
|
83
|
+
default:
|
|
84
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async function searchLegislation(args: Record<string, unknown>): Promise<unknown> {
|
|
89
|
+
const type = reqStr(args, 'type', '"ukpga"');
|
|
90
|
+
const title = reqStr(args, 'title', '"equality"');
|
|
91
|
+
const year = numOrUndef(args.year);
|
|
92
|
+
const page = numOrUndef(args.page) ?? 1;
|
|
93
|
+
|
|
94
|
+
// The plain /{type}?title=... endpoint returns HTML; the Atom feed lives at
|
|
95
|
+
// /{type}/data.feed?title=... — confirmed via curl.
|
|
96
|
+
const params = new URLSearchParams({ title });
|
|
97
|
+
if (year !== undefined) params.set('year', String(year));
|
|
98
|
+
params.set('start-page', String(page));
|
|
99
|
+
const url = `${BASE}/${encType(type)}/data.feed?${params.toString()}`;
|
|
100
|
+
const xml = await getText(url);
|
|
101
|
+
|
|
102
|
+
const totalResults = numAttr(xml, /<openSearch:totalResults>\s*([0-9]+)\s*<\/openSearch:totalResults>/);
|
|
103
|
+
const results: Array<Record<string, unknown>> = [];
|
|
104
|
+
for (const entry of matchAll(xml, /<entry>([\s\S]*?)<\/entry>/g)) {
|
|
105
|
+
const block = entry[1];
|
|
106
|
+
const itemTitle = decode(firstGroup(block, /<title>([\s\S]*?)<\/title>/));
|
|
107
|
+
// The bare <link href="..."/> (no rel) points to the dated full-text page;
|
|
108
|
+
// the <id> is the canonical id URI.
|
|
109
|
+
const id = firstGroup(block, /<id>([\s\S]*?)<\/id>/)?.trim();
|
|
110
|
+
let url2 = firstGroup(block, /<link\s+href="([^"]+)"\s*\/>/);
|
|
111
|
+
if (!url2) url2 = firstGroup(block, /<link\s+rel="self"\s+href="([^"]+)"/);
|
|
112
|
+
results.push({
|
|
113
|
+
title: itemTitle,
|
|
114
|
+
url: url2 ?? id,
|
|
115
|
+
id,
|
|
116
|
+
year: numAttr(block, /<ukm:Year\s+Value="([0-9]+)"/),
|
|
117
|
+
number: numAttr(block, /<ukm:Number\s+Value="([0-9]+)"/),
|
|
118
|
+
type: attr(block, /<ukm:DocumentMainType\s+Value="([^"]+)"/) ?? type,
|
|
119
|
+
updated: firstGroup(block, /<updated>([\s\S]*?)<\/updated>/)?.trim(),
|
|
120
|
+
published: firstGroup(block, /<published>([\s\S]*?)<\/published>/)?.trim(),
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return {
|
|
125
|
+
source: 'legislation.gov.uk',
|
|
126
|
+
note: 'UK legislation only. Parsed best-effort from an Atom feed.',
|
|
127
|
+
query: { type, title, year, page },
|
|
128
|
+
totalResults,
|
|
129
|
+
count: results.length,
|
|
130
|
+
results,
|
|
131
|
+
feed_url: url,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
async function getLegislation(args: Record<string, unknown>): Promise<unknown> {
|
|
136
|
+
const type = reqStr(args, 'type', '"ukpga"');
|
|
137
|
+
const year = reqNum(args, 'year', '2010');
|
|
138
|
+
const number = reqNum(args, 'number', '15');
|
|
139
|
+
|
|
140
|
+
const docPath = `${encType(type)}/${year}/${number}`;
|
|
141
|
+
const url = `${BASE}/${docPath}/data.xml`;
|
|
142
|
+
const xml = await getText(url);
|
|
143
|
+
|
|
144
|
+
const fullTextUrl = `${BASE}/${docPath}`;
|
|
145
|
+
return {
|
|
146
|
+
source: 'legislation.gov.uk',
|
|
147
|
+
note: 'UK legislation only. Content is XML (CLML); fields parsed best-effort. See full_text_url for the authoritative text.',
|
|
148
|
+
title: decode(firstGroup(xml, /<dc:title>([\s\S]*?)<\/dc:title>/)),
|
|
149
|
+
type: attr(xml, /<ukm:DocumentMainType\s+Value="([^"]+)"/) ?? type,
|
|
150
|
+
category: attr(xml, /<ukm:DocumentCategory\s+Value="([^"]+)"/),
|
|
151
|
+
year: numAttr(xml, /<ukm:Year\s+Value="([0-9]+)"/) ?? Number(year),
|
|
152
|
+
number: numAttr(xml, /<ukm:Number\s+Value="([0-9]+)"/) ?? Number(number),
|
|
153
|
+
status: attr(xml, /<ukm:DocumentStatus\s+Value="([^"]+)"/),
|
|
154
|
+
// RestrictExtent on the root <Legislation> element, e.g. "E+W+S+N.I."
|
|
155
|
+
extent: attr(xml, /\bRestrictExtent="([^"]+)"/),
|
|
156
|
+
enactment_date: attr(xml, /<ukm:EnactmentDate\s+Date="([^"]+)"/),
|
|
157
|
+
modified: firstGroup(xml, /<dc:modified>([\s\S]*?)<\/dc:modified>/)?.trim(),
|
|
158
|
+
isbn: attr(xml, /<ukm:ISBN\s+Value="([^"]+)"/),
|
|
159
|
+
publisher: decode(firstGroup(xml, /<dc:publisher>([\s\S]*?)<\/dc:publisher>/)),
|
|
160
|
+
summary: decode(firstGroup(xml, /<dc:description>([\s\S]*?)<\/dc:description>/)),
|
|
161
|
+
full_text_url: fullTextUrl,
|
|
162
|
+
data_url: url,
|
|
163
|
+
raw_excerpt: xml.slice(0, 1200),
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
async function getText(url: string): Promise<string> {
|
|
168
|
+
const res = await fetch(url, { headers: { Accept: 'application/atom+xml, application/xml', 'User-Agent': UA } });
|
|
169
|
+
const body = await res.text();
|
|
170
|
+
if (!res.ok) throw new Error(`legislation.gov.uk: ${res.status} ${body.slice(0, 200)}`);
|
|
171
|
+
return body;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// --- XML/Atom helpers (regex-based; no XML libs in the Worker) ---
|
|
175
|
+
|
|
176
|
+
function encType(type: string): string {
|
|
177
|
+
return encodeURIComponent(type.trim().replace(/^\/+|\/+$/g, ''));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function* matchAll(s: string, re: RegExp): Generator<RegExpExecArray> {
|
|
181
|
+
let m: RegExpExecArray | null;
|
|
182
|
+
while ((m = re.exec(s)) !== null) yield m;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function firstGroup(s: string, re: RegExp): string | undefined {
|
|
186
|
+
const m = re.exec(s);
|
|
187
|
+
return m ? m[1] : undefined;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function attr(s: string, re: RegExp): string | undefined {
|
|
191
|
+
const v = firstGroup(s, re);
|
|
192
|
+
return v ? decode(v) : undefined;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function numAttr(s: string, re: RegExp): number | undefined {
|
|
196
|
+
const v = firstGroup(s, re);
|
|
197
|
+
return v !== undefined ? Number(v) : undefined;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function decode(s: string | undefined): string | undefined {
|
|
201
|
+
if (s === undefined) return undefined;
|
|
202
|
+
return s
|
|
203
|
+
.replace(/</g, '<')
|
|
204
|
+
.replace(/>/g, '>')
|
|
205
|
+
.replace(/"/g, '"')
|
|
206
|
+
.replace(/�?39;|'/g, "'")
|
|
207
|
+
.replace(/&/g, '&')
|
|
208
|
+
.replace(/\s+/g, ' ')
|
|
209
|
+
.trim();
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function reqStr(args: Record<string, unknown>, key: string, example: string): string {
|
|
213
|
+
const v = args[key];
|
|
214
|
+
if (typeof v !== 'string' || !v.trim())
|
|
215
|
+
throw new Error(`Required argument "${key}" is missing. Pass a string like ${example}.`);
|
|
216
|
+
return v.trim();
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function reqNum(args: Record<string, unknown>, key: string, example: string): number {
|
|
220
|
+
const n = numOrUndef(args[key]);
|
|
221
|
+
if (n === undefined) throw new Error(`Required argument "${key}" is missing. Pass a number like ${example}.`);
|
|
222
|
+
return n;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function numOrUndef(v: unknown): number | undefined {
|
|
226
|
+
if (typeof v === 'number' && Number.isFinite(v)) return v;
|
|
227
|
+
if (typeof v === 'string' && v.trim() && Number.isFinite(Number(v))) return Number(v);
|
|
228
|
+
return undefined;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
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
|
+
}
|