mcp-law-server
Provides vector similarity search for law titles, clauses, and audit items, enabling semantic retrieval.
Provides relational query for hierarchical and categorical law data, supporting structured lookups and filtering.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@mcp-law-server find regulations related to government procurement audit"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
mcp-law-server
审计法规智能检索 MCP Server —— 面向审计 Agent 的法规/条款/审计事项检索与核实服务。
Milvus 向量检索(法规名 / 条款 / 审计事项)+ MySQL 关系查询(层级 / 分类)+ Hermes Agent 编排 + Agent 核实
技术栈
层 | 选型 |
语言 / 运行时 | Python 3.12 |
包管理 / 构建 | uv + hatchling(src-layout) |
MCP 框架 | FastMCP >=2.3(stdio + HTTP 双传输) |
MySQL 访问 | SQLAlchemy 2.x async + asyncmy(双库:audit_corpus / auditkm_factory) |
向量库 | Milvus(pymilvus),库 |
Embedding | BGE-large-zh-v1.5,1024 维(本地 FlagEmbedding 推理) |
LLM | Qwen3.5-27B(vLLM,OpenAI-compatible HTTP) |
缓存 | Redis / 内存双后端(TTL + 多轮对话上下文) |
配置 | pydantic-settings + |
编排 | Hermes Python 编排引擎( |
Related MCP server: hivelaw
目录结构
mcp_law_server/
├── pyproject.toml # 元数据 / 依赖 / 入口 / 工具配置
├── .env.example # 环境变量模板(复制为 .env 填写)
├── Dockerfile # Docker 镜像构建(python:3.12-slim)
├── docker-compose.yaml # 单服务编排(stdio/http 双传输)
├── src/mcp_law_server/ # ── 应用代码(src-layout)──
│ ├── main.py # CLI 入口(stdio / http 双传输 + 优雅关闭)
│ ├── config/ # 配置层 —— Settings 单例(pydantic-settings)
│ ├── models/ # 数据模型层 —— enums / schemas / errors / error_codes
│ ├── interfaces/ # 接口层 —— 13 个 Protocol 定义(embedding/db/vector/cache)
│ ├── db/ # MySQL 数据访问层 —— connection + 5 个 DAO
│ ├── vector/ # Milvus 向量访问层 —— client + 3 个 Searcher
│ ├── embedding/ # Embedding 层 —— BGEEncoder 本地推理
│ ├── cache/ # 缓存层 —— 内存/Redis 双后端 + TypedCache
│ ├── tools/ # MCP 工具层 —— 11 个 tool handler(核心业务)
│ ├── hermes/ # Hermes 编排层 —— 10 文件 Python 包(14 Agent DAG)
│ ├── observability/ # 可观测性 —— logging + degradation + log_format
│ ├── registry/ # MCP Registry —— 12 文件 7 模块(工具注册/语义匹配/网关)
│ ├── chat/ # Chat 服务 —— export/law/stats/sse 4 模块
│ └── server/ # MCP Server 注册 —— mcp_app + error_boundary
├── scripts/ # ── 运维脚本(验证/演示/向量化/性能测试)──
└── tests/ # ── 测试(14 子目录,1066 测)──依赖方向(从下到上,禁止反向引用):
config → models → {db, vector, embedding, cache} → tools → server → main
横切层 observability/、registry/、interfaces/ 被多层依赖。
核心能力(11 个 MCP 工具)
类型 | 工具 | 说明 |
编排入口 |
| Hermes DAG 综合查询(意图→路由→三通道并行→融合) |
编排入口 |
| Agent 00 问题拆解 + 逐题验证 + 可信度聚合 |
路由入口 |
| 按意图路由到对应原子工具 |
原子工具 |
| 法规名称向量检索(MySQL 三形态 + Milvus 语义) |
原子工具 |
| 条款内容向量检索(Milvus 6 collection 联合) |
原子工具 |
| 审计问题→法规映射(bge 双路 RRF 合并) |
原子工具 |
| 按法规 ID 查六要素详情 |
原子工具 |
| 法规全文条款检索 |
原子工具 |
| 法规层级关系查询(上位法/相关法/历史版本/废止) |
原子工具 |
| 条款法定属性分类(7 类法律规范属性) |
原子工具 |
| 法规引用 4 轮 Loop 核实 |
快速开始
# 1. 安装核心 + 开发依赖(uv 会自动准备 Python 3.12 解释器)
uv sync
# 2. (按需)安装 ML 依赖(FlagEmbedding / torch,体积较大)
uv sync --extra ml
# 3. 配置环境变量
cp .env.example .env # 然后编辑 .env 填写真实值
# 4. 启动 MCP Server(stdio 模式)
uv run mcp-law-server
# 5. 启动 MCP Server(HTTP 模式)
MCP_TRANSPORT=http uv run mcp-law-server常用命令
命令 | 说明 |
| 安装核心 + 开发依赖 |
| 额外安装 ML 依赖 |
| 启动 MCP server(stdio) |
| 启动 MCP server(HTTP) |
| 运行全部测试(1066 测) |
| 代码风格检查 |
| 类型检查 |
| Docker 部署 |
环境变量
见 .env.example,字段与 src/mcp_law_server/config/settings.py 一一对应。
Available Tools
11 toolsagent_queryC
Hermes 编排综合查询(意图→路由→多通道→融合,返回最终回复与结构化依据)
Inputs: query (required), session_id. Returns: object
decompose_queryA
问题拆解与逐题验证编排器:将复杂审计问题拆为子问题,逐题调用 Hermes 编排获取答案并核实,汇总输出含可信度评估
Inputs: query (required). Returns: object
get_clause_classificationsC
查询条款法定属性分类(7 类 clause_type)
Inputs: top_k, law_id, keyword, clause_types. Returns: object
get_regulation_hierarchyB
查询法规层级关系(上位法 / 相关法 / 历史版本 / 废止)
Inputs: law_id (required). Returns: object
issue_to_lawC
审计问题 → 法规映射(bge 双路向量检索 + audit_issues 富表)
Inputs: query (required), top_k, basis_type. Returns: object
law_article_searchC
按条款号在法规正文中检索(MySQL LIKE 降级方案)
Inputs: law_id (required), article_number (required). Returns: Generic wrapper for non-object return types.
law_lookupB
按法规 ID 获取法规六要素
Inputs: law_id (required). Returns: object
search_clause_vectorC
按条款内容做语义检索,返回候选条款(含相似度)
Inputs: query (required), top_k, law_id, region_type, +1 more. Returns: object
search_law_name_vectorB
按法规名称检索(MySQL 精确优先 + Milvus 向量兜底)
Inputs: law_name (required), top_k, region_type. Returns: object
smart_queryC
智能综合查询(按意图路由到对应检索通道)
Inputs: query (required), law_name, intent_type, article_number. Returns: object
verify_law_referenceC
多轮 Loop 核实 Agent 输出的法规引用是否真实存在
Inputs: references (required), question. Returns: object
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 11 tools
Most tools have distinct purposes, but agent_query, decompose_query, and smart_query all serve query functions and could cause confusion about when to use each.
Names mostly follow verb_noun or noun_verb patterns with snake_case, but issue_to_law and smart_query deviate from the pattern, introducing minor inconsistency.
11 tools is well-scoped for a legal regulation server, covering queries, searches, hierarchy, and verification without being excessive.
The tool set covers core operations: semantic and keyword search, hierarchy retrieval, clause classification, issue mapping, and reference verification. No obvious gaps for a read-only legal server.
Related MCP Connectors
AI governance MCP server for EU AI Act compliance and jurisdiction verification
MCP server for FCA Handbook compliance analysis with verbatim citations.
City hiring-compliance MCP server with regulation search and full audit risk scoring.
MCP server unifying ERPs, CRMs, APIs and knowledge base for Claude, ChatGPT and Gemini.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceRAG-enabled MCP server that uses Google Gemini for embeddings and Supabase for vector storage, enabling semantic search and document similarity matching through natural language queries.-
- AlicenseNot gradedqualityDmaintenanceMCP server for AI compliance auditing. Scores agent outputs for hallucination liability under the EU AI Act, issues verifiable compliance stamps, and tracks audit history by agent.MIT
- FlicenseAqualityBmaintenanceAn MCP server that provides queryable access to Anti-Money Laundering (AML) red flag knowledge from regulatory documents. It enables compliance officers to ask natural-language questions and receive relevant, sourced red flags from a local vector database.7-
- FlicenseNot gradedqualityDmaintenanceA production-grade MCP server that automates financial compliance audits by combining LLMs with structured analysis, enabling policy validation, risk profiling, and automated reporting.-