China Law MCP

io.github.thu-lawyerv0.1.1Updated Oct 4, 2026

Search 23,995 Chinese statutes and verify citations to catch LLM-fabricated references.

Overview

AI-generated overview

Lets an assistant search 23,995 current Chinese statutes offline and verify whether cited law articles actually exist.

What it does
Provides a local corpus of 378 Chinese laws (constitution, statutes, legislative interpretations) with 23,995 articles. Tools include search_statutes for natural-language retrieval, get_article for fetching an article by law and number, list_laws for browsing the catalog, verify_citation for checking a single citation, and check_citations_in_text for extracting and validating every citation in a passage. Retrieval uses a local BM25 index with no external API calls.
When to use it
Useful when an assistant answers Chinese legal questions and citations must be checked, or when you want to catch fabricated references to Chinese laws. Also suited to looking up article text or finding relevant statutes from a plain-language description.
Requirements
Runs locally as a stdio process. Install via uvx or pip (Python), or run the published Docker image. No account, API key, or network access is required; the SQLite database ships with the package and the BM25 index is built on first run.
Before you install
The README states retrieval is a BM25 baseline with a hand-written colloquial-to-legal mapping, so uncommon phrasing may return irrelevant articles; always rely on the returned article text. Coverage is limited to the constitution, statutes, and legislative interpretations, excluding administrative regulations, local rules, and judicial interpretations. Currency status is partly inferred, and the tool does not constitute legal advice. An optional encryption script uses the CHINA_LAW_KEY…

Installation

In SourceWeft

  1. Open China Law MCP in the dashboard and add it to a workspace.
  2. Enable the server for the chats that should use its tools.

Desktop only via STDIO. STDIO servers start a local process, so they need the SourceWeft desktop host.

Other MCP clients

Follow the launch instructions in the repository.

README

⚖️ china-law-mcp

中国法律条文 MCP 服务器 · 让 AI 引用法条不再编造

免费 · 免注册 · 免 API key · 本地运行

[License: MIT] [CI] [Python] [PyPI] [Downloads] [MCP] [MCP Registry] [Glama] [ghcr.io] [Laws] [Articles]

English · 中文


解决什么问题

直接问大模型中国法律问题,有两个后果:引用的条文可能根本不存在或已废止,你无法核实。法律是最不能容忍编造的领域。

china-law-mcp 给 AI 装上一个离线法条库 + 引用核验器:

  • 模型要引用《民法典》第 1254 条?先调 verify_citation 查一下,不存在就换掉
  • 模型写了一整段分析?check_citations_in_text 会把里面所有《某法》第 N 条抽出来逐条核验,列出编造的引用
  • 不知道适用哪条?search_statutes 用自然语言检索(支持「同事借我钱不还」这种口语)

数据在本地,不联网、不注册、不需要 API key。

快速开始

方式一:一行命令(推荐)

bash
uvx china-law-mcp

方式二:pip 安装

bash
pip install china-law-mcpchina-law-mcp

方式二:克隆运行

bash
git clone https://github.com/thu-lawyer/china-law-mcpcd china-law-mcppip install -r requirements.txtpython -m china_law_mcp        # 首次运行自动构建 BM25 索引,约 6 秒

方式三:Docker(镜像已发布到 ghcr.io)

bash
docker run -i --rm ghcr.io/thu-lawyer/china-law-mcp:latest
json
{  "mcpServers": {    "china-law": {      "command": "docker",      "args": ["run", "-i", "--rm", "ghcr.io/thu-lawyer/china-law-mcp:latest"]    }  }}

接入 Claude Code / Cursor / 其他 MCP 客户端

json
{  "mcpServers": {    "china-law": {      "command": "uvx",      "args": ["china-law-mcp"]    }  }}

工具

工具作用
search_statutes(query, top_k, law?)自然语言问题 → 相关法条(口语自动扩展为法言法语)
get_article(law, article_no)法律 + 条号 → 条文原文,支持「民法典」「1254」「第一千二百五十四条」
list_laws(keyword?, department?)浏览库内法律目录
verify_citation(law, article_no)核验单条引用是否真实存在
check_citations_in_text(text)抽取文本中全部引用并逐条核验,列出编造的

效果示例

自然语言检索(口语直接问):

text
search_statutes("同事借我钱不还怎么办")→ 中华人民共和国民法典 第六百七十五条  借款人应当按照约定的期限返还借款…→ 中华人民共和国民法典 第六百七十四条  借款人应当按照约定的期限支付利息…
search_statutes("外卖吃出异物能退吗")→ 中华人民共和国食品安全法 第一百四十八条  消费者因不符合食品安全标准的食品受到损害的,                                            可以向经营者要求赔偿损失,也可以向生产者要求赔偿…

引用核验(防止 AI 编造):

text
verify_citation("民法典", "1254")   → verified=True   (真实存在)verify_citation("民法典", "9999")   → verified=False  中华人民共和国民法典 没有第 9999 条
check_citations_in_text("根据《民法典》第1254条…依据《劳动合同法》第99条和《民法典》第88888条…")→ 共 3 条,有效 1,无效 2→ invalid: ['《劳动合同法》第99条', '《民法典》第88888条']

数据

  • 378 部法律、23,995 条现行条文(宪法、法律、立法解释全量)
  • 每条含:法律名、编章、条号(中文 + 阿拉伯数字)、条文全文、部门法、时效状态
  • SQLite 数据库(15 MB)随仓库提供,开箱即用;BM25 索引首次运行自动构建(约 6 秒,之后缓存)

换成你自己的语料:

bash
python scripts/build_corpus.py 你的条文.jsonl     # → data/laws.db

字段说明见 scripts/build_corpus.py 头部注释。scripts/ 下另有两个可选工具:make_subset.py(抽取常用法律子集)、encrypt_data.py(把数据库加密为 laws.db.enc,服务器可用 CHINA_LAW_KEY 环境变量自动解密)。

工作原理

用户提问   ↓search_statutes   ← BM25 召回 + 口语同义词/共现规则扩展 + 覆盖率与短语重排 + 条号直查   ↓返回条文原文(含出处)   ↓模型依据条文作答   ↓check_citations_in_text   ← 正则抽取《X法》第N条,逐条查库核验   ↓编造的引用被列出并剔除

检索是纯本地 BM25(rank-bm25 + jieba),不调用任何外部 API,因此没有网络依赖、没有调用成本,也不会把你的查询发给第三方。

已知局限

  • 检索是 BM25 基线,口语→法言法语的映射靠一张手工规则表(约 40 条)。常见场景效果好,生僻表述可能召回不相关条文——请始终以返回的条文原文为准。
  • 覆盖范围为宪法、法律、立法解释(378 部),不含行政法规、地方性法规、司法解释。修法频繁的领域请留意时效状态字段。
  • 条文时效状态部分为库内推定(见语料 status_basis 字段)。
  • 本工具提供条文检索与引用核验,不构成法律意见。

收录情况

开发

bash
pip install -r requirements-dev.txtPYTHONPATH=src pytest tests/ -v     # 12 个测试,覆盖检索、直查、引用核验

相关项目

许可

MIT。条文数据来自公开渠道整理,请遵守相应来源的使用条款。

Source: README.md at commit f502333

Tools

0
Tool metadata has not been indexed yet.

Version history

1
  1. v0.1.1LatestOct 4, 2026