Legal Document RAG MCP Server

Legal Document RAG MCP Server

Enables semantic and keyword search over legal documents, conflict detection, and document overview, supporting Indonesian and English texts.

Category
Visit Server

README

Legal Document RAG — MCP Server

Fully local, offline RAG system for legal documents (Indonesian + English).
Built on MCP SDK, ChromaDB, SQLite FTS5, and multilingual-e5-large.


Requirements

  • Python ≥ 3.11
  • Tesseract OCR with Indonesian language pack:
    # Ubuntu / Debian
    sudo apt install tesseract-ocr tesseract-ocr-ind
    
    # macOS
    brew install tesseract
    brew install tesseract-lang  # includes ind
    

Setup

# 1. Clone / copy the project
cd legal_rag_mcp

# 2. Create virtual environment
python -m venv .venv
source .venv/bin/activate   # Windows: .venv\Scripts\activate

# 3. Install dependencies
pip install -r requirements.txt

# 4. (First run) The multilingual-e5-large model (~2.2 GB) will be
#    downloaded automatically to ~/.cache/huggingface/hub
#    All subsequent runs are fully offline.

Usage

Drop documents in the watch folder

legal_rag_mcp/raw_legal_docs/
├── kontrak_jual_beli.pdf
├── perjanjian_kerjasama.docx
├── schedule_of_fees.xlsx
└── scanned_addendum.png

Launch the MCP server

# Development mode (with MCP Inspector UI)
mcp dev mcp_server/server.py

# Production mode (stdio, for Claude Desktop or any MCP client)
python mcp_server/server.py

Claude Desktop configuration (claude_desktop_config.json)

{
  "mcpServers": {
    "legal-rag": {
      "command": "python",
      "args": ["/absolute/path/to/legal_rag_mcp/mcp_server/server.py"]
    }
  }
}

Tools Exposed

Tool Purpose
search_clauses Hybrid semantic + keyword search
find_conflicts Cross-document conflict detection (two-zone thresholds)
get_document_overview Document metadata + clause outline
retrieve_context Read a clause in full surrounding context
list_documents Inventory of all ingested files

Conflict Detection Thresholds

Zone Cosine Similarity Interpretation
Near-duplicate > 0.88 Same clause — skip
HIGH suspicion 0.75 – 0.88 Same topic, different obligations
MODERATE suspicion 0.60 – 0.75 Related topic, may diverge
Unrelated < 0.60 Different provisions

Thresholds are configurable in config.py.


Re-ingestion (Diff-Based)

When a file in raw_legal_docs/ is modified:

  1. File-level SHA-256 hash is compared against the stored hash.
  2. If unchanged → skip entirely.
  3. If changed → re-chunk the document, compute per-chunk hashes.
  4. Only changed or new chunks are re-embedded and upserted.
  5. Orphaned chunks (present in old version, absent in new) are deleted.
  6. Full re-embedding is never triggered by a partial change.

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