Uk Legislation Mcp Server

io.github.cyanheads由 GitHub 帳號 cyanheads 發布v0.2.1更新於 Oct 29, 2026

Search and read UK legislation at any date, resolve citations, list amendments, track changes.

已驗證Streamable HTTP可網頁執行網頁搜尋與抓取知識與記憶

概覽

AI 產生的概覽

從 legislation.gov.uk 讀取英國法規:檢索法規、依任意日期讀取條文、解析引註、列出修正並追蹤變更。

可以做什麼
  • 依全文、標題、類型與年份檢索並列出法規,可依適用範圍與時間點篩選
  • 讀取整部法規或單一條文,支援現行修正版、制定原文或某一日期的版本,並附編輯狀態與未生效影響
  • 列出施加於某法規或由其產生的效力(修正、廢止、生效、修改)
  • 讀取 legislation.gov.uk 發布日誌中最多 31 天的變更
  • 將引註、簡稱與 legislation.gov.uk 連結解析為標準條目與條文
  • 離線解讀類型代碼、適用範圍、版本關鍵字與引註格式
適用情境
適合需要回答英國、蘇格蘭、威爾斯或北愛爾蘭法規問題、判斷某條文是否生效或某日期的文本、追溯其修正來源,或監控近期發布變更的情境。
執行需求
可使用託管 HTTP 端點,或透過 npx(Node.js)或 Docker 在本機執行;無需 API 金鑰或帳號。共用部署時應將 UK_LEGISLATION_CONTACT 設為電子郵件或網址,因為 legislation.gov.uk 的合理使用政策要求用戶端表明身分。需要能存取 legislation.gov.uk。
安裝前請注意
對 legislation.gov.uk 僅供讀取,不寫入、不涉及付款。修正文本為編輯性整併,可能落後於實際修正,依賴前應查看編輯狀態與未生效影響。請求受共用佇列限速,託管實例對所有呼叫者統一以每秒一次上游請求的節奏送出。法規文本與註記屬第三方資料,並非指令。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 Uk Legislation Mcp Server,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Web executable,透過 Streamable HTTP。 遠端服務在工作區中設定後即可從網頁執行環境執行。

交給代理程式安裝

把這段提示詞貼上到 Claude Code、Codex、Cursor 等代理程式,或 SourceWeft 對話中。代理程式會讀取該伺服器的安裝指南,先向你展示發布者、端點和登入方式,經你同意後再把它新增到你的客戶端。金鑰不會寫進任何命令。

閱讀 https://sourceweft.com/mcp/io.github.cyanheads%2Fuk-legislation-mcp-server/install.md,並按其中說明把這個 MCP 伺服器接入我的客戶端。修改任何設定之前,先告訴我它的發布者、端點和登入方式,等我確認。不要把 API 金鑰寫進命令或我會提交的檔案;問我金鑰應從哪裡取得。

檢視代理程式所依據的安裝指南

其他 MCP 客戶端

把它新增到你客戶端的 mcpServers 設定中。

{
  "mcpServers": {
    "uk-legislation": {
      "type": "http",
      "url": "https://uk-legislation.caseyjhand.com/mcp"
    }
  }
}

README

@cyanheads/uk-legislation-mcp-server

Search and read UK legislation at any date, resolve citations, list amendments, track changes via MCP. STDIO or Streamable HTTP.

6 Tools • 1 Resource


Overview

The UK statute book from legislation.gov.uk: primary, secondary, and EU-origin legislation for the UK, England, Scotland, Wales, and Northern Ireland. Resolve citations, search by text or title, read any provision as it stands today, as enacted, or on a past date, and track amendments. No API key required.

Tools

ToolDescription
uklaw_search_legislationSearch by full text or title, or list by type and year, filtered by extent and point in time
uklaw_get_documentRead an item or provision as revised, as enacted or made, or on a date, with its editorial status and unapplied effects
uklaw_get_amendmentsList the effects (amendments, repeals, commencements, modifications) recorded against an item or made by it
uklaw_track_changesRead the legislation.gov.uk Publication Log for a window of up to 31 days
uklaw_lookup_citationResolve a citation, short title, or legislation.gov.uk URI to the canonical item and provision
uklaw_list_referenceDecode type codes, extents, version keywords, annotation letters, citation forms, and other vocabulary, offline

Resources

ResourceDescription
skill://uk-legislation-guide/SKILL.mdAgent Skill covering how to decide with the uklaw_* tools whether a provision is in force and current, its text on a date, what amended or commenced it, and what changed since a date

