Skip to content

Environment & Configuration

This page covers all configuration files, environment variables, storage keys, install paths, and dependencies used by the AI Legal Assistant.


MCP Server Configuration (.mcp.json)

The root .mcp.json file registers three MCP servers that provide live legal data to skills:

json
{
  "mcpServers": {
    "uk-legislation": {
      "command": "npx",
      "args": ["tsx", "mcp-servers/uk-legislation/src/index.ts"]
    },
    "caselaw": {
      "command": "npx",
      "args": ["tsx", "mcp-servers/caselaw/src/index.ts"]
    },
    "lex": {
      "type": "http",
      "url": "https://lex.lab.i.ai.gov.uk/mcp"
    }
  }
}
ServerTypeDescriptionTools Provided
uk-legislationLocal (stdio)Runs locally via npx tsx. Queries the legislation.gov.uk XML APIsearch_legislation, lookup_statute, lookup_section, check_in_force, check_amendments, get_extent
caselawLocal (stdio)Runs locally via npx tsx. Queries the National Archives' Find Case Law servicesearch_caselaw, get_recent_judgments, search_by_party, search_by_judge, lookup_judgment, get_judgments_for_section, download_judgment_pdf, extract_judgment_text, summarise_judgment
lexRemote (HTTP)Connects to the LAI Government lex server63,000+ court cases, semantic legal search

TIP

The local uk-legislation server requires no configuration beyond having the project cloned and npm install run in mcp-servers/uk-legislation/. It queries the public legislation.gov.uk API directly with no API key required (Open Government Licence v3.0).


Dashboard Environment Variables

The dashboard runs with zero required environment variables in demo mode. For hosted trial, live analysis, OCR, and audio features, the following server-side environment variables apply.

Hosted Trial Configuration

VariableAliasDescriptionDefault
AI_LEGAL_UK_HOSTED_ANTHROPIC_API_KEY--Server-side Anthropic key for signed-in hosted analysis requests--
AI_LEGAL_UK_HOSTED_OPENAI_API_KEY--Server-side OpenAI key for signed-in hosted analysis and OCR requests--
AI_LEGAL_UK_HOSTED_GEMINI_TTS_API_KEY--Preferred server-side Gemini key for hosted caselaw audio--
AI_LEGAL_UK_HOSTED_ENABLED--Set to false to pause hosted trial requests globallytrue
AI_LEGAL_UK_HOSTED_MONTHLY_LIMIT--Global monthly hosted request capapp default
AI_LEGAL_UK_HOSTED_MONTHLY_LIMIT_USD--Global monthly estimated-spend capapp default
ANALYSIS_MODEL--Anthropic model override for analysis routesapp default
OPENAI_ANALYSIS_MODEL--OpenAI model override for analysis routesapp default

Signed-in hosted users are still subject to per-user, per-device/network, monthly, and company-scope quota checks. Companies can be given higher pilot limits from the /ops quota controls. Users who need heavier usage can add their own Anthropic or OpenAI key in Settings; browser keys are stored only in that browser's local storage and are not persisted by the server.

OCR Configuration

VariableAliasDescriptionDefault
OCR_PROVIDERAI_LEGAL_UK_OCR_PROVIDEROCR provider for scanned PDF processing--
AI_LEGAL_UK_HOSTED_OPENAI_API_KEY--Preferred OpenAI key for hosted OCR and hosted analysis--
OPENAI_API_KEY--Legacy OpenAI OCR fallback when a hosted key is not configured--
OCR_OPENAI_MODEL--OpenAI model to use for OCR requestsgpt-4o

Only OpenAI OCR is Implemented

The OCR system recognises five provider values but only openai has a working implementation. The other four are recognised but will fail at runtime.

Supported OCR Providers

Provider ValueStatusRequirements
openaiImplementedAI_LEGAL_UK_HOSTED_OPENAI_API_KEY or OPENAI_API_KEY must be set. Uses OpenAI vision API for scanned PDF text extraction
googleStub onlyRecognised but not implemented; will fail at runtime
awsStub onlyRecognised but not implemented; will fail at runtime
azureStub onlyRecognised but not implemented; will fail at runtime
tesseractStub onlyRecognised but not implemented; will fail at runtime

