Sandbox
@i-dot-ai/lex

UK legal API and MCP server for agent search

Lex provides programmatic access to UK legal documents, including legislation, amendments, explanatory notes, and search over large legal datasets. It is built as a FastAPI service with MCP integration so agents can query legal sources directly.

69 stars33 forksPythonUpdated 7d ago
Who it's for

Builders who want Claude Code, Cursor, or Copilot to search UK legal material.

What it delivers

You can ground agent work in official UK legal data instead of pasting legal text by hand.

What it does

Hybrid legal search

Search legislation and related documents with semantic and keyword matching.

MCP integration

Connect Claude Desktop, Claude Code, Cursor, and Copilot tools to the API through Model Context Protocol.

Large legal dataset

Work with legislation, amendments, explanatory notes, and case law coverage described in the README.

Ingestion and maintenance scripts

Use scripts for loading sample or full datasets, backfilling summaries, exporting data, and creating indexes.

Deployment and operations docs

Follow the repo's architecture, deployment, runbook, and troubleshooting guides.

How to get it

  1. 1Run
    make install          # Install dependencies
    make test             # Run tests
    make run              # Start API locally (without Docker)
    uv run ruff format .  # Format code
  2. 2Run
    lex/
    ├── src/
    │   ├── lex/              # Data pipeline (scraping, parsing, indexing)
    │   └── backend/          # API server (FastAPI + MCP)
    ├── infrastructure/       # Azure Bicep templates and deploy scripts
    ├── scripts/              # Maintenance, migration, and export utilities
    ├── tests/                # Test suite
    └── docs/                 # Documentation

README

Lex

UK legal API for AI agents and researchers. Access comprehensive UK legislation data with semantic search and Model Context Protocol integration.

Python 3.12+ License

What is Lex?

Lex provides programmatic access to 8.4M+ UK legal documents - legislation, amendments, and explanatory notes - with hybrid semantic search.

This is an experimental service and should not be used as a production dependency.

Dataset Coverage

  • Legislation - 220K Acts and Statutory Instruments (1267-present, complete from 1963)
  • Amendments - 892K legislative changes and modifications
  • Explanatory Notes - 89K notes providing legislative context
  • Case Law - 70K judgments and 4.7M paragraphs (temporarily disabled pending TNA licence)
  • PDF Digitisation - Historical legislation (pre-1963) digitised using AI

What Can You Build?

  • Legal Research - Find relevant legislation in seconds
  • Policy Analysis - Track legislative changes over time
  • AI Grounding - Ground AI assistants in authoritative UK legal sources

MCP Integration

Connect AI assistants to Lex via Model Context Protocol. See the live documentation for setup instructions for:

  • Claude Desktop
  • Claude Code
  • Cursor
  • Microsoft Copilot Studio
  • VS Code + GitHub Copilot

Local Development

Prerequisites

  • Python 3.12+
  • uv
  • Docker & Docker Compose
  • Azure OpenAI credentials

Quick Start

# Clone and setup
git clone https://github.com/i-dot-ai/lex.git && cd lex
cp .env.example .env  # Add your Azure OpenAI keys

# Start services and load sample data
docker compose up -d
make ingest-all-sample

# Visit http://localhost:8000/docs for API documentation

Data Loading

# Quick samples (recommended for testing)
make ingest-legislation-sample
make ingest-all-sample

# Full datasets (production use)
make ingest-legislation-full
make ingest-all-full

# Create indexes for fast filtering
uv run python scripts/create_payload_indexes.py

Development Commands

make install          # Install dependencies
make test             # Run tests
make run              # Start API locally (without Docker)
uv run ruff format .  # Format code

Architecture

lex/
├── src/
│   ├── lex/              # Data pipeline (scraping, parsing, indexing)
│   └── backend/          # API server (FastAPI + MCP)
├── infrastructure/       # Azure Bicep templates and deploy scripts
├── scripts/              # Maintenance, migration, and export utilities
├── tests/                # Test suite
└── docs/                 # Documentation

Documentation

Acknowledgements

Built with support from The National Archives and Ministry of Justice.

License

MIT - See LICENSE for details.

Files in the repo

Repository payload24 top-level entries
  • .claude
  • .claude-plugin
  • .github
  • app
  • data
  • docs
  • infrastructure
  • scripts
  • skills
  • src
  • tests
  • .dockerignore
  • .env.example
  • .gitignore
  • .mcp.json
  • .pre-commit-config.yaml
  • .python-version
  • CONTRIBUTING.md
  • docker-compose.yaml
  • LICENSE
  • Makefile
  • pyproject.toml
  • README.md
  • uv.lock

Discussion (0)

Ask about usage, or say what you built with it

Sign in to join the discussion.

No comments yet. Be the first to say what this is good for.

More connectors

Real-time global intelligence dashboard. AI-powered news aggregation, geopolitical monitoring, and infrastructure tracking in a unified situational awareness interface

86k

High-performance code intelligence MCP server. Indexes codebases into a persistent knowledge graph — average repo in milliseconds. 158 languages, sub-ms queries, 99% fewer tokens. Single static binary, zero dependencies.

43k

Universal provider proxy for OpenAI Codex & Claude Code — use any LLM (Claude, Gemini, Grok, DeepSeek, Ollama…) with Codex CLI, App, SDK, and Claude Code

14k
okf-memory/
okf-agent-memory

Git-native persistent memory for AI coding agents. Implements Google OKF v0.2 with sub-300µs in-memory BM25 search, embedded MCP server, and progressive disclosure. Slashes token bloat by 80% with zero external databases or dependencies. Built in pure Go.

547
tirth8205/
code-review-graph

Local-first code intelligence graph for MCP and CLI. Builds a persistent map of your codebase so AI coding tools read only what matters, with benchmarked context reductions on reviews and large-repo workflows.

31k
2akouwu/
reverify

Stop your AI from making things up — it proposes, deterministic tools decide, every claim checked against ground truth with evidence. Grounded facts and context survive resets. Reverse engineering is the proving ground. MCP server + CLI.

1.1k