The skill is served over MCP through the Agent Skills extension (io.modelcontextprotocol/skills, skill://{+path} template) and ships in skills/ in the npm package, the Docker image, and the .mcpb bundle. The tools do not depend on it.

Capability reference

uklaw_search_legislation tool

  • text (full text: AND/OR, "quoted phrases", stemming) and/or title (every word must occur), or neither to list by type and year; limit 1–50 (default 20) with page
  • Filters: types (codes such as ukpga, uksi, eur, or the groups all, primary, secondary, eu-origin, draft; default all, which excludes drafts), year or year_from / year_to (1267–2100), extent (england, wales, scotland, ni) with extent_match (applicable or exact), and as_of (YYYY-MM-DD); extent and as_of cannot be combined
  • Each result carries the item path to pass to uklaw_get_document; has_more flags another page, and title searches and listings add facets (type counts and the newest 25 years)

uklaw_get_document tool

  • item is a full path (ukpga/2018/12, uksi/2019/419, eur/2016/679, regnal ukpga/Eliz2/3-4/19) or a legislation.gov.uk URI; provision a path (section/45/2/f, schedule/2/paragraph/3) or shorthand (s. 45(2)(f), Sch. 2 para. 3); version current (default), enacted (or made, adopted, created), or a YYYY-MM-DD date; language en or cy
  • kind is full (Markdown text with its annotations), outline (provision paths to read next, 100 per call from outline_offset), or pdf_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), and match_text lists an item's provisions that contain a term
  • editorial (document_status, outstanding_effects, caveat) and unapplied_effects (the first 20, at item or provision level; a provision read also lists the effects on its enclosing provisions and, on full text, the provisions inside it, and says when it could not check them) show how far the revised text can be relied on; version.available lists the versions to pass as version

uklaw_get_amendments tool

  • item full or partial (uksi, ukpga/2018); direction affected (default: changes made to it) or affecting (changes it makes); filters counterpart (the other item, full or partial), status (all, unapplied, applied; default all), and provision (needs a full item; scans up to 1,500 effects per call)
  • limit 1–100 (default 20), continued with next_cursor; each effect names both sides with their provisions, in_force dates, applied / outstanding, and notes; total counts effects before the provision filter, and scan reports its coverage
  • Pre-1963 Acts are queried by calendar year (ukpga/1925/20) and drafts are not indexed: both fail as regnal_item / draft_item, with the route to take instead

uklaw_track_changes tool

  • start_date (required) and end_date (defaults to start_date), a window of at most 31 days; filters content_type (legislation, changes, draft, associated-documents), direction (with changes only), category (primary, secondary, eu-origin; with legislation or associated-documents only), item, new_only, and event (published, withdrawn)
  • limit 1–80 (default 40), continued with next_cursor; mode is day_walk (days newest first, up to 4 upstream requests per call) or item_log (a full item path reads that item's own log and reports read_back_to)
  • A changes event carries no effect detail: uklaw_get_amendments on its item has it

uklaw_lookup_citation tool

  • One citation of 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 item path, plus provision_found for a cited provision, checked against the current version; a miss or an ambiguous title is found: false with guidance or up to 20 candidates, not an error
FormExamplesResolves to
UK Act by chapter2018 c. 12ukpga/2018/12; before 1963 the calendar year is searched and the regnal candidates returned
Act of the Northern Ireland Assembly2016 c. 5 (N.I.)nia/2016/5
UK Statutory InstrumentS.I. 2019/419, SI 2019 No. 419, S.I. 2002/808 (W. 89)uksi/2019/419; alternative series numbers are ignored, and Welsh and NI SIs canonicalize to wsi / nisi
Scottish Statutory InstrumentS.S.I. 2020/123ssi/2020/123
Northern Ireland Statutory RuleS.R. 2020/12, S.R. 2020 No. 12nisr/2020/12
Scottish and Welsh Acts and Measures2020 asp 13, asp 2020/13, 2016 anaw 1, 2021 asc 1, 2010 nawm 1asp/2020/13, anaw/2016/1, asc/2021/1, mwa/2010/1
EU-origin legislationRegulation (EU) 2016/679, Regulation (EC) No 1535/2003, Directive 95/46/EC, Decision (EU) 2019/419; the issuing body may lead (Council Regulation (EC) No 1/2003)eur/2016/679, eur/2003/1535 (pre-2015 numbering is number/year), eudr/1995/46, eudn/2019/419
Defined nameUK GDPReur/2016/679
legislation.gov.uk URIhttps://www.legislation.gov.uk/ukpga/2018/12/section/45Split into item, provision, and version
Short titleData Protection Act 2018, Human Rights Act 1998 (c. 42)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, or attribution
  • Offline, with no request to legislation.gov.uk; each entry is a key, label, description, and optional details

skill://uk-legislation-guide/SKILL.md resource

  • Markdown with YAML frontmatter: scope, identifier sources, the gates for in-force status, revised-text lag, container effects, dated reads, and date semantics, and workflows for commencement, point-in-time text, amendment history, and changes since a date
  • Listed in resources/list; the skill://{+path} template reads any file under it

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) and If-Modified-Since revalidation
  • Citation 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") supported
  • PDF-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 the unapplied_effects touching it, so the caller can tell when the revised text is behind on amendments
  • uklaw_lookup_citation returns a miss as found: false with guidance or candidates, not as an error
  • Each tool's typed error reasons (provision_not_found, version_not_found, regnal_item, …) carry a recovery hint naming the next call
  • Every 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

