Skip to main content
Glama
notasandy

MCP Code Sanitizer

🔍 mcp-code-sanitizer

一款严格的 AI 代码审查工具,可通过 Claude Desktop、Cursor 或任何兼容 MCP 的代理直接使用 Groq LLM 运行您的代码。

Python FastMCP Groq License

Claude Desktop  ──MCP──►  code-sanitizer  ──REST──►  Groq API
                            (server.py)               (llama-3.3-70b)

✨ 功能

工具

描述

analyze_code

严格的代码审查 — 错误、漏洞、评分 0–100

compare_code

比较两个版本,发现回归问题,建议合并/请求更改

explain_code

针对初级/中级/高级受众的分步解释

generate_tests

生成 pytest/jest/go 测试,包含正常路径、边界情况和安全测试

analyze_file

通过并行分块分析磁盘上的整个文件

generate_report

根据任何分析结果生成精美的 HTML 报告

cache_info

缓存统计信息和清理

响应示例

{
  "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-sanitizer

2. 创建虚拟环境并安装依赖

python -m venv venv

# macOS / Linux
source venv/bin/activate

# Windows
venv\Scripts\activate

pip install -r requirements.txt

3. 添加您的 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

~/Library/Application Support/Claude/claude_desktop_config.json

Windows

%APPDATA%\Claude\claude_desktop_config.json

Linux

~/.config/Claude/claude_desktop_config.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"
      }
    }
  }
}

重启 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 文件进行:

变量

默认值

描述

GROQ_API_KEY

必需。在 console.groq.com 获取

GROQ_MODEL

llama-3.3-70b-versatile

Groq 模型

CACHE_TTL

3600

缓存 TTL(秒)

CACHE_MAX

200

最大缓存条目数

可用的 Groq 模型

模型

速度

质量

llama-3.3-70b-versatile

⚡⚡

⭐⭐⭐⭐⭐ (默认)

llama-3.1-8b-instant

⚡⚡⚡

⭐⭐⭐

mixtral-8x7b-32768

⚡⚡

⭐⭐⭐⭐


📦 要求

fastmcp>=2.3.0
httpx>=0.27.0
python-dotenv>=1.0.0

🤝 贡献

欢迎提交 PR 和 Issue!特别关注:

  • 支持其他 LLM 提供商(OpenAI, Anthropic)

  • 新工具(安全审计、依赖检查、复杂度分析)

  • 提示词改进


📄 许可证

MIT — 随心所欲地使用。如果能给个 GitHub 星标将不胜感激 ⭐


🔗 链接

Install Server
A
license - permissive license
B
quality
B
maintenance

Maintenance

Maintainers
Response time
Release cycle
1Releases (12mo)

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/notasandy/mcp-code-sanitizer'

If you have feedback or need assistance with the MCP directory API, please join our Discord server