Legal Contract Review Agent

Legal Contract Review Agent

An AI-powered MCP server for analyzing Japanese legal contracts and identifying risks through a RAG-enhanced workflow. It enables clients to search legal knowledge, analyze clause risks, and generate automated contract review reports.

Category
Visit Server

README

Legal Contract Review Agent

AI-powered Japanese legal contract review agent system built with LangGraph, RAG, MCP, and Tool Calling.

中文文档 | 日本語ドキュメント

Demo

Demo Screenshot

Architecture

┌─────────────┐    ┌──────────────────────────────────────────┐
│  React UI   │───▶│  FastAPI Backend                         │
└─────────────┘    │                                          │
                   │  LangGraph Agent Workflow:                │
┌─────────────┐    │  parse_contract → retrieve_knowledge     │
│ Claude       │    │  → analyze_risks → generate_report      │
│ Desktop     │───▶│                                          │
│ (MCP Client)│    │  Tools: search_legal_knowledge           │
└─────────────┘    │         analyze_clause_risk              │
                   │         generate_suggestion              │
                   │                                          │
                   │  RAG: ChromaDB + OpenAI Embeddings       │
                   └──────────────────────────────────────────┘

Tech Stack

  • LLM: OpenAI GPT-4o
  • Agent Framework: LangGraph (StateGraph)
  • RAG: ChromaDB + text-embedding-3-small
  • MCP: FastMCP (Python)
  • Backend: FastAPI
  • Frontend: React + Vite + TypeScript
  • Deployment: Docker Compose

Quick Start

Prerequisites

  • Docker & Docker Compose
  • OpenAI API Key

Setup & Run

cd legal-contract-agent

# Create .env from template and add your OpenAI API Key
cp .env.example .env
# Edit .env: OPENAI_API_KEY=sk-your-key-here

# Build and start all services
docker compose up --build

Open http://localhost:5173 — paste a Japanese contract and click "契約書を審査する".

To stop:

docker compose down        # Stop containers
docker compose down -v     # Stop and remove data volumes

Run Without Docker (Alternative)

# Install Python dependencies
pip install .

# Install frontend dependencies
cd frontend && npm install && cd ..

# Terminal 1: Start backend
uvicorn backend.main:app --reload

# Terminal 2: Start frontend
cd frontend && npm run dev

MCP Server (for Claude Desktop)

python -m backend.mcp.server

Add to Claude Desktop config:

{
  "mcpServers": {
    "legal-review": {
      "command": "python",
      "args": ["-m", "backend.mcp.server"],
      "cwd": "/path/to/legal-contract-agent"
    }
  }
}

Project Structure

backend/
├── main.py              # FastAPI entry point
├── Dockerfile           # Backend container image
├── agent/
│   ├── graph.py         # LangGraph workflow
│   ├── nodes.py         # Agent node functions
│   ├── state.py         # Agent state definition
│   └── tools.py         # LangChain tools
├── rag/
│   ├── store.py         # ChromaDB vector store
│   └── loader.py        # Knowledge loader
├── mcp/
│   └── server.py        # MCP server
└── data/
    └── legal_knowledge.json  # Legal knowledge (20 entries)

frontend/
├── Dockerfile           # Frontend container image
└── src/
    ├── App.tsx           # Main UI
    └── App.css           # Styles

docker-compose.yml       # Container orchestration

Key Design Decisions

  • LangGraph over simple chain: Supports conditional branching, state management, and is extensible for multi-agent collaboration
  • RAG: Grounds agent responses in reliable legal knowledge rather than relying solely on LLM memory
  • MCP: Standardized AI tool protocol enabling any client (Claude Desktop, etc.) to invoke contract review capabilities
  • Tool Calling: Agent autonomously decides when to invoke which tool, demonstrating autonomous decision-making

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