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 two MCP servers that provide live legal data to skills:

json
{
  "mcpServers": {
    "uk-legislation": {
      "command": "npx",
      "args": ["tsx", "mcp-servers/uk-legislation/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
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 live analysis and OCR features, the following server-side environment variables apply.

OCR Configuration

VariableAliasDescriptionDefault
OCR_PROVIDERAI_LEGAL_UK_OCR_PROVIDEROCR provider for scanned PDF processing--
OPENAI_API_KEY--OpenAI API key (used for OCR only, not for analysis)--
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
openaiImplementedOPENAI_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 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 server does not hold or store provider API keys. The user provides their own supported provider key via the browser UI. The key is stored in browser localStorage and sent in the request body of each API call. Route handlers pass it directly to the selected provider adapter without persisting it.

How API Keys Flow

Browser (localStorage)  -->  Request Body  -->  Route Handler  -->  Provider adapter
                                                    |
                                             (never stored,
                                              never logged)
  1. User enters their provider API key in the browser UI
  2. Key is stored in localStorage under ai-legal-uk-api-key
  3. Each API request includes the key in the JSON request body ({ apiKey: "sk-..." })
  4. Server-side route handler extracts the key and passes it to the selected provider adapter
  5. Key is never logged, stored on disk, or cached server-side

API Key Validation

The dashboard validates API keys by making a minimal test request:

POST https://api.anthropic.com/v1/messages
Model: ANALYSIS_MODEL (default `claude-sonnet-4-20250514`, override via env)
Max tokens: 16
Message: "Reply with only: OK"

Keys must:

  • Be a non-empty string
  • Start with sk-
  • Pass the validation request above

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.