🛡️ 盲审计员-MCP服务器
“代码->审核->修改->再次审核->通过。”
盲人审计员是 强制性代码审计制度 基于MCP(模型上下文协议)构建。它使用了一种独特的 “思维隔离” 强制AI代理进入独立的“审计阶段”并在输出最终结果之前对其代码进行自我审查的机制。
🧠 核心哲学:思维隔离
传统的人工智能编码通常是“生成和输出”的,这会让错误和偏差溜走。Blind Auditor引入了一个中间层:
- 拦截:当代理想要输出代码时,它必须首先将其提交给Blind Auditor。
- 隔离:盲审不会立即返回结果。相反,它注入了 强制性系统指令,迫使代理暂停其当前角色并切换到“无情审计员”角色。
- 审计:在这种孤立的环境中,代理必须逐行扫描生成的代码,以符合预定义的
rules.json. - 发布:只有当审计分数达到阈值(默认值>80)并且没有严重问题时,代码才会解锁并返回给用户。
🎯 主要特点
- 🛡️ 零信任架构:默认不信任代理人的初稿;它必须通过审计。
- 💰 零额外成本:重用主机IDE的当前会话模型,不需要额外的API密钥。
- ⚖️ 偏置消除:通过快速注射强制透视开关,以打破发电惯性。
- 📏 严格遵守:硬代码团队代码标准(
rules.json)这比简单的Prompts更有效。 - 🔄 自动修复循环:审核失败时自动触发“修复重新提交”循环,直到达到合规性或达到最大重试次数。
______________________________________________________________________
🚀 快速开始
1.先决条件
这个项目需要Python 3.10+和 紫外线.
# Install uv (if not already installed)
curl -LsSf https://astral.sh/uv/install.sh | sh
# Enter project directory
cd blind-auditor
# Install dependencies (automatically creates virtual environment)
uv sync2.配置审核规则(rules.json)
创建或编辑 rules.json 在项目根中。这是审计员的“规则手册”。
{
"project_name": "MyCoreProject",
"strict_mode": true,
"max_retries": 3,
"rules": [
{
"id": "SEC-001",
"severity": "CRITICAL",
"description": "Strictly prohibit hardcoding any API Keys, passwords, or sensitive Tokens.",
"weight": 50
},
{
"id": "PERF-001",
"severity": "WARNING",
"description": "Avoid database queries or IO operations inside loops.",
"weight": 15
},
{
"id": "STYLE-001",
"severity": "PREFERENCE",
"description": "Use snake_case for variable names.",
"weight": 5
}
]
}配置字段:
severity:
- CRITICAL:严重错误。如果发现,审核将立即失败。通常会受到很高的惩罚。 - WARNING:警告。适度处罚;积累会导致失败。 - PREFERENCE:风格偏好。罚款低。
weight:违反此规则时扣除的罚分(总分:100)。
3.配置IDE(反重力/光标/风帆)
步骤A:添加系统提示(关键)
为确保代理知道必须使用此工具,请在您的 .cursorrules 或IDE系统提示设置:
# Blind Auditor Protocol
**CRITICAL INSTRUCTION**:
You are integrated with the **Blind Auditor MCP**.
Whenever you generate code for a user request, you **MUST NOT** output the code block directly to the user.
**Execution Protocol**:
1. **Draft**: Generate the code internally in your thought process.
2. **Submit**: Call the `submit_draft` tool with your code and language.
3. **Obey**: The tool will return a strict "Audit Instruction". You MUST follow it exactly to audit your own code.
4. **Finalize**: Only when the tool returns "✅ AUDIT PASSED" can you display the final code to the user.
**Prohibited**:
- Do NOT output code blocks before passing the audit.
- Do NOT skip the audit step for "simple" changes.步骤B:配置MCP服务器
将以下内容添加到MCP客户端配置文件中(例如。, claude_desktop_config.json 或IDE设置):
备注:替换 /path/to/your/blind-auditor 使用克隆此存储库的实际绝对路径。
{
"mcpServers": {
"blind-auditor": {
"command": "uv",
"args": ["run", "--directory", "/path/to/your/blind-auditor", "blind-auditor"]
}
}
}______________________________________________________________________
🔧 工具详细信息
1. submit_draft
提交代码草案。
- 输入:
code(内容),language(程序设计语言) - 行为:锁定会话并返回强制审核指令。
2. submit_audit_result
提交您的审计结论。
- 输入:
- passed (bool):你是否相信它通过了。 - issues (列表):发现的问题列表。 - score (int):0-100分。
- 行为:
- 如果 `score Agent Agent["Agent Generates Draft"] -->|1. submit_draft| MCP MCP -->|2. Inject Audit Instructions| Agent
subgraph Isolation ["Thinking Isolation"] Agent -->|3. Self-Review| Agent Agent -->|4. submit_audit_result| MCP end
MCP -->|5. Verdict| Decision{"Passed?"}
Decision -->|No - Issues Found| Retry["Retry Count +1"] Retry -->|Limit Not Reached| Fix["Agent Fixes Code"] Fix -->|Resubmit| Agent
Decision -->|Yes - Score >= 80| Final["✅ Output Final Code"]
Retry -->|Limit Reached| Force["⚠️ Force Output - With Warning"]
## ❓ 故障排除
**Q: Agent始终直接输出代码,而无需调用工具。**
A: 检查系统提示是否配置正确。您必须明确告诉代理“不要直接输出代码”。您也可以在聊天中手动提醒:“请先通过盲人审核员审核”。
**Q: 为什么即使我给代码100分,它也会失败?**
A: 检查是否有 `CRITICAL` 规则在 `rules.json` 被触发。当前的逻辑主要依赖于 `score` 由代理人通过,但如果 `passed` 是 `True` 当 `score < 80`,系统将强制拒绝。
**Q: 支持哪些编程语言?**
A: 理论上,支持所有语言。Blind Auditor本身不解析代码语法,而是依赖于Agent的理解来匹配中的描述 `rules.json`.
______________________________________________________________________
## 🛠️ 开发指南
Run server
uv run blind-auditor
Or run directly with Python module
uv run python -m src.main
Debug mode (output to stderr)
View print statements in src/main.py
## 📄 许可证
MIT许可证