Next.js Standard Variables

VariableDefaultDescription
PORT3000Port for the development server
NODE_ENVdevelopmentNode environment (development, production, test)

Example: Setting OCR Variables

bash
# For development with OCR support
export OCR_PROVIDER=openai
export AI_LEGAL_UK_HOSTED_OPENAI_API_KEY=sk-your-openai-key-here
export OCR_OPENAI_MODEL=gpt-4o

# Then start the dashboard
cd dashboard && npm run dev

API Key Handling

Security Model

The dashboard has two live paths. Hosted trial requests use server-side AI_LEGAL_UK_HOSTED_* keys only after authentication and quota checks. User-supplied provider keys remain browser-local: the browser stores them in localStorage, sends them with the request that needs them, and the server does not persist them.

How API Keys Flow

Hosted trial  -->  Clerk session  -->  quota gate  -->  hosted env key  -->  Provider adapter
Own key       -->  localStorage   -->  request body  ------------------>  Provider adapter

Hosted trial requests are logged to usage_events for quota and budget protection; document text and browser API keys are not stored there. When a user adds their own key in Settings, it is stored under ai-legal-uk-api-key in that browser only and sent in the JSON request body for the relevant call.

API Key Validation

Settings accepts Anthropic keys beginning sk-ant- and OpenAI keys beginning sk-. Google AI Studio keys beginning AIza are stored separately for Gemini audio and are not accepted for legal analysis. The legacy /api/anthropic/validate route still performs an Anthropic-only provider ping; new hosted-trial routes rely on provider-prefix detection plus server-side provider errors.

Validation Constants

Defined in dashboard/lib/api-route-utils.ts:

ConstantValueDescription
MAX_LIVE_DOCUMENT_CHARS50,000Maximum character count for uploaded documents
ANTHROPIC_VALIDATE_URLhttps://api.anthropic.com/v1/messagesEndpoint for API key validation
ANTHROPIC_VALIDATE_MODELDefault claude-sonnet-4-20250514 (override with ANALYSIS_MODEL env var)Model used for Anthropic key validation and live analysis

Browser localStorage Keys

The dashboard stores all client-side state in the browser's localStorage:

KeyTypeDescriptionExample Value
ai-legal-uk-modestringCurrent operating mode"demo" or "live"
ai-legal-uk-reviewsJSON arrayArray of saved review result objects (full analysis data)[{ id: "...", type: "contract", score: 72, ... }]
ai-legal-uk-api-keystringUser's provider API key (for live mode only)"sk-..."

Demo Mode

In demo mode (ai-legal-uk-mode = "demo"), no API key is needed. The dashboard uses fixture data from dashboard/lib/demo-data/ to simulate analysis results with zero API cost.

localStorage Data Lifecycle

Mode (ai-legal-uk-mode): Set when the user toggles between demo and live mode via the UI. Defaults to "demo" if not set.

Reviews (ai-legal-uk-reviews): Updated after each completed analysis. Contains the full review data including scores, clauses, recommendations, and metadata. Reviews persist across browser sessions until manually cleared from the History page.

API Key (ai-legal-uk-api-key): Set when the user enters their provider API key in Settings. Sent with each live-mode API request in the request body. Never transmitted to any server other than the selected provider API. Clearing browser storage removes the key.


Installation Paths

When ./install.sh is run, files are copied to these locations under the user's home directory:

Source DirectoryDestinationContents
legal/SKILL.md~/.claude/skills/legal/SKILL.mdMain orchestrator / router (command menu + routing table)
skills/legal-*/SKILL.mdconfigured agent-host skills directoryAll 38 individual skill files (3 orchestrators + 35 single-agent / utility)
agents/legal-*.mdconfigured agent-host agents directoryAll 12 agent files
scripts/generate_legal_pdf.py~/.claude/skills/legal/scripts/generate_legal_pdf.pyPDF report generator
templates/~/.claude/skills/legal/templates/Report templates

Directory Structure After Installation

