Lex

Lex

Provides programmatic access to UK legal documents with hybrid semantic search and Model Context Protocol integration for AI assistants.

Category
Visit Server

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.

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured