Skip to main content

Strict AI code reviewer MCP server powered by Groq — finds bugs, vulnerabilities and security issues

Project description

mcp-code-sanitizer

Strict AI-powered code reviewer for Claude Desktop, Cursor, and any MCP-compatible agent. Finds bugs, vulnerabilities, and security issues — powered by Groq (free API).

Python FastMCP Groq License smithery badge

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

demo


Features

Tool What it does
analyze_code Strict review — bugs, security issues, score 0–100
compare_code Compares two versions, detects regressions, recommends merge/request_changes
explain_code Step-by-step explanation for junior / middle / senior audience
generate_tests Generates pytest / jest / go test — happy path, edge cases, security
analyze_file Analyzes a whole file from disk with parallel chunking
generate_report Builds an HTML report from any analysis result
cache_info Cache statistics and clearing

Example output

{
  "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"]
}

Quick Start

1. Clone and install

git clone https://github.com/notasandy/mcp-code-sanitizer
cd mcp-code-sanitizer

python -m venv venv
source venv/bin/activate   # Windows: venv\Scripts\activate

pip install -r requirements.txt

2. Add your Groq API key

Get a free key at console.groq.com/keys — no credit card required.

cp .env.example .env
# edit .env and set GROQ_API_KEY=gsk_...

3. Test the server

python server.py

Silence means it's working — the server is listening for MCP requests via stdio.


Connect to Claude Desktop

OS Config path
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"
      }
    }
  }
}

Windows example: "command": "C:\\Users\\YourName\\mcp-code-sanitizer\\venv\\Scripts\\python.exe"

Restart Claude Desktop — you'll see the tools icon in chat.


Connect to Cursor

Create .cursor/mcp.json in your project root:

{
  "mcpServers": {
    "code-sanitizer": {
      "command": "/full/path/to/venv/bin/python",
      "args": ["/full/path/to/server.py"],
      "env": {"GROQ_API_KEY": "gsk_your_key_here"}
    }
  }
}

GitHub Action — automatic PR review

Add AI code review to any repository in 5 lines.
The action posts a structured comment on every PR with score, issues, and fix suggestions.

# .github/workflows/ai-review.yml
name: AI Code Review
on:
  pull_request:
    types: [opened, synchronize]

permissions:
  contents: read
  pull-requests: write

jobs:
  review:
    runs-on: ubuntu-latest
    steps:
      - uses: notasandy/mcp-code-sanitizer@main
        with:
          groq_api_key: ${{ secrets.GROQ_API_KEY }}

Add GROQ_API_KEY to your repository secrets → Settings → Secrets → Actions.

The action automatically:

  • Reviews only changed files (up to 10 per PR)
  • Posts a score and structured issue list as a PR comment
  • Fails the check if critical issues are found

Usage in chat

After connecting, just write naturally in Claude Desktop or Cursor:

Review this code for vulnerabilities:

def get_user(user_id):
    query = f"SELECT * FROM users WHERE id = {user_id}"
    return db.execute(query)

Or call tools explicitly:

analyze_file /path/to/my_script.py
generate_tests for this function: ...
compare_code — before vs after refactor, did it get better?
generate_report and save to /tmp/report.html

Architecture

mcp-code-sanitizer/
├── server.py          # FastMCP entry point
├── config.py          # Constants — keys, limits, extension map
├── groq_client.py     # Async Groq client with auto-retry on 429
├── cache.py           # In-memory LRU 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 output

Configuration

All settings via .env or environment variables:

Variable Default Description
GROQ_API_KEY Required. Get at console.groq.com
GROQ_MODEL llama-3.3-70b-versatile Groq model to use
CACHE_TTL 3600 Cache TTL in seconds
CACHE_MAX 200 Max cached entries

Available Groq models

Model Speed Quality
llama-3.3-70b-versatile Fast Best (default)
llama-3.1-8b-instant Fastest Good
mixtral-8x7b-32768 Fast Great

Testing with MCP Inspector

fastmcp dev inspector server.py

A browser UI opens with full tool testing interface.


Requirements

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

Python 3.10+


Contributing

PRs and Issues are welcome. Most wanted:

  • Support for other LLM providers (OpenAI, Anthropic)
  • New tools: dependency audit, complexity score, docstring generator
  • Prompt improvements and new language support

License

MIT — do whatever you want. A star would be appreciated.


Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_code_sanitizer-0.1.1.tar.gz (7.3 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_code_sanitizer-0.1.1-py3-none-any.whl (7.4 MB view details)

Uploaded Python 3

File details

Details for the file mcp_code_sanitizer-0.1.1.tar.gz.

File metadata

  • Download URL: mcp_code_sanitizer-0.1.1.tar.gz
  • Upload date:
  • Size: 7.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for mcp_code_sanitizer-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2744b9cf844fae05cddb9f0a255a4045e37c0a280aee956f0c76de1ac28e6e79
MD5 db99548d8de4dbff7df93021eb102392
BLAKE2b-256 1b60b229a3218adea02c98c03dd0215603d41f5ad91faa24925489f13c02ef1c

See more details on using hashes here.

File details

Details for the file mcp_code_sanitizer-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for mcp_code_sanitizer-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e8cbff1763fd118182ebadba50d67ab89756e0d2044c1930a6219d12d2fe585a
MD5 5c1c754b73155574c824af5028259838
BLAKE2b-256 f4a1b1506b969c566633d0e18ea2ab1f8e0d9e2b542eeb01b412f60ec5a01dc5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page