~/.claude/
  skills/
    legal/
      SKILL.md                    # Main router (35 commands)
      scripts/
        generate_legal_pdf.py     # PDF report generator
      templates/
        ...                       # Report templates
    legal-review/
      SKILL.md                    # Flagship contract review (5-agent orchestrator)
    legal-employment/
      SKILL.md                    # Employment review (4-agent orchestrator)
    legal-corporate/
      SKILL.md                    # Corporate review (3-agent orchestrator)
    legal-risks/
      SKILL.md
    legal-compare/
      SKILL.md
    ... (38 skill directories total)
  agents/
    legal-clauses.md              # Contract review: clause analysis (20%)
    legal-risks.md                # Contract review: risk assessment (25%)
    legal-compliance.md           # Contract review: compliance check (20%)
    legal-terms.md                # Contract review: terms & obligations (15%)
    legal-recommendations.md      # Contract review: recommendations (20%)
    legal-employment-contract.md  # Employment: contract terms (25%)
    legal-employment-rights.md    # Employment: statutory rights (25%)
    legal-employment-discrimination.md  # Employment: Equality Act (25%)
    legal-employment-obligations.md     # Employment: obligations (25%)
    legal-corporate-compliance.md # Corporate: CA 2006 / ECCTA (35%)
    legal-corporate-documents.md  # Corporate: document review (35%)
    legal-corporate-risk.md       # Corporate: risk assessment (30%)

Project Source Paths

PathContents
skills/legal-*/SKILL.mdSource skill files (38 skills)
agents/legal-*.mdSource agent files (12 agents)
legal/SKILL.mdSource orchestrator / router
dashboard/Web application source
mcp-servers/uk-legislation/MCP server source
scripts/Utility scripts (PDF generator, etc.)
samples/Sample legal documents
templates/Report templates

Installation Commands

bash
# Install from local clone
./install.sh

# Install via curl (clones from GitHub automatically)
curl -fsSL https://raw.githubusercontent.com/davendra/ai-legal-uk/main/install.sh | bash

# Uninstall (removes all installed files from ~/.claude/)
./uninstall.sh

Python Dependencies

The PDF report generator (/legal report-pdf) requires Python 3.8+ and the reportlab library:

bash
pip3 install reportlab
DependencyMinimum VersionPurpose
Python3.8+Runtime for generate_legal_pdf.py
reportlabAny recentPDF generation with A4 layout, score gauges, risk charts, colour-coded tables, prioritised action checklists

INFO

reportlab is only required for the /legal report-pdf command. The remaining command skills are pure Markdown and have no Python dependencies.


Dashboard Dependencies

The dashboard's Node.js dependencies are managed via package.json in the dashboard/ directory:

bash
cd dashboard
npm install

Key Packages

PackagePurpose
nextNext.js 14 App Router framework
react, react-domReact 18 UI library
@anthropic-ai/sdkAnthropic API client for live analysis
@radix-ui/*Accessible headless UI primitives
tailwindcssUtility-first CSS framework
typescriptType checking and compilation
fast-xml-parserXML parsing for legislation API responses
lucide-reactIcon library
next-themesDark/light theme support
tailwind-merge, clsxCSS utility for conditional class merging

MCP Server Dependencies

The MCP server has its own package.json in mcp-servers/uk-legislation/:

bash
cd mcp-servers/uk-legislation
npm install
PackagePurpose
@modelcontextprotocol/sdkMCP server framework
fast-xml-parserParsing legislation.gov.uk XML responses
zodInput validation schemas for tool parameters
tsxTypeScript execution in development mode
typescriptCompilation for production build

MCP Server Internal Constants

Defined in mcp-servers/uk-legislation/src/index.ts:

ConstantValueDescription
BASE_URLhttps://www.legislation.gov.uklegislation.gov.uk API base URL
CACHE_TTL_MS86,400,000 (24 hours)In-memory cache time-to-live
CACHE_MAX_ENTRIES500Maximum cache entries before LRU eviction
FETCH_TIMEOUT_MS30,000 (30 seconds)HTTP fetch timeout with AbortController

INFO

The MCP server has no external API key requirements -- it queries the public legislation.gov.uk XML API directly under the Open Government Licence v3.0.

AI Legal UK · The Counsel — Established MMXXVI · Built for England & Wales · Not legal advice.