LegalContext
by protomated
LegalContext is an open-source Model Context Protocol (MCP) server that creates a secure bridge between a law firm's Clio document management system and Claude Desktop AI assistant. It allows efficient document retrieval while maintaining data security and client confidentiality.
Last updated: N/A
LegalContext
LegalContext is an open-source Model Context Protocol (MCP) server that creates a secure bridge between a law firm's Clio document management system and Claude Desktop AI assistant.
Features
- Secure Document Access: Connects to Clio API to access legal documents while maintaining security
- Local Processing: All document processing happens locally within the firm's infrastructure
- MCP Integration: Implements the Model Context Protocol for seamless integration with Claude Desktop
- Vector Search: Uses LanceDB for efficient document retrieval based on semantic similarity
- Free Tier Limitations: Includes built-in limits for the free version (100 documents, 50 queries/day)
About LegalContext
LegalContext addresses a critical challenge in legal practice: efficiently finding and leveraging information within your document management system while maintaining the highest standards of data security and client confidentiality.
For a comprehensive overview of how LegalContext can transform your legal practice, solve search frustrations, and protect against AI hallucinations, please read our detailed white paper.
The white paper covers:
- How LegalContext addresses the crisis of information retrieval in legal practice
- Why traditional search methods fail for legal documents
- How our local-first approach protects client confidentiality
- Real-world use cases and implementation examples
- Detailed technical architecture and security model
Table of Contents
- Prerequisites
- Installation
- Docker Deployment (Firmwide)
- Clio Setup
- Usage
- Security Considerations
- Limitations (Free Tier)
- Contributing
- License
Prerequisites
- Bun: Version 1.0 or later (JavaScript runtime and package manager)
- Clio: A Clio account with API access and registered application credentials
- Claude Desktop: Anthropic's Claude Desktop application
- Operating System: macOS, Linux, or Windows with WSL
Automated Setup (Local)
macOS Setup
-
Install Bun
curl -fsSL https://bun.sh/install | bash
After installation, you may need to close and reopen your terminal, or run:
source ~/.bashrc # if using bash source ~/.zshrc # if using zsh
-
Clone the Repository
git clone https://github.com/yourusername/legalcontext-mcp-server.git cd legalcontext-mcp-server
-
Install Dependencies
bun install
-
Configure Environment Variables
cp .env.example .env
Edit the
.env
file using your preferred text editor and set the required variables:nano .env # or use any other text editor
Ensure you set the following variables:
CLIO_CLIENT_ID
: Your Clio application's Client IDCLIO_CLIENT_SECRET
: Your Clio application's Client SecretCLIO_REDIRECT_URI
: The callback URL registered in your Clio app settingsCLIO_API_REGION
: The region of your Clio account ('us', 'eu', 'ca', 'au')LANCEDB_DB_PATH
: Local filesystem path to store the LanceDB database files (e.g.,./lancedb
)
-
Start the Server
bun run src/server.ts
-
Configure Claude Desktop
Create or edit the Claude Desktop configuration file:
nano ~/.config/Claude-Desktop/claude_desktop_config.json
Add LegalContext as an MCP server:
{ "mcpServers": [ { "name": "LegalContext", "command": "/Users/YOUR_USERNAME/.bun/bin/bun", "args": ["/Users/YOUR_USERNAME/path/to/legalcontext-mcp-server/src/server.ts"] } ] }
Replace
/Users/YOUR_USERNAME/
with your actual home directory path.Restart Claude Desktop for the changes to take effect.
Windows Setup
-
Install Bun
Install Windows Subsystem for Linux (WSL) if you haven't already:
wsl --install
After WSL is installed, open a WSL terminal and install Bun:
curl -fsSL https://bun.sh/install | bash
Close and reopen your WSL terminal, or run:
source ~/.bashrc
-
Clone the Repository
git clone https://github.com/yourusername/legalcontext-mcp-server.git cd legalcontext-mcp-server
-
Install Dependencies
bun install
-
Configure Environment Variables
cp .env.example .env
Edit the
.env
file:nano .env
Configure the required variables as described in the macOS section.
-
Start the Server
bun run src/server.ts
-
Configure Claude Desktop
Create or edit the Claude Desktop configuration file at this location:
C:\Users\YOUR_USERNAME\AppData\Roaming\Claude-Desktop\claude_desktop_config.json
Add LegalContext as an MCP server:
{ "mcpServers": [ { "name": "LegalContext", "command": "wsl", "args": ["~/.bun/bin/bun", "~/path/to/legalcontext-mcp-server/src/server.ts"] } ] }
Replace
~/path/to/
with your actual WSL path to the project.Restart Claude Desktop for the changes to take effect.
Docker Deployment (Firmwide)
LegalContext can be deployed using Docker for a more standardized, firmwide setup. This approach simplifies deployment across different environments and ensures consistent behavior.
Need help? Email the Protomated team for deployment assistance or custom features/configurations for your firm's specific needs.
Prerequisites
- Docker installed on the host machine
- Docker Compose (optional, for more complex setups)
- Network access to Clio API
- Clio API credentials
Basic Docker Deployment
-
Build the Docker Image
docker build -t legalcontext-mcp-server:latest .
-
Create a docker-compose.yml File
version: '3' services: legalcontext: image: legalcontext-mcp-server:latest container_name: legalcontext restart: unless-stopped volumes: - ./lancedb:/app/lancedb # Persist vector database - ./config:/app/config # Store configuration and tokens environment: - NODE_ENV=production - LOG_LEVEL=info - CLIO_CLIENT_ID=${CLIO_CLIENT_ID} - CLIO_CLIENT_SECRET=${CLIO_CLIENT_SECRET} - CLIO_REDIRECT_URI=${CLIO_REDIRECT_URI} - CLIO_API_REGION=${CLIO_API_REGION} - LANCEDB_DB_PATH=/app/lancedb - MAX_DOCUMENTS=100 - MAX_QUERIES_PER_DAY=50 ports: - "3001:3001" # Expose HTTP port if needed
-
Create an Environment Variables File
Create a
.env
file in the same directory as yourdocker-compose.yml
:CLIO_CLIENT_ID=your_client_id CLIO_CLIENT_SECRET=your_client_secret CLIO_REDIRECT_URI=https://your-server-address/auth/clio/callback CLIO_API_REGION=us
-
Start the Container
docker-compose up -d
Advanced Firmwide Deployment
For any firm seeking advanced deployments, consider these additional steps:
-
Authentication and Security
- Use a reverse proxy (like Nginx or Traefik) to handle HTTPS termination
- Implement IP-based access controls to restrict access to the server
- Consider integration with the firm's identity provider (e.g., Azure AD, Okta) for authentication
-
High Availability Setup
- Deploy multiple instances behind a load balancer
- Use shared storage (e.g., NFS, S3) for the vector database to enable scaling
- Implement health checks and automatic container restart
-
Monitoring and Logging
version: '3' services: legalcontext: # ... basic config as above logging: driver: "json-file" options: max-size: "10m" max-file: "3" # Add these if using Prometheus monitoring labels: - "prometheus.scrape=true" - "prometheus.port=3001" - "prometheus.path=/metrics"
-
Using Docker Secrets for Sensitive Information
version: '3.8' services: legalcontext: # ... other configuration secrets: - clio_client_id - clio_client_secret environment: - CLIO_CLIENT_ID_FILE=/run/secrets/clio_client_id - CLIO_CLIENT_SECRET_FILE=/run/secrets/clio_client_secret # ... other environment variables secrets: clio_client_id: file: ./secrets/clio_client_id.txt clio_client_secret: file: ./secrets/clio_client_secret.txt
-
Integration with Claude Desktop
For firmwide deployments, instead of having each user configure Claude Desktop manually, consider:
- Creating a standard Claude Desktop configuration package for distribution
- Using a centralized network service for MCP communication instead of stdio
- Developing a simple configuration utility that sets up the proper paths for each user
Example centralized configuration script:
#!/bin/bash # Script to configure Claude Desktop for LegalContext # Create config directory if it doesn't exist mkdir -p ~/.config/Claude-Desktop # Generate the config file with the correct server address cat > ~/.config/Claude-Desktop/claude_desktop_config.json << EOF { "mcpServers": [ { "name": "LegalContext (Firm)", "url": "http://legalcontext.internal.example.com:3001" } ] } EOF echo "Claude Desktop configured successfully."
Updating the Docker Deployment
# Pull the latest code
git pull
# Rebuild the Docker image
docker-compose build
# Restart the service
docker-compose down
docker-compose up -d
# View logs
docker-compose logs -f
Backing Up the Vector Database
# Stop the container
docker-compose stop legalcontext
# Back up the vector database
tar -czf lancedb-backup-$(date +%Y%m%d).tar.gz ./lancedb
# Restart the container
docker-compose start legalcontext
Clio Setup
Creating a Clio API Application
- Visit Clio Developers Portal (or your region-specific Clio instance)
- Click "New Application"
- Enter required information:
- Name: "LegalContext"
- Redirect URI: http://localhost:3001/auth/clio/callback (for local development)
- Scopes: documents, folders (minimum required)
- Save the application and note your Client ID and Client Secret
Usage
Authenticating with Clio
- Start the LegalContext server
- Visit http://localhost:3001/auth/clio in your browser
- Follow the OAuth flow to authorize LegalContext with your Clio account
Indexing Documents
Run the document indexing process to pull and index Clio documents:
bun run src/scripts/index.ts
This process:
- Fetches documents from Clio (up to 100 for free tier)
- Downloads document content
- Extracts text from PDFs and DOCXs
- Generates vector embeddings
- Stores embeddings in the local LanceDB database
Using with Claude Desktop
- Start Claude Desktop
- Verify LegalContext appears in the available tools list
- Ask legal questions that require access to your documents
- Claude will automatically use LegalContext to retrieve relevant context from your documents
Example queries:
- "What are the key provisions in our standard NDA?"
- "Summarize the legal implications in the Johnson case documents."
- "What arguments were made in our most recent motion for summary judgment?"
Security Considerations
- Data Boundary Control: All document processing happens locally. Sensitive content never leaves your infrastructure during processing.
- Authentication: OAuth 2.0 authentication with Clio protects document access.
- Token Security: Access tokens are stored securely with encryption.
- Transparency: Open-source codebase allows security review by your team.
Limitations (Free Tier)
- Maximum of 100 indexed documents
- 50 queries per day limit
- Manual or scheduled batch indexing only (no real-time)
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the Mozilla Public License 2.0 - see the LICENSE file for details.