UK Legal Research MCP Server
Provides 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.
README
uk-legal-mcp
UK legal research MCP server — case law, legislation, parliament, OSCOLA citations, HMRC tax
Stack: Python 3.12 · FastMCP v3 · Fly.io · Streamable HTTP
Architecture: Gateway + 5 mounted sub-modules (in-process, zero network hop)
Status: Pre-production
What it is
A single MCP server exposing 11 UK legal research tools across five domains. One connection, one endpoint, one authentication context. Built for AI-native legal research workflows.
MCP Client (Claude, etc.)
│
▼
uk-legal-mcp gateway (uk-legal-mcp.fly.dev/mcp)
┌──────────────────────────────────────────────────┐
│ │
│ case_law → TNA Find Case Law API │
│ legislation → legislation.gov.uk + Lex API │
│ parliament → Hansard + Members API │
│ citations ★ → OSCOLA parser (self-contained) │
│ hmrc → HMRC APIs + GOV.UK search │
│ │
└──────────────────────────────────────────────────┘
Tool Reference
Case Law (case_law_*)
| Tool | Description |
|---|---|
case_law_search |
Search UK judgments by keyword, court, judge, party, date range |
case_law_get_judgment |
Retrieve full LegalDocML XML for a judgment by TNA URI |
Upstream: TNA Find Case Law API · Rate limit: 1,000 req/5 min · Cache: 1hr TTL
Legislation (legislation_*)
| Tool | Description |
|---|---|
legislation_search |
Search Acts and SIs via i.AI Lex API (ranked, JSON) |
legislation_get_toc |
Get table of contents for an Act (section numbers + titles) |
legislation_get_section |
Retrieve a specific section with extent, in-force status, version date |
Always surface extent — a section may apply to England & Wales but not Scotland or NI.
Upstream: legislation.gov.uk + i.AI Lex API · Rate limit: 3,000 req/5 min · Cache: 24hr TTL
Parliament (parliament_*)
| Tool | Description |
|---|---|
parliament_search_hansard |
Search Hansard for debates, speeches, questions |
parliament_vibe_check |
Assess parliamentary reception of a policy (uses LLM sampling) |
parliament_find_member |
Look up an MP or Lord by name (returns integer member ID) |
parliament_member_debates |
Retrieve contributions by a specific member |
Upstream: UK Parliament Members API + Hansard API · Cache: not cached (live data)
Citations ★ (citations_*)
The differentiator. No equivalent exists in the UK legal MCP ecosystem.
| Tool | Description |
|---|---|
citations_parse |
Extract all OSCOLA citations from free text. Resolves to URLs. Disambiguates via sampling. |
citations_resolve |
Parse and resolve a single citation string to its canonical URL |
citations_network |
Map all citations within a judgment (cases cited + legislation referenced) |
Supported citation types:
| Type | Example |
|---|---|
| Neutral citation | [2024] UKSC 12 |
| Law report | [2024] 1 WLR 100 |
| Legislation section | s.47 Companies Act 2006 |
| Statutory Instrument | SI 2018/1234 |
| Retained EU law | Regulation (EU) 2016/679 |
No external API. Fully self-contained — zero network dependency.
Ambiguous citations (e.g. bare [2024] EWHC 123) are disambiguated via ctx.sample().
HMRC (hmrc_*)
| Tool | Description |
|---|---|
hmrc_get_vat_rate |
VAT rate for any commodity or service (standard/reduced/zero/exempt) |
hmrc_check_mtd_status |
Check MTD VAT mandate status for a VRN (requires HMRC OAuth) |
hmrc_search_guidance |
Search GOV.UK for HMRC guidance documents |
Cache: VAT rates 90 days, MTD status 24hr
FastMCP Features Used
| Feature | Where |
|---|---|
mount() direct |
Gateway — in-process composition |
namespace= / prefix= |
Gateway — tools as case_law_search, legislation_get_section |
RateLimitingMiddleware |
Gateway — 50 req/min per client |
ResponseLimitingMiddleware |
Gateway — 80,000 char cap (LegalDocML can be 200k+) |
ResponseCachingMiddleware |
case_law, legislation, hmrc — per upstream stability |
@mcp.resource + {param} |
case_law, legislation, citations — stable URI-addressed docs |
@mcp.prompt |
legislation, parliament — reusable research workflows |
Depends() |
All modules (HTTP client), citations (compiled regex) |
ctx.sample() |
parliament_vibe_check, citations_parse (disambiguation) |
readOnlyHint=True |
All tools — entire server is read-only |
Repository Structure
uk-legal-mcp/
├── src/
│ ├── gateway.py # FastMCP gateway — mounts all modules
│ ├── deps.py # Shared httpx clients + error formatting
│ └── modules/
│ ├── case_law/ # TNA Find Case Law
│ │ ├── __init__.py
│ │ ├── tools.py
│ │ ├── resources.py
│ │ └── models.py
│ ├── legislation/ # legislation.gov.uk + i.AI Lex API
│ │ ├── __init__.py
│ │ ├── tools.py
│ │ ├── resources.py
│ │ ├── prompts.py
│ │ └── models.py
│ ├── parliament/ # Hansard + Members API
│ │ ├── __init__.py
│ │ ├── tools.py
│ │ ├── prompts.py
│ │ └── models.py
│ ├── citations/ # OSCOLA parser ★
│ │ ├── __init__.py
│ │ ├── tools.py
│ │ ├── patterns.py # Compiled regex engine (lru_cache)
│ │ └── models.py
│ └── hmrc/ # VAT, MTD, GOV.UK guidance
│ ├── __init__.py
│ ├── tools.py
│ └── models.py
├── tests/
│ └── test_citations.py # Unit tests — citations module (no API needed)
├── pyproject.toml
├── fly.toml
└── Dockerfile
Deployment
Prerequisites
pip install -e .
fly auth login
Environment Variables
fly secrets set HMRC_CLIENT_ID=your_client_id
fly secrets set HMRC_CLIENT_SECRET=your_client_secret
# Optional: TNA computational analysis licence reference
fly secrets set COMPUTATIONAL_ANALYSIS=your_tna_licence_ref
Deploy
fly launch --name uk-legal-mcp --region lhr
fly deploy
Local Development
# Install dependencies
pip install -e .
# Run locally
python -m src.gateway
# Test with MCP Inspector
npx @modelcontextprotocol/inspector http://localhost:8000/mcp
Testing
# Run citations unit tests (no API or credentials needed)
pytest tests/test_citations.py -v
# Syntax check all modules
python -m py_compile src/gateway.py
python -m py_compile src/modules/citations/tools.py
python -m py_compile src/modules/citations/patterns.py
Open Questions
- [ ] TNA Computational Analysis Licence — apply before bulk judgment fetching; required for large-scale programmatic access
- [ ] Lex API rate limits — undocumented; measure empirically during early build. Treat as 60 req/min until confirmed.
- [ ] OSCOLA court code enumeration — compile complete list of UKFTT divisions and UKUT chamber codes for patterns.py
- [ ]
citations_networkcross-ref data — TNA may not expose outbound citation links via API. BAILII scrape may be needed as fallback; evaluate during integration testing. - [ ]
ctx.sample()in production — confirm Claude client implements sampling handler. parliament_vibe_check and citations_parse both degrade gracefully if sampling is unavailable. - [ ] Lex API JSON schema — undocumented; verify response field names against live API before shipping legislation_search.
- [ ] HMRC MTD endpoint scope — current implementation uses
read:vatscope; verify this covers obligations lookup or ifwrite:vatis also needed.
Licences
| Source | Licence | Notes |
|---|---|---|
| TNA Find Case Law | Open Justice Licence | Computational analysis requires separate application |
| legislation.gov.uk | Open Government Licence v3 | Attribution required |
| Hansard | Open Parliament Licence | Attribution required |
| HMRC APIs | OGL / commercial terms vary | Sandbox vs production environments differ |
Build Order (from spec)
citations— no external API, pure Python, highest differentiating value. EstablishesDepends()andctx.sample()patterns.case_law— TNA API is well-documented. Establishes resource template + XML parsing layer.legislation— builds on case_law patterns. Adds Lex API JSON path +@mcp.prompt.parliament— adds sampling-based sentiment analysis.hmrc— simplest module, JSON tools with TTL caching.- Gateway — wire up mounts, middleware, integration test.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。