Connect to the hosted instance, no install:

sh
claude mcp add --transport http uk-legislation-mcp-server https://uk-legislation.caseyjhand.com/mcp

Every caller of the hosted instance shares one request queue, paced at one legislation.gov.uk request per second under its fair use policy. For sustained use, run your own instance.

Or run it locally:

sh
claude mcp add uk-legislation-mcp-server -- npx -y @cyanheads/uk-legislation-mcp-server

For other clients, add this to the MCP config file:

json
{  "mcpServers": {    "uk-legislation-mcp-server": {      "command": "npx",      "args": ["-y", "@cyanheads/uk-legislation-mcp-server"]    }  }}

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_CONTACT to an email or URL when you run a shared deployment. For Docker or a source build, see Running the server.

Configuration

VariableDescriptionDefault
UK_LEGISLATION_CONTACTEmail or URL appended to the User-Agent so legislation.gov.uk can reach the operator. Set it on shared deployments.none
UK_LEGISLATION_MIN_REQUEST_GAP_MSMinimum gap between upstream request starts, in ms, across the process; 250 at least. A longer robots.txt crawl delay for this server's User-Agent raises it. Replicas sharing one User-Agent divide the fair use limit, so use at least 250 ms × replica count.1000
UK_LEGISLATION_CACHE_MAX_MBResponse cache size bound, in MB (8–1024).64
MCP_TRANSPORT_TYPETransport: stdio or http.stdio
MCP_HTTP_PORTHTTP server port.3010
MCP_HTTP_HOSTHTTP server host.127.0.0.1
MCP_SESSION_MODEHTTP session mode: stateless, stateful, or auto. .env.example and the Docker image set stateless.auto
MCP_AUTH_MODEAuthentication: none, jwt, or oauth.none
MCP_LOG_LEVELLog level (debug, info, warning, error, etc.).info
LOGS_DIRDirectory for log files (Node.js only).<app-root>/logs
OTEL_ENABLEDEnable OpenTelemetry.false

See .env.example for the full list of optional overrides.

Running the server

Local development

Requires Bun v1.4.0 or higher (or Node.js v24+).

  • Clone and install:

    sh
    git clone https://github.com/cyanheads/uk-legislation-mcp-server.gitcd uk-legislation-mcp-server && bun installcp .env.example .env   # optionally set UK_LEGISLATION_CONTACT
  • Build and run the production version:

    sh
    # One-time buildbun run rebuild
    # Run the built serverbun run start:http# orbun run start:stdio
  • Run checks and tests:

    sh
    bun run devcheck  # Lints, formats, type-checks, and morebun run test      # Runs the test suite

Docker

sh
docker run --rm -p 3010:3010 ghcr.io/cyanheads/uk-legislation-mcp-server:latest

The image defaults to HTTP transport, stateless session mode, and logs to /var/log/uk-legislation-mcp-server. To run it over stdio from an MCP client, use "command": "docker" with "args": ["run", "-i", "--rm", "-e", "MCP_TRANSPORT_TYPE=stdio", "ghcr.io/cyanheads/uk-legislation-mcp-server:latest"]. To build locally, docker build -t uk-legislation-mcp-server .; OpenTelemetry peer dependencies are installed by default — build with --build-arg OTEL_ENABLED=false to omit them.

Project structure

DirectoryPurpose
src/index.tscreateApp() entry point: registers the six tools; setup() reads robots.txt and builds the pacer, response cache, client, and service.
src/configServer-specific environment variable parsing and validation with Zod.
skills/The published uk-legislation-guide Agent Skill, served as an MCP resource via createApp({ skills: 'skills' }).
src/mcp-server/tools/definitionsTool definitions (*.tool.ts), plus the shared input/output schemas and Markdown rendering helpers.
src/services/legislationlegislation.gov.uk service layer: HTTP client, response cache, citation and provision-path parsing, CLML and Atom parsers, reference data, attribution.
tests/Unit tests mirroring src/, run against recorded CLML and Atom fixtures.

