Skip to main content
Glama
notasandy

MCP Code Sanitizer

🔍 mcp-code-sanitizer

Claude Desktop、Cursor、またはMCP互換エージェントから直接Groq LLMを使用してコードをレビューする、厳格なAI駆動型コードレビューツールです。

Python FastMCP Groq License

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

✨ 機能

ツール

説明

analyze_code

厳格なコードレビュー — バグ、脆弱性、0〜100のスコア評価

compare_code

2つのバージョンを比較し、リグレッションを検出し、マージまたは変更リクエストを推奨

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 セクションを追加します:

OS

設定パス

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

🤝 コントリビューション

プルリクエストや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