MCP Code Sanitizer
🔍 mcp-code-sanitizer
一款严格的 AI 代码审查工具,可通过 Claude Desktop、Cursor 或任何兼容 MCP 的代理直接使用 Groq LLM 运行您的代码。
Claude Desktop ──MCP──► code-sanitizer ──REST──► Groq API
(server.py) (llama-3.3-70b)✨ 功能
工具 | 描述 |
| 严格的代码审查 — 错误、漏洞、评分 0–100 |
| 比较两个版本,发现回归问题,建议合并/请求更改 |
| 针对初级/中级/高级受众的分步解释 |
| 生成 pytest/jest/go 测试,包含正常路径、边界情况和安全测试 |
| 通过并行分块分析磁盘上的整个文件 |
| 根据任何分析结果生成精美的 HTML 报告 |
| 缓存统计信息和清理 |
响应示例
{
"summary": "Critical SQL injection and secret exposed in logs",
"score": 23,
"issues": [
{
"severity": "critical",
"line": 2,
"title": "SQL Injection",
"description": "f-string directly interpolates user_id into query",
"fix": "cursor.execute('SELECT * FROM users WHERE id = %s', (user_id,))"
}
],
"warnings": [{"title": "No exception handling", "description": "..."}],
"suggestions": ["Consider using an ORM instead of raw SQL"]
}Related MCP server: Claude Code Review MCP
🚀 快速开始
1. 克隆仓库
git clone https://github.com/YOUR_USERNAME/mcp-code-sanitizer
cd mcp-code-sanitizer2. 创建虚拟环境并安装依赖
python -m venv venv
# macOS / Linux
source venv/bin/activate
# Windows
venv\Scripts\activate
pip install -r requirements.txt3. 添加您的 Groq API 密钥
在 console.groq.com/keys 获取免费密钥
cp .env.example .env
# Open .env and set GROQ_API_KEY=gsk_...4. 测试服务器
python server.py静默表示它正在运行 — 服务器正在通过 stdio 监听 MCP 请求。
🔌 连接到 Claude Desktop
找到您的配置文件并添加 mcpServers 部分:
操作系统 | 配置文件路径 |
macOS |
|
Windows |
|
Linux |
|
{
"mcpServers": {
"code-sanitizer": {
"command": "/full/path/to/venv/bin/python",
"args": ["/full/path/to/server.py"],
"env": {
"GROQ_API_KEY": "gsk_your_key_here"
}
}
}
}重启 Claude Desktop — 您将在聊天中看到 🔧 图标。
🔌 连接到 Cursor
在项目根目录创建 .cursor/mcp.json:
{
"mcpServers": {
"code-sanitizer": {
"command": "/full/path/to/venv/bin/python",
"args": ["/full/path/to/server.py"],
"env": {"GROQ_API_KEY": "gsk_your_key_here"}
}
}
}🧪 通过 MCP Inspector 测试
source venv/bin/activate # or venv\Scripts\activate on Windows
fastmcp dev inspector server.py浏览器 UI 将打开,提供完整的工具测试界面。
💬 聊天中使用
连接到 Claude Desktop 后,只需输入:
Review this code for vulnerabilities:
def get_user(user_id):
query = f"SELECT * FROM users WHERE id = {user_id}"
return db.execute(query)或者显式调用工具:
Use analyze_file on /path/to/my_script.py
Generate tests for this function: ...
Compare these two versions and tell me if it got better: ...🏗️ 架构
mcp-code-sanitizer/
├── server.py # FastMCP entry point (39 lines)
├── config.py # Constants — keys, limits, mappings
├── groq_client.py # Groq API client with auto-retry on rate limits
├── cache.py # In-memory cache with TTL
├── prompts.py # System prompts for all tools
└── tools/
├── analyze.py # analyze_code
├── compare.py # compare_code
├── explain.py # explain_code
├── tests.py # generate_tests
├── file_tool.py # analyze_file (chunking + parallel analysis)
├── cache_tool.py # cache_info
└── report.py # generate_report (HTML)⚙️ 配置
所有设置均通过环境变量或 .env 文件进行:
变量 | 默认值 | 描述 |
| — | 必需。在 console.groq.com 获取 |
|
| Groq 模型 |
|
| 缓存 TTL(秒) |
|
| 最大缓存条目数 |
可用的 Groq 模型
模型 | 速度 | 质量 |
| ⚡⚡ | ⭐⭐⭐⭐⭐ (默认) |
| ⚡⚡⚡ | ⭐⭐⭐ |
| ⚡⚡ | ⭐⭐⭐⭐ |
📦 要求
fastmcp>=2.3.0
httpx>=0.27.0
python-dotenv>=1.0.0🤝 贡献
欢迎提交 PR 和 Issue!特别关注:
支持其他 LLM 提供商(OpenAI, Anthropic)
新工具(安全审计、依赖检查、复杂度分析)
提示词改进
📄 许可证
MIT — 随心所欲地使用。如果能给个 GitHub 星标将不胜感激 ⭐
🔗 链接
Available Tools
7 toolsanalyze_codeC
Strict analysis of a code fragment using Groq LLM.
Inputs: code (required), language, context. Returns: result
analyze_fileA
Analyzes a whole code file from disk. Automatically detects language by file extension. Large files are split into chunks and analyzed in parallel.
Inputs: file_path (required), language, context. Returns: result
cache_infoA
Shows cache statistics or clears the cache Args: clear: True - clears the cache, False - shows statistics.
Returns: JSON with cache stats or clear result.
Inputs: clear. Returns: result
compare_codeA
Compares two versions of code and evaluates whether the change is an improvement.
Performs a structured diff analysis: identifies what improved, what regressed, and what changed neutrally. Returns a merge recommendation based on the findings. Useful for code review, refactoring validation, and AI-generated code verification.
Inputs: code_before (required), code_after (required), language, context. Returns: result
explain_codeA
Explains what code does - step by step and clearly. Args: code: Code to explain. language: Programming language. audience: Target audience level - junior, middle, or senior. Returns: JSON with step-by-step explanation, key concepts, and gotchas.
Inputs: code (required), language, audience. Returns: result
generate_reportA
Generates a beautiful HTML report from analyze_code or analyze_file results. Args: analysis_json: JSON string from analyze_code or analyze_file. output_path: Path to save the HTML file (optional). source_name: File/fragment name for the report title. Returns: JSON with fields: html, saved_to, length.
Inputs: analysis_json (required), output_path, source_name. Returns: result
generate_testsA
Generates tests for the provided code. Args: code: Code to generate tests for. language: Programming language. framework: Test framework (optional - pytest, jest, unittest, etc.). Returns: JSON with test cases, runnable test code, and coverage estimate.
Inputs: code (required), language, framework. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 7 tools
Each tool has a clearly distinct purpose: code fragment analysis, whole file analysis, cache management, code comparison, code explanation, report generation, and test generation. No overlap in functionality.
All tool names follow a consistent verb_noun pattern using snake_case (e.g., analyze_code, generate_tests). No inconsistencies in style.
7 tools is a well-scoped set for code analysis and sanitization tasks, covering the core operations without being overwhelming or too sparse.
The tool surface covers analysis, comparison, explanation, test generation, and reporting. A minor gap is the lack of code transformation or refactoring tools, but the set is reasonable for the stated domain.
Maintenance
Related MCP Connectors
AI code governance and code review for Claude Code, Copilot and Cursor. Checks rules and security.
AI-powered codebase analysis — call graphs, security, dead code, complexity. 150+ tools.
Checks AI-written code for leaked keys and made-up packages, on your machine. Never uploads code.
Scores your code across 12 areas, with findings, fix prompts, and re-assessment in your AI agent
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceA server that enables interaction with PostgreSQL, MySQL, MariaDB, or SQLite databases through Claude Desktop using natural language queries.1-
- AlicenseAqualityDmaintenanceAn MCP server that provides code review functionality using OpenAI, Google, and Anthropic models, serving as a "second opinion" tool that works with any MCP client.134MIT
- AlicenseAqualityDmaintenanceEnables comprehensive security scanning of code projects, detecting vulnerabilities in dependencies, code patterns (XSS, eval, etc.), and exposed secrets, with detailed reports in Spanish prioritized by severity.4MIT
- AlicenseAqualityDmaintenanceAI-powered code review tool that detects AI-generated code defects invisible to traditional linters — hallucinated packages, deprecated APIs, cross-file contradictions, hidden security anti-patterns, and over-engineering. Works as a standalone CLI, GitHub Action, or MCP server. Supports TypeScript, Python, Java, Go, and Kotlin. Free for individuals, no API key required.441Business Source 1.1