legal-contract-mcp
MCP server for first-pass legal contract review. It loads txt/docx/pdf contracts, detects standard clauses, flags heuristic risks, summarizes, and compares agreements.
README
legal-contract-mcp
An MCP (Model Context Protocol) server that gives an LLM client (Claude, Claude Code, Claude Desktop, etc.) tools to do a first-pass review of contracts: load a .txt/.docx/.pdf, detect standard clause types, flag heuristic risk issues, generate a summary, and diff two contracts against each other.
This is not legal advice — it's a rules-based first pass meant to speed up human review, built to demonstrate a real, non-trivial MCP server (as opposed to a toy "add two numbers" example).
Why this exists
Most MCP server examples are thin wrappers around an API call. This one does actual work locally:
- Parses real document formats (txt/docx/pdf)
- Detects 12 standard clause types via a maintained pattern library, not a single regex
- Runs 8 explainable risk heuristics (e.g. indemnification without a liability cap, auto-renewal without a clear notice period, non-competes with no defined scope) — every flag cites the exact clause text it's based on
- Falls back gracefully to an extractive summary if no
OPENAI_API_KEYis set, and upgrades to an LLM-generated summary if one is
Tools exposed
| Tool | Description |
|---|---|
load_contract(path) |
Load a .txt/.docx/.pdf file, returns a doc_id |
list_documents() |
List contracts loaded in this session |
extract_clauses(doc_id) |
Detected clause types with snippets |
missing_clauses(doc_id) |
Standard clause types NOT found — gap check |
flag_risks(doc_id) |
Heuristic risk flags with severity + evidence |
summarize_contract(doc_id) |
Plain-English summary (LLM or extractive fallback) |
compare_contracts(doc_id_a, doc_id_b) |
Diff clause types and risk flags between two contracts |
search_clause_library(query) |
Look up a clause type's definition by keyword |
Setup
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -e ".[dev]"
Optional — enable LLM-powered summaries:
export OPENAI_API_KEY=sk-ant-...
Run it
Inspector (interactive dev UI):
mcp dev src/legal_contract_mcp/server.py
As a stdio server (for Claude Desktop / Claude Code config):
{
"mcpServers": {
"legal-contract-mcp": {
"command": "python",
"args": ["-m", "legal_contract_mcp.server"],
"cwd": "/absolute/path/to/legal-contract-mcp",
"env": { "OPENAI_API_KEY": "sk-ant-..." }
}
}
}
Then in a chat with the connected client:
Load the contract at tests/sample_contracts/weak_nda.txt and flag its risks.
Test
pytest # unit tests for clause detection + risk rules
python scripts/smoke_test.py # spins up the real MCP server over stdio and calls every tool
Includes two sample contracts (tests/sample_contracts/weak_nda.txt and solid_msa.txt) chosen so the risk engine's output differs meaningfully between a weak and a well-drafted agreement — tests assert on that difference, not just "does it run."
Project structure
src/legal_contract_mcp/
parsing.py # txt/docx/pdf -> plain text, in-memory doc store
clause_library.py # 12 clause types: definitions + detection patterns
clauses.py # runs the library against a document
risk_rules.py # 8 heuristic risk rules, each with cited evidence
llm.py # optional Claude-powered summary, extractive fallback
server.py # FastMCP tool definitions
tests/
sample_contracts/ # weak NDA vs. solid MSA fixtures
test_clauses_and_risks.py
Extending it
- Add a clause type: add an entry to
CLAUSE_LIBRARYinclause_library.pywith a definition and one or more regex patterns. - Add a risk rule: add a function block to
evaluate_risks()inrisk_rules.py— return aRiskFlagwithrule,severity,message, andevidence. - Swap the in-memory store in
parsing.pyfor a database if you want documents to persist across server restarts.
Disclaimer
This tool provides automated, heuristic pattern-matching only. It is not a substitute for review by a licensed attorney and should not be relied on as legal advice.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。