Development guide

See CLAUDE.md for development guidelines and architectural rules. The short version:

  • Handlers throw, framework catches — no try/catch in tool logic
  • Use ctx.log for logging and ctx.fail with a declared reason for expected failures
  • Register new tools in allToolDefinitions in src/mcp-server/tools/definitions/index.ts
  • Wrap 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:

sh
bun run devcheckbun run test

License

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.

來源:README.md,提交 d2b7906

工具

6

uklaw_search_legislation

Search UK legislation

Search the UK statute book on legislation.gov.uk by full text or title, or list legislation by type and year, filtered by geographical extent and point in time. Full-text search ranks by relevance; title searches and type/year listings run newest year first and carry type and year counts (facets) to narrow with. Each result gives the item path to pass to uklaw_get_document. For a known citation or short title, uklaw_lookup_citation is cheaper and exact.

輸入參數pagetextyearas_oflimittitletypesextentyear_toyear_fromextent_match

uklaw_get_document

Read UK legislation text

Read one item or one provision of UK legislation from legislation.gov.uk — as it stands now (revised), as enacted/made, or as it stood on a date — in Markdown, with its editorial status, annotations (the applied amendment history), the unapplied effects touching it, the versions available, and attribution. Provision-level reads are the main path; an item-level read returns the whole text only for small items and otherwise an outline of provision paths to read next. With match_text (item level), returns the provisions whose text matches. Revised text is an editorial consolidation that can lag: read editorial.caveat and unapplied_effects before relying on it, and use uklaw_get_amendments for every recorded effect on an item, applied or not.

輸入參數item必填versionlanguageprovisionmatch_textoutline_offset

uklaw_get_amendments

List amendments to or by legislation

List the effects — amendments, repeals, revocations, commencements, modifications — recorded against an item (direction affected) or made by an item (direction affecting), from legislation.gov.uk's changes feeds. Filter by the other item (counterpart), by applied status (unapplied = the outstanding work on the revised text), and by provision. item may be partial (ukpga/2018 = all effects on 2018 Acts). Each effect names both sides with provision links, in-force dates, and why it is not applied. For the applied history of one provision in prose, read its annotations with uklaw_get_document.

輸入參數item必填limitcursorstatusdirectionprovisioncounterpart

uklaw_track_changes

Track legislation.gov.uk publications

Read the legislation.gov.uk Publication Log for a date window of up to 31 days: new items, new revised versions, newly recorded effects, and withdrawals, newest first — the compliance-monitoring view of "what changed". Filter by content type, effect direction, category, an item or type/year, first-time items only, or event. With a full item path it reads that item's own log, usually in one call; otherwise it walks the window day by day, newest first, so a broad window may need several calls. A changes event carries no effect detail — uklaw_get_amendments with that item has it. Continue with next_cursor.

輸入參數itemeventlimitcursorcategoryend_datenew_onlydirectionstart_date必填content_type

uklaw_lookup_citation

Resolve a legislation citation

Resolve a citation or short title to the canonical legislation.gov.uk item and provision: "Data Protection Act 2018 s. 45", "2018 c. 12", "S.I. 2019/419", "S.S.I. 2020/123", "S.R. 2020/12", "2020 asp 13", "Regulation (EU) 2016/679 art. 28", a legislation.gov.uk URI, or a short title. Returns the item path to pass to uklaw_get_document, and when a provision is given, whether it exists in the current version. A miss or an ambiguous title is a result with found false plus guidance or candidates, not an error. To find legislation by topic or by partial title words rather than a known citation, use uklaw_search_legislation.

輸入參數citation必填

uklaw_list_reference

List legislation reference vocabulary

Decode the vocabulary the other uklaw_* tools take and return: legislation type codes (ukpga, uksi, eur, …) with their labels, categories and enacted keywords; type groups; extents; version keywords; document status; annotation letters (F, C, I, M, E, P, X); effect record fields; provision path forms and shorthand; accepted citation formats; Publication Log vocabulary and read modes; data coverage; and the attribution lines. Offline — no request to legislation.gov.uk.

輸入參數topic必填

版本歷史

4
  1. v0.2.1最新Oct 29, 2026
  2. v0.1.3Oct 25, 2026
  3. v0.1.2Oct 9, 2026
  4. v0.1.1Sep 27, 2026

評分

已滿足適用檢查項的 100%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通必需25 分
  • 已宣告認證方式必需10 分
  • 已列出工具必需15 分
  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分