uk-legislation-mcp-server
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@uk-legislation-mcp-serverWhat amendments were made by the Finance Act 2021?"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Overview
The National Archives publishes the UK statute book on legislation.gov.uk: primary, secondary, and EU-origin legislation for the UK, England, Scotland, Wales, and Northern Ireland. This server resolves citations and searches the statute book by text or title. It reads any provision as it stands now, as enacted or made, or as it stood on a date; lists the amendments made to or by an item; and follows what legislation.gov.uk publishes day to day. The API needs no key or account. The server runs as a stdio process or a local Streamable HTTP server.
Tools
Tool | Description |
| Search by full text or title, or list by type and year, filtered by extent and point in time |
| Read an item or provision as revised, as enacted or made, or on a date, with its editorial status and unapplied effects |
| List the effects (amendments, repeals, commencements, modifications) recorded against an item or made by it |
| Read the legislation.gov.uk Publication Log for a window of up to 31 days |
| Resolve a citation, short title, or legislation.gov.uk URI to the canonical item and provision |
| Decode type codes, extents, version keywords, annotation letters, citation forms, and other vocabulary, offline |
Related MCP server: gb-eli-mcp
Capability reference
uklaw_search_legislation tool
text(full text: AND/OR, "quoted phrases", stemming) and/ortitle(every word must occur), or neither to list by type and year;limit1–50 (default 20) withpageFilters:
types(codes such asukpga,uksi,eur, or the groupsall,primary,secondary,eu-origin,draft; defaultall, which excludes drafts),yearoryear_from/year_to(1267–2100),extent(england,wales,scotland,ni) withextent_match(applicableorexact), andas_of(YYYY-MM-DD);extentandas_ofcannot be combinedEach result carries the
itempath to pass touklaw_get_document;has_moreflags another page, and title searches and listings addfacets(type counts and the newest 25 years)
uklaw_get_document tool
itemis a full path (ukpga/2018/12,uksi/2019/419,eur/2016/679, regnalukpga/Eliz2/3-4/19) or a legislation.gov.uk URI;provisiona path (section/45/2/f,schedule/2/paragraph/3) or shorthand (s. 45(2)(f),Sch. 2 para. 3);versioncurrent(default),enacted(ormade,adopted,created), or aYYYY-MM-DDdate;languageenorcykindisfull(Markdowntextwith itsannotations),outline(provision paths to read next, 100 per call fromoutline_offset), orpdf_only(links.pdf); text over 20,000 characters, or an item with more than 25 leaf provisions, comes back as an outline (a provision with no smaller provisions to list is returned whole up to 40,000 characters and cut past that, with a notice linking the full text), andmatch_textlists an item's provisions that contain a termeditorial(document_status,outstanding_effects,caveat) andunapplied_effects(the first 20, at item or provision level) show how far the revised text can be relied on;version.availablelists the versions to pass asversion
uklaw_get_amendments tool
itemfull or partial (uksi,ukpga/2018);directionaffected(default: changes made to it) oraffecting(changes it makes); filterscounterpart(the other item, full or partial),status(all,unapplied,applied; defaultall), andprovision(needs a full item; scans up to 1,500 effects per call)limit1–100 (default 20), continued withnext_cursor; each effect names both sides with their provisions,in_forcedates,applied/outstanding, andnotes;totalcounts effects before the provision filter, andscanreports its coveragePre-1963 Acts are queried by calendar year (
ukpga/1925/20) and drafts are not indexed: both fail asregnal_item/draft_item, with the route to take instead
uklaw_track_changes tool
start_date(required) andend_date(defaults tostart_date), a window of at most 31 days; filterscontent_type(legislation,changes,draft,associated-documents),direction(withchangesonly),category(primary,secondary,eu-origin; withlegislationorassociated-documentsonly),item,new_only, andevent(published,withdrawn)limit1–80 (default 40), continued withnext_cursor;modeisday_walk(days newest first, up to 4 upstream requests per call) oritem_log(a fullitempath reads that item's own log and reportsread_back_to)A
changesevent carries no effect detail:uklaw_get_amendmentson its item has it
uklaw_lookup_citation tool
One
citationof up to 300 characters: a numbered citation, a short title, or a legislation.gov.uk URI, optionally with a provision (forms below)Returns the canonical
itempath, plusprovision_foundfor a cited provision, checked against the current version; a miss or an ambiguous title isfound: falsewithguidanceor up to 20candidates, not an error
Form | Examples | Resolves to |
UK Act by chapter |
|
|
Act of the Northern Ireland Assembly |
|
|
UK Statutory Instrument |
|
|
Scottish Statutory Instrument |
|
|
Northern Ireland Statutory Rule |
|
|
Scottish and Welsh Acts and Measures |
|
|
EU-origin legislation |
|
|
Defined name |
|
|
legislation.gov.uk URI |
| Split into item, provision, and version |
Short title |
| Resolved by title and year; a trailing chapter resolves the Act by number when the title does not |
Any form can end with a provision (s. 45(2)(f), section 45, reg. 5, art. 28(3), r. 7, r. 3.4, Sch. 2 para. 3, Pt 3) or start with one followed by "of" or "of the": section 45 of the Data Protection Act 2018. uklaw_list_reference topic citation_formats returns the same list.
uklaw_list_reference tool
topic:types,type_groups,extents,versions,document_status,annotation_types,effects,provision_paths,citation_formats,publication_log,coverage, orattributionOffline, with no request to legislation.gov.uk; each entry is a
key,label,description, and optionaldetails
Features
Built on @cyanheads/mcp-ts-core: stdio and Streamable HTTP transports, pluggable auth (none / jwt / oauth), swappable storage (in-memory, filesystem, Supabase, Cloudflare KV/R2/D1), structured logging with optional OpenTelemetry tracing.
legislation.gov.uk-specific:
Keyless client for legislation.gov.uk's API: CLML XML for documents, Atom feeds for search, effects, and the Publication Log
Follows legislation.gov.uk's fair use policy: an identifying User-Agent on every request, one process-wide queue that spaces request starts (1 second apart by default) and adopts a longer robots.txt crawl delay set for this server, up to 60 seconds, and at most 4 upstream requests per tool call within a 45-second deadline
Process-wide response cache, with lifetimes taken from upstream
max-age(capped at one hour) andIf-Modified-SincerevalidationCitation shorthand (
s. 45(2)(f),reg. 5,Sch. 2 para. 3) normalized to provision paths; pre-1963 regnal paths and Welsh-language text (language: "cy") supportedPDF-only items are linked, never fetched, as legislation.gov.uk's robots.txt requires
Agent-friendly output:
Every document read returns its editorial status with the text (
editorial.document_status,caveat,outstanding_effects) and theunapplied_effectstouching it, so the caller can tell when the revised text is behind on amendmentsuklaw_lookup_citationreturns a miss asfound: falsewithguidanceorcandidates, not as an errorEach tool's typed error reasons (
provision_not_found,version_not_found,regnal_item, …) carry a recovery hint naming the next callEvery response that returns legislation includes
attribution, the licence lines its content needs (see License)Upstream text is treated as data: legislation text, annotations, and effect notes are blockquoted in
content[], inline values are escaped, and URIs are percent-encoded
Getting started
Add the following to your MCP client configuration file.
{
"mcpServers": {
"uk-legislation-mcp-server": {
"type": "stdio",
"command": "bunx",
"args": ["@cyanheads/uk-legislation-mcp-server@latest"],
"env": {
"MCP_TRANSPORT_TYPE": "stdio",
"MCP_LOG_LEVEL": "info"
}
}
}
}Or with npx (no Bun required):
{
"mcpServers": {
"uk-legislation-mcp-server": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@cyanheads/uk-legislation-mcp-server@latest"],
"env": {
"MCP_TRANSPORT_TYPE": "stdio",
"MCP_LOG_LEVEL": "info"
}
}
}
}Or with Docker:
{
"mcpServers": {
"uk-legislation-mcp-server": {
"type": "stdio",
"command": "docker",
"args": ["run", "-i", "--rm", "-e", "MCP_TRANSPORT_TYPE=stdio", "ghcr.io/cyanheads/uk-legislation-mcp-server:latest"]
}
}
}For Streamable HTTP, set the transport and start the server:
MCP_TRANSPORT_TYPE=http MCP_HTTP_PORT=3010 bun run start:http
# Server listens at http://localhost:3010/mcpPrerequisites
Bun v1.4.0 or higher (or Node.js v24+).
No API key or account is needed. The legislation.gov.uk fair use policy asks non-browser clients to identify themselves, so set
UK_LEGISLATION_CONTACTto an email or URL when you run a shared deployment.
Installation
Clone the repository:
git clone https://github.com/cyanheads/uk-legislation-mcp-server.gitNavigate into the directory:
cd uk-legislation-mcp-serverInstall dependencies:
bun installConfigure environment:
cp .env.example .env
# edit .env and set UK_LEGISLATION_CONTACT as neededConfiguration
Variable | Description | Default |
| Email or URL appended to the User-Agent so legislation.gov.uk can reach the operator. Set it on shared deployments. | none |
| Minimum gap between upstream request starts, in ms, across the process; |
|
| Response cache size bound, in MB ( |
|
| Transport: |
|
| HTTP server port. |
|
| HTTP server host. |
|
| HTTP session mode: |
|
| Authentication: |
|
| Log level ( |
|
| Directory for log files (Node.js only). |
|
| Enable OpenTelemetry. |
|
See .env.example for the full list of optional overrides.
Running the server
Local development
Build and run the production version:
# One-time build bun run rebuild # Run the built server bun run start:http # or bun run start:stdioRun checks and tests:
bun run devcheck # Lints, formats, type-checks, and more bun run test # Runs the test suite
Project structure
Directory | Purpose |
|
|
| Server-specific environment variable parsing and validation with Zod. |
| Tool definitions ( |
| legislation.gov.uk service layer: HTTP client, response cache, citation and provision-path parsing, CLML and Atom parsers, reference data, attribution. |
| Unit tests mirroring |
Development guide
See CLAUDE.md for development guidelines and architectural rules. The short version:
Handlers throw, framework catches — no
try/catchin tool logicUse
ctx.logfor logging andctx.failwith a declared reason for expected failuresRegister new tools in
allToolDefinitionsinsrc/mcp-server/tools/definitions/index.tsWrap external API calls: validate raw → normalize to domain type → return output schema; never fabricate missing fields
Contributing
Issues are welcome. Run checks and tests before submitting:
bun run devcheck
bun run testLicense
This project is licensed under the Apache 2.0 License. See the LICENSE file for details.
Legislation content from legislation.gov.uk is © Crown and database right, licensed under the Open Government Licence v3.0. EU-origin items also carry a European Union credit (© European Union, 1998-2020, re-used under Commission Decision 2011/833/EU), and pre-1987 statutory instruments contributed to legislation.gov.uk by Westlaw UK carry a Westlaw credit. Every tool that returns legislation lists the lines that apply to its content in attribution.
This server cannot be deployed
Maintenance
Related MCP Connectors
Search UK Acts, Statutory Instruments, and legislation with full text retrieval
Resolve, search and verify legal citations against the official sources, with provenance.
Official EUR-Lex, UK, US, and gazette search, metadata fetch, and change-only watches.
Temporal search and comparison for official Luxembourg and reviewed EU law, with provenance.
Related MCP Servers
- AlicenseAqualityBmaintenanceProvides comprehensive tools for searching UK case law, legislation, parliamentary Hansard debates, and HMRC tax guidance. It features a specialized OSCOLA citation parser to extract and resolve legal references directly from text.3554 PyPI16MIT
- AlicenseAqualityAmaintenanceEnables searching and retrieval of UK legislation (Acts, Statutory Instruments) from legislation.gov.uk with persistent identifiers and verifiable citations.942 PyPIApache 2.0
- AlicenseNot gradedqualityBmaintenanceEnables querying UK Parliament data including MPs, Lords, bills, Hansard debates, and divisions.174 npmMIT
- AlicenseAqualityBmaintenanceEnables MCP clients to search New Zealand legislation, browse point-in-time versions of Acts, Bills, and secondary legislation, and read the text of sections or schedules via the official legislation.govt.nz developer API.8MIT