UK legal research MCP server — case law, legislation, parliament, bills, votes, committees, citations, HMRC
Project description
uk-legal-mcp
A Model Context Protocol server for UK legal research. Connects AI assistants to case law, legislation, parliamentary debates, OSCOLA citation parsing, and HMRC tax data through a single endpoint.
15 tools across 5 modules. One connection. Read-only. No API keys required for 14 of 15 tools.
MCP Client (Claude, Cursor, etc.)
|
v
uk-legal-mcp gateway (Streamable HTTP)
+----------------------------------------------------+
| |
| case_law TNA Find Case Law API |
| legislation legislation.gov.uk + i.AI Lex API |
| parliament Hansard API + Members API |
| citations OSCOLA regex parser (no network) |
| hmrc HMRC sandbox/prod + GOV.UK search |
| |
+----------------------------------------------------+
Quickstart
Connect to the hosted server
Add to your Claude Desktop config (~/Library/Application Support/Claude/claude_desktop_config.json):
{
"mcpServers": {
"uk-legal": {
"type": "streamable-http",
"url": "https://uk-legal-mcp.fly.dev/mcp"
}
}
}
Then try:
- "Search for case law about cycling accidents"
- "Get section 172 of the Companies Act 2006"
- "Parse the citations in: The court applied Donoghue v Stevenson [1932] AC 562 and s.2 Occupiers' Liability Act 1957"
- "What is parliament saying about short selling?"
Run locally
pip install -e .
python -m src.gateway
# Server starts on http://localhost:8000/mcp
Inspect with the MCP Inspector:
npx @modelcontextprotocol/inspector http://localhost:8000/mcp
Tools
Case Law
| Tool | What it does |
|---|---|
case_law_search |
Full-text search of UK judgments. Filter by court, judge, party, date range. |
case_law_get_judgment |
Retrieve full LegalDocML XML for a judgment by TNA URI slug. |
Upstream: TNA Find Case Law (Atom/XML). Rate limit: 1,000 req/5 min. Cached 1 hour.
Legislation
| Tool | What it does |
|---|---|
legislation_search |
Search Acts of Parliament and Statutory Instruments via the i.AI Lex API. |
legislation_get_toc |
Table of contents for an Act — parts, chapters, sections, schedules. |
legislation_get_section |
Retrieve a specific section with territorial extent, in-force status, and version date. |
Upstream: legislation.gov.uk (CLML XML) + i.AI Lex API (JSON). Cached 24 hours.
Note: Always check the extent field. A section may apply to England and Wales but not Scotland or Northern Ireland.
Parliament
| Tool | What it does |
|---|---|
parliament_search_hansard |
Search Hansard debate contributions by exact phrase. |
parliament_vibe_check |
Assess parliamentary reception of a policy topic. Searches Hansard, then uses LLM sampling to classify sentiment, supporters, opponents, and concerns. |
parliament_find_member |
Look up an MP or Lord by name. Returns member ID for use with member_debates. |
parliament_member_debates |
Retrieve a specific member's Hansard contributions, optionally filtered by topic. |
Upstream: hansard-api.parliament.uk + members-api.parliament.uk. Not cached (live data).
Citations
| Tool | What it does |
|---|---|
citations_parse |
Extract all OSCOLA citations from free text. Resolves to canonical URLs. Disambiguates bare court codes via LLM sampling. |
citations_resolve |
Parse and resolve a single citation string to its canonical URL. |
citations_network |
Fetch a judgment from TNA and map every citation within it — cases, legislation, SIs, EU law. |
Self-contained. No external API. Zero network dependency (except citations_network which fetches the judgment XML).
Supported citation formats:
| Format | Example |
|---|---|
| Neutral citation | [2024] UKSC 12 |
| Law report (with or without volume) | [2024] 1 WLR 100, [1932] AC 562 |
| Legislation section | s.47 Companies Act 2006 |
| Statutory Instrument | SI 2018/1234 |
| Retained EU law | Regulation (EU) 2016/679 |
HMRC
| Tool | What it does |
|---|---|
hmrc_get_vat_rate |
VAT rate lookup for any commodity or service. Static table current as of Autumn Statement 2023. |
hmrc_check_mtd_status |
Check Making Tax Digital VAT mandate status for a VRN. Requires HMRC OAuth credentials. |
hmrc_search_guidance |
Search GOV.UK for HMRC guidance documents. |
hmrc_get_vat_rate and hmrc_search_guidance require no credentials. hmrc_check_mtd_status requires HMRC_CLIENT_ID and HMRC_CLIENT_SECRET — register at developer.service.hmrc.gov.uk. Defaults to sandbox; set HMRC_API_BASE=https://api.service.hmrc.gov.uk for production.
Architecture
src/
gateway.py FastMCP gateway — mounts all modules, applies middleware
deps.py Shared httpx clients (lifespan-managed) + error formatting
modules/
case_law/ TNA Find Case Law (Atom/XML parsing)
legislation/ legislation.gov.uk (CLML XML) + Lex API (JSON)
parliament/ Hansard API + Members API (JSON)
citations/ OSCOLA regex engine (compiled once, lru_cache)
hmrc/ HMRC OAuth + GOV.UK search (JSON)
tests/
test_citations.py 35 unit tests — regex patterns, resolution, disambiguation
Each module is a standalone FastMCP instance mounted into the gateway with a namespace prefix (case_law_, legislation_, etc.). All modules share a single httpx client pool via the gateway's lifespan context.
Middleware stack (gateway level):
| Middleware | Purpose |
|---|---|
RateLimitingMiddleware |
50 req/min per client across all modules |
ResponseLimitingMiddleware |
80,000 char cap (LegalDocML XML can exceed 200k) |
ResponseCachingMiddleware |
Per-module TTLs on case_law (1hr), legislation (24hr), hmrc (90 days) |
Deployment
Fly.io
fly auth login
fly launch --name uk-legal-mcp --region lhr
fly deploy
Optional secrets:
fly secrets set HMRC_CLIENT_ID=your_id HMRC_CLIENT_SECRET=your_secret
# For production HMRC (default is sandbox):
fly secrets set HMRC_API_BASE=https://api.service.hmrc.gov.uk
Docker
docker build -t uk-legal-mcp .
docker run -p 8000:8000 uk-legal-mcp
Testing
pip install -e '.[test]' # or: pip install pytest
pytest tests/test_citations.py -v
All 35 citation tests run offline with no API credentials.
Upstream APIs and Licences
| Source | API | Licence | Auth |
|---|---|---|---|
| TNA Find Case Law | caselaw.nationalarchives.gov.uk |
Open Justice Licence | None |
| legislation.gov.uk | legislation.gov.uk |
OGL v3 | None |
| i.AI Lex API | lex.lab.i.ai.gov.uk |
OGL v3 | None |
| UK Parliament Hansard | hansard-api.parliament.uk |
Open Parliament Licence | None |
| UK Parliament Members | members-api.parliament.uk |
Open Parliament Licence | None |
| HMRC | test-api.service.hmrc.gov.uk |
OGL / commercial terms | OAuth 2.0 |
| GOV.UK Search | www.gov.uk/api/search.json |
OGL v3 | None |
Stack
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file uk_legal_mcp-0.2.0.tar.gz.
File metadata
- Download URL: uk_legal_mcp-0.2.0.tar.gz
- Upload date:
- Size: 41.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf0abdfdb9d153de79c10c6a631cadada80fbc3c2c53cec75691843667fab68d
|
|
| MD5 |
b88ca4a6534e4cc3749cfc79927951bc
|
|
| BLAKE2b-256 |
d4d9ad172b7f49ab9e52db9c71e5facc87dd9d694a0a3df44c1c0c87ed7034f6
|
File details
Details for the file uk_legal_mcp-0.2.0-py3-none-any.whl.
File metadata
- Download URL: uk_legal_mcp-0.2.0-py3-none-any.whl
- Upload date:
- Size: 53.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
870f6bc3b182db025016d4216ce7923fc0aabc2f0be32c40d584c7998b3897e1
|
|
| MD5 |
ee3ba4f181233feea8270a0e666c0788
|
|
| BLAKE2b-256 |
d192c71bb3cb498f1282eec6babdebdba6c320790e6c472e12a47359c8995601
|