解决什么问题
直接问大模型中国法律问题,有两个后果:引用的条文可能根本不存在或已废止,你无法核实。法律是最不能容忍编造的领域。
china-law-mcp 给 AI 装上一个离线法条库 + 引用核验器:
- 模型要引用《民法典》第 1254 条?先调
verify_citation查一下,不存在就换掉 - 模型写了一整段分析?
check_citations_in_text会把里面所有《某法》第 N 条抽出来逐条核验,列出编造的引用 - 不知道适用哪条?
search_statutes用自然语言检索(支持「同事借我钱不还」这种口语)
数据在本地,不联网、不注册、不需要 API key。
快速开始
方式一:一行命令(推荐)
uvx china-law-mcp
方式二:pip 安装
pip install china-law-mcp
china-law-mcp
方式二:克隆运行
git clone https://github.com/thu-lawyer/china-law-mcp
cd china-law-mcp
pip install -r requirements.txt
python -m china_law_mcp # 首次运行自动构建 BM25 索引,约 6 秒
方式三:Docker(镜像已发布到 ghcr.io)
docker run -i --rm ghcr.io/thu-lawyer/china-law-mcp:latest
{
"mcpServers": {
"china-law": {
"command": "docker",
"args": ["run", "-i", "--rm", "ghcr.io/thu-lawyer/china-law-mcp:latest"]
}
}
}
接入 Claude Code / Cursor / 其他 MCP 客户端
{
"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) |
抽取文本中全部引用并逐条核验,列出编造的 |
效果示例
自然语言检索(口语直接问):
search_statutes("同事借我钱不还怎么办")
→ 中华人民共和国民法典 第六百七十五条 借款人应当按照约定的期限返还借款…
→ 中华人民共和国民法典 第六百七十四条 借款人应当按照约定的期限支付利息…
search_statutes("外卖吃出异物能退吗")
→ 中华人民共和国食品安全法 第一百四十八条 消费者因不符合食品安全标准的食品受到损害的,
可以向经营者要求赔偿损失,也可以向生产者要求赔偿…
引用核验(防止 AI 编造):
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 秒,之后缓存)
换成你自己的语料:
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字段)。 - 本工具提供条文检索与引用核验,不构成法律意见。
收录情况
- PyPI:https://pypi.org/project/china-law-mcp/
- MCP 官方注册表(active):https://registry.modelcontextprotocol.io/v0/servers?search=china-law-mcp
- Glama:https://glama.ai/mcp/servers/thu-lawyer/china-law-mcp —— 工具定义评分 A
- awesome-mcp-servers:已提交 PR
- 容器镜像:
ghcr.io/thu-lawyer/china-law-mcp
开发
pip install -r requirements-dev.txt
PYTHONPATH=src pytest tests/ -v # 12 个测试,覆盖检索、直查、引用核验
相关项目
- 律问 LawQ —— 同一套检索引擎的 Web / 小程序版本(带流式问答)
- 中国行政诉讼案例数据集 —— 635 个行政案件、425 篇裁判文书全文
许可
MIT。条文数据来自公开渠道整理,请遵守相应来源的使用条款。
Metadata
Release files for china-law-mcp 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| china_law_mcp-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for china_law_mcp-0.1.1-py3-none-any.whl |
Release files / china_law_mcp-0.1.1-py3-none-any.whl
| Download URL | china_law_mcp-0.1.1-py3-none-any.whl |
|---|---|
| Size | 3.4 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
969c0cee3a79e3414fd4c7c6b5c7ac0d290dbcd5c61eb903e4a6ccc999642e78
|
|
BLAKE2b-256 checksum How to use checksums |
d29192eb8cabe1535bedea4af85e2774e0065151934682da0b5e2f348bdf0ccf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.7
|
Security for china-law-mcp 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.