Command Palette

Search for a command to run...

UnylyUnyly
Browse all

Legal Analysis

FreeNot checked

Legal document analysis pipeline with contract review, citation validation, and governance scoring.

GitHubEmbed

About

Legal document analysis pipeline with contract review, citation validation, and governance scoring.

README

Build MCP AI Agents for Legal — Dr. Maryam Miradi's 5-step framework, fully implemented.

AI-powered legal document analysis pipeline: parse → understand → generate → audit → route. One MCP server, reusable from LangGraph, CrewAI, and Google ADK.

Legal PDF
    │
    ▼
Step 1: Scope/Objective
    LegalAgentState initialised (confidence=0, escalation=True, validated=False)
    Document type check: accept contracts/agreements/NDAs/leases/employment
    Reject: invoices, scripts, unknown → escalate immediately
    │
    ▼
Step 2: Ground/Observe
    Run all 4 PDF parsers, pick highest score:
      PyPDF (85%) → PDFPlumber (90%) → LlamaIndex (88%) → Docling (92%) ✓
    Build surface map: what the document CAN and CANNOT answer
    Label each topic: DECISIVE / INFORMATIVE / IGNORE
    │
    ▼
Step 3: Logic/Input → Generator Agent
    Extract: clauses, obligations, key dates, risk flags, governing law
    Uses extended thinking (xhigh) — Claude Sonnet
    │
    ▼
Step 4: Assembly/Execute → Auditor Agent
    Verify every citation exists in the source document
    Check required compliance clauses per document type
    Produce audit score (0–1) and compliance gap report
    │
    ▼
Step 4b: Router Agent
    APPROVED   → confidence ≥ 70% AND audit passed
    REGENERATE → audit failed, regeneration budget remaining (max 2 attempts)
    ESCALATE   → max regenerations hit, low confidence, or unsupported type
    │
    ▼
Step 5: Deploy/Reuse — MCP Server
    extract_legal_document()           → full pipeline
    check_document_quality_tool()      → fast quality gate
    validate_legal_citation_tool()     → citation existence check
    analyze_contract_with_governance() → full + governance rules
    legal_analysis_workflow (prompt)   → workflow prompt for any LLM framework

Quick Start

pip install -e .
cp .env.example .env   # set ANTHROPIC_API_KEY

# Run demo with a synthetic contract (no PDF needed)
legal-agent demo

# Analyze a real PDF
legal-agent analyze contract.pdf

# Quality gate (fast, no LLM)
legal-agent quality contract.pdf

# With governance rules
legal-agent analyze nda.pdf --governance "GDPR compliance, data retention, right to audit"

# HTTP API
legal-agent serve
# → http://localhost:8000/docs

# MCP server (for LangGraph / CrewAI / Google ADK)
pip install -e ".[mcp]"
legal-agent mcp-server

PDF Parsers

Parser OCR Confidence Notes
PyPDF 85% Built-in fallback, always available
PDFPlumber 90% Highest word count, great for tables
LlamaIndex 88% pip install -e "[llama]"
Docling (IBM) 92% Recommendedpip install -e "[docling]"

All four run in parallel. The highest confidence × word_count score wins.

LegalAgentState

from legal_agent import LegalAgentState

# Fail-safe defaults (Dr. Miradi's pattern)
state = LegalAgentState(
    confidence=0.0,    # no trust until measured
    escalation=True,   # escalate to human by default
    validated=False,   # not valid until Auditor passes
)

Accepted Document Types

Type Accepted Required Clauses Checked
Contract governing_law, termination, liability_limitation, payment_terms
Agreement governing_law, termination, dispute_resolution
NDA confidentiality_scope, term, return_of_information
Lease rent_amount, lease_term, security_deposit
Employment compensation, termination, non_compete
Invoice Rejected — escalated immediately
Script Rejected — escalated immediately
Unknown Rejected — escalated immediately

MCP Tools (reusable across LangGraph / CrewAI / Google ADK)

# Any framework calls the same MCP server
@mcp.tool()
async def extract_legal_document(file_path: str) -> str: ...

@mcp.tool()
def check_document_quality_tool(file_path: str) -> str: ...

@mcp.tool()
def validate_legal_citation_tool(document_text: str, citation: str) -> str: ...

@mcp.tool()
async def analyze_contract_with_governance(file_path: str, governance_rules: str) -> str: ...

Built With

  • Anthropic Claude — Generator (extended thinking) + Auditor + surface map
  • Docling (IBM) — best-in-class PDF parsing (92% OCR confidence)
  • PDFPlumber — table-aware PDF extraction
  • FastMCP — MCP server
  • FastAPI + uvicorn — HTTP API
  • Rich — terminal UI

Based on Dr. Maryam Miradi's framework: www.maryammiradi.com

from github.com/jaykimproject/legal-mcp-agent

Installing Legal Analysis

This server has no published package — it is built from source. Open the repository and follow its README.

▸ github.com/jaykimproject/legal-mcp-agent

FAQ

Is Legal Analysis MCP free?

Yes, Legal Analysis MCP is free — one-click install via Unyly at no cost.

Does Legal Analysis need an API key?

No, Legal Analysis runs without API keys or environment variables.

Is Legal Analysis hosted or self-hosted?

Self-hosted: the server runs locally on your machine via the install command above.

How do I install Legal Analysis in Claude Desktop, Claude Code or Cursor?

Open Legal Analysis on unyly.org, pick your client tab (Claude Desktop, Claude Code, Cursor) and press Install — the config is generated automatically, no JSON editing.

Related MCPs

Compare Legal Analysis with

Not sure what to pick?

Find your stack in 60 seconds

Author?

Embed badge for your README

Browse similar

All development MCPs