Skip to main content
Glama

⚖️ china-law-mcp

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

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

License: MIT Python MCP Laws Articles

English · 中文


解决什么问题

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

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

  • 模型要引用《民法典》第 1254 条?先调 verify_citation 查一下,不存在就换掉

  • 模型写了一整段分析?check_citations_in_text 会把里面所有《某法》第 N 条抽出来逐条核验,列出编造的引用

  • 不知道适用哪条?search_statutes 用自然语言检索(支持「同事借我钱不还」这种口语)

数据在本地,不联网、不注册、不需要 API key。 公开仓库自带常用法律子集,完整法条库加密存放。

Related MCP server: mcp-fr-legal

快速开始

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

uvx --from git+https://github.com/thu-lawyer/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 秒

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

{
  "mcpServers": {
    "china-law": {
      "command": "uvx",
      "args": ["--from", "git+https://github.com/thu-lawyer/china-law-mcp", "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条']

数据:两层设计

公开仓库不带全量法条数据,避免数据被任意再分发。

层

内容

位置

公开子集(随仓库)

11 部常用法律 / 2,877 条现行条文:民法典、刑法、劳动合同法、道路交通安全法、消费者权益保护法、食品安全法、治安管理处罚法、行政诉讼法、行政处罚法、个人信息保护法、公司法

data/laws.db(2 MB,开箱即用)

完整数据(不公开)

378 部法律 / 23,995 条现行条文:宪法、法律、立法解释全量

data/laws.db.enc(AES-256-GCM 加密,需口令)

使用完整数据:

export CHINA_LAW_KEY='你的口令'      # 由数据提供方单独告知
python -m china_law_mcp              # 自动解密到临时文件,进程退出即清理

设计要点:

  • 加密为 AES-256-GCM,密钥由 scrypt(n=2¹⁵)从口令派生;口令错误会因认证标签校验失败而直接拒绝,不会解出损坏数据

  • 明文只落在系统临时目录,进程退出自动删除

  • 未设置口令时:检测到 laws.db.enc 会给出明确提示,而不是静默失败

  • ⚠️ 密文与口令若放在同一处,加密等于没有——口令必须单独传递

自建数据(换成你自己的语料):

python scripts/build_corpus.py 你的条文.jsonl     # → data/laws.db
python scripts/encrypt_data.py data/laws.db       # → data/laws.db.enc(需 CHINA_LAW_KEY)
python scripts/make_subset.py 完整语料.jsonl       # → 抽取公开子集

工作原理

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

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

已知局限

  • 公开仓库只含 11 部常用法律的子集;完整 378 部需向维护者获取加密数据与口令。

  • 检索是 BM25 基线,口语→法言法语的映射靠一张手工规则表(约 40 条)。常见场景效果好,生僻表述可能召回不相关条文——请始终以返回的条文原文为准。

  • 覆盖范围为宪法、法律、立法解释(378 部),不含行政法规、地方性法规、司法解释。修法频繁的领域请留意时效状态字段。

  • 条文时效状态部分为库内推定(见语料 status_basis 字段)。

  • 本工具提供条文检索与引用核验,不构成法律意见。

相关项目

许可

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

Available Tools

5 tools
check_citations_in_textA

抽取一段文本中的所有《法律》第 N 条引用并逐条核验,返回不存在的引用清单。

把模型生成的答案整段传进来,即可发现其中编造的引用。

Args: text: 待检查的文本(例如模型输出的一段法律分析)。

Returns: total / valid / invalid 计数,以及逐条核验结果。

ParametersJSON Schema
NameRequiredDescriptionDefault
textYes

TDQS

A3.8/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full burden. It discloses the extraction pattern, per-citation verification, and return counts, but omits whether the operation is read-only, requires network access, has rate limits, or has other side effects. For a verification tool, this is adequate but incomplete.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is front-loaded with the core purpose and uses clear Args/Returns structure. It is slightly verbose but every section contributes useful information for calling the tool correctly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple one-parameter tool with no output schema, the description covers purpose, usage, input semantics, and a summary of return values. It could mention edge cases (e.g., no citations found) or output shape more precisely, but it is largely complete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It explains that the single parameter is the text to check and gives a helpful example (model output legal analysis), which adds meaning beyond the bare schema type.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states a specific verb and resource: extract all 《法律》第 N 条 citations from a text, verify them one by one, and return the list of non-existent citations. It clearly distinguishes itself from siblings like search_statutes and list_laws, though it does not explicitly name the alternative verify_citation for single-citation checking.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It gives clear context by instructing to pass an entire model-generated answer to discover fabricated citations. This tells the agent when the tool is useful, but it does not mention exclusions or explicitly compare against sibling tools like verify_citation.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

get_articleA

按法律名与条号取条文原文。

Args: law: 法律名,支持简称,如「民法典」「中华人民共和国刑法」。 article_no: 条号,中文或阿拉伯数字均可,如「1254」「第一千二百五十四条」。

Returns: 找到则返回条文(含所属编章、部门法、时效状态),否则 None。

ParametersJSON Schema
NameRequiredDescriptionDefault
lawYes
article_noYes

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A3.5/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full behavioral burden. It usefully discloses that found articles include 编章, 部门法, and 时效状态, and that the tool returns None when not found, but it does not state read-only nature, permissions, rate limits, or other operational behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is front-loaded with the purpose, then uses compact Args and Returns sections. Every sentence earns its place, and the examples clarify accepted input formats without waste.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a two-parameter retrieval tool with an output schema, the description covers both inputs and the fallback return behavior. It lacks routing guidance to sibling tools, but nothing required to invoke the tool correctly is missing.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It does so by documenting both parameters: law supports abbreviations with examples, and article_no accepts Chinese or Arabic numerals with examples.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states a specific verb and resource: retrieve the original text of a legal article by law name and article number. This is clear, but it does not explicitly differentiate itself from siblings such as search_statutes or verify_citation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

There is no explicit when-to-use guidance, no mention of when to prefer search_statutes or other siblings, and no exclusions. Usage is only implied by the required parameters.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

list_lawsA

浏览库内法律目录(可按名称关键词或部门法筛选)。

Args: keyword: 法律名包含的关键词,如「劳动」「行政」。 department: 部门法,如「民法商法」「行政法」。 limit: 最多返回条数,默认 30。

ParametersJSON Schema
NameRequiredDescriptionDefault
limitNo
keywordNo
departmentNo

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A3.7/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. '浏览' implies a read-only operation and the limit default is stated, but there is no explicit confirmation of read-only behavior, side effects, or authentication needs.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The purpose is front-loaded in one sentence, followed by a compact Args section. Every sentence adds useful information with no filler.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple list tool with an output schema, the description covers purpose and all parameters adequately. It does not explicitly state that no filters returns all laws up to the limit, nor any ordering or pagination behavior beyond the limit.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It explains all three parameters with examples for keyword and department, and restates the limit default, adding clear meaning beyond the bare schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states a specific verb and resource: browsing the law catalog, with optional filters by name keyword or department. It is clear what the tool does, but it does not differentiate itself from siblings like search_statutes or get_article.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It implies usage for browsing/filtering laws, but gives no explicit when-to-use versus alternatives such as search_statutes. There are no exclusions or conditions for choosing this tool over its siblings.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

search_statutesA

按自然语言问题检索中国现行法律条文。

支持口语提问(如「同事借我钱不还怎么办」「外卖吃出异物能退吗」), 也会自动扩展为法言法语;支持「《民法典》第1254条」这类精确引用(直查优先)。

Args: query: 自然语言问题或关键词。 top_k: 返回条数,默认 6。 law: 可选,限定在某部法律内检索,支持简称如「民法典」「消保法」。

Returns: 条文列表,含 law / article_no / chapter / text / score / via。

ParametersJSON Schema
NameRequiredDescriptionDefault
lawNo
queryYes
top_kNo

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A4.2/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full burden and discloses meaningful behavior: automatic expansion into legal language, direct citation lookup priority, and returned fields including score and via. It still omits permissions, ranking behavior, coverage limits, and the precise meaning of score/via.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Structured as purpose, usage, Args, and Returns, with the core purpose front-loaded. There is slight redundancy between the introductory query-mode text and the query argument, but every section helps callers.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 3-parameter search tool with an output schema, the description covers query modes, parameter meanings, and return fields. It omits explicit sibling routing, which is a minor gap but not an invocation blocker.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate, and it does: query is defined as natural-language question or keywords, top_k defaults to 6, and law is optional with abbreviation support such as 民法典/消保法. All three visible parameters receive useful semantic detail beyond the bare schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb (检索) and resource (中国现行法律条文), and clarifies supported query modes such as自然语言 and precise citation. Sibling differentiation is implicit rather than explicit; it does not name or contrast get_article/list_laws.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Gives clear usage contexts: colloquial questions, keyword queries, and exact statutory citations with direct-lookup priority. It does not say when to prefer sibling tools like get_article or verify_citation, and offers no exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

verify_citationA

核验一条法律引用是否真实存在(防幻觉)。

在引用《某法》第 N 条之前调用本工具,可以避免编造或引用已废止条文。

Args: law: 法律名,支持简称,如「民法典」。 article_no: 条号,如「1254」或「第一千二百五十四条」。

Returns: verified(bool) + 条文原文(存在时)/ 原因(不存在时)。

ParametersJSON Schema
NameRequiredDescriptionDefault
lawYes
article_noYes

TDQS

A3.8/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations exist, so the description carries the full burden. It discloses the return contract (verified bool plus 条文原文 or 原因) and the anti-hallucination purpose, which is useful, but it says nothing about read-only safety, permissions, or rate limits.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Front-loaded purpose sentence, then a usage cue, then Args and Returns. Every section earns its place and nothing is padded, though the Args/Returns blocks partially restate schema structure.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

With no output schema and 0% schema coverage, the description correctly fills both gaps by documenting parameter formats and the return shape. It is complete enough to invoke correctly, missing only edge-case behavior (e.g. what 'reason' values look like).

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate, and it does: law supports abbreviations (「民法典」) and article_no accepts both Arabic and Chinese numerals («1254» or «第一千二百五十四条»). These format details are genuinely beyond the bare schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb+resource ('核验一条法律引用是否真实存在') and adds the intent (防幻觉), so an agent immediately knows this is an existence-check rather than a retrieval tool. It does not explicitly name how it differs from siblings like get_article or check_citations_in_text, which keeps it below a 5.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Gives a clear triggering condition: call before citing 《某法》第 N 条 to avoid fabricating or citing repealed articles. This is explicit 'when to use' guidance. It lacks explicit 'when not to use' or a named alternative sibling, so it falls short of a 5.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 5 tool updatesv0.1.0
    • First observedcheck_citations_in_text
    • First observedget_article
    • First observedlist_laws
    • First observedsearch_statutes
    • First observedverify_citation

TDQS

A3.9/5.0

Scored across 5 tools

Disambiguation4/5

search_statutes (NL retrieval) and get_article (exact law+article lookup) overlap somewhat, especially since search_statutes also does '直查优先' for exact citations. verify_citation also retrieves a law+article, but its validation-focused return (verified bool) distinguishes it from get_article's text retrieval, and check_citations_in_text is clearly distinct as a batch extractor.

Naming Consistency5/5

All five tools use a consistent snake_case verb_noun pattern: search_statutes, get_article, list_laws, verify_citation, check_citations_in_text. The longer batch tool name remains readable and follows the same convention.

Tool Count5/5

Five tools is well-scoped for a legal retrieval/verification server, with each tool covering a distinct capability (search, exact fetch, browse, single verify, bulk verify). No redundant or filler tools.

Completeness4/5

The surface covers the core read-only legal workflow: search by NL, fetch by citation, browse the catalog, and verify single or bulk citations. Minor gaps like retrieving a full law's chapter structure or browsing by effective date exist, but the primary agent workflows are supported.

Maintenance

ActivityMaintained
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers

  • F
    license
    A
    quality
    C
    maintenance
    Enables semantic search and retrieval of Chinese judicial cases from the Supreme People's Court case library, supporting natural language queries for similar cases, case details, filtering, and statistics.
    8
    10
    -
  • A
    license
    A
    quality
    C
    maintenance
    Provides offline access to the French legal corpus (Legifrance/DILA) with full-text search, verbatim article retrieval, and citation grounding to prevent hallucinations.
    4
    76 npm
    MIT
  • A
    license
    Not graded
    quality
    A
    maintenance
    Semantic and exact retrieval over 22M Taiwan court judgments with built-in citation guardrails — bundles carry a read-whitelist so downstream models cannot cite judgments whose reasoning was never read. Also provides exact lookup of administrative interpretations with lifecycle status (repealed / superseded / unverified).
    326
    Elastic 2.0