CodePecker
MCP server that reviews and fixes code across four dimensions (security, standards, production readiness, sustainability), runs tests to verify fixes, and provides findings with diffs.
README
CodePecker
An MCP server that reviews a piece of code across four dimensions — security, standards, production readiness, sustainability — automatically fixes the issues, verifies the fix by running the code's tests, and reports what it did. Any MCP-capable agent (Claude Code, Codex, Copilot) can call it as a tool; there's also a CLI for local demos.
review → remediate → run tests → repeat (bounded) → findings + fixed code + diff + citations
How it works
For each of the four dimensions, CodePecker gathers findings two ways:
- Deterministic checks (regex/code) for rules that must be caught reliably —
hardcoded secrets,
eval/unsafe deserialization, bareexcept, missing tests. No LLM, so they never "forget". - An LLM judge for the nuanced rules (input validation, logging, timeouts, N+1 queries, …), with guardrails: it may only cite rules from the batch it was given, any evidence it quotes must appear in the code, and severity/dimension come from the rule metadata — hallucinated findings are dropped in code.
Each rule lives in a markdown file in knowledge_base/ (RAG), tagged
deterministic: true|false so it's enforced by exactly one path. A hand-written,
bounded agent loop then asks the model to remediate and re-runs the tests — a fix
that resolves a finding but breaks the tests is not accepted.
The full "why" behind every decision is in DECISIONS.md.
Setup
Requires Python 3.10+.
git clone <this repo> && cd CodePecker
python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
pip install -e . --no-deps # makes `codepecker` + `python -m codepecker.*` work
cp .env.example .env # then add your key (below)
Keys — the default needs just one. Text runs on Groq (fast Llama 3.3 70B) and
embeddings run locally (no key). Put your Groq key in .env:
GROQ_API_KEY=... # free key at https://console.groq.com/keys
Provider-agnostic via LiteLLM — switch model or provider with no code change,
e.g. CODEPECKER_TEXT_MODEL=openai/gpt-4o (one key does both), or go fully offline
with CODEPECKER_TEXT_MODEL=ollama/llama3.1. See .env.example.
Usage
CLI (local demo)
codepecker examples/sample_bad_code.py
# or: python -m codepecker.cli examples/sample_bad_code.py
Prints the findings, the remediated code, a unified diff, the rules cited, and a
metrics summary. Each run is appended to metrics.jsonl.
Reliable live demo: the loop makes many LLM calls, so a free tier's tokens-per-minute cap can throttle a full run. The loop is resilient — a mid-run rate limit is recorded and the review still completes (with degraded coverage noted) rather than crashing. For a smooth end-to-end demo, use a higher-limit tier or run the text model locally:
CODEPECKER_TEXT_MODEL=ollama/llama3.1(no key, no limits).
MCP server (in an agent)
Run it over stdio:
python -m codepecker.server
Connect it to an MCP client with this config (Claude Desktop / Codex / Copilot use the same shape):
{
"mcpServers": {
"codepecker": {
"command": "/absolute/path/to/.venv/bin/python",
"args": ["-m", "codepecker.server"],
"env": { "GROQ_API_KEY": "your-key" }
}
}
}
For Claude Code:
claude mcp add codepecker -- /absolute/path/to/.venv/bin/python -m codepecker.server
The server exposes one tool, review_and_remediate(code, language).
Evaluation
python eval/run_eval.py
Runs CodePecker over the labeled golden set (eval/golden/) and reports
precision/recall/F1 per dimension, remediation resolution + test-pass rates, and mean
iterations/latency; writes eval/report.json. This is the "how do I know it's good?"
evidence and is meant to run in CI. (It drives the full loop over every sample, so use
a decent rate-limit tier.)
Design decisions (the short "why")
| Decision | Why |
|---|---|
| MCP server, not a bot/CI check | Reusable across agents, and reviews in the loop rather than post-hoc |
| Hand-written loop, no LangChain | Bounded task; transparent and testable control flow |
| RAG over fine-tuning for rules | Rules stay editable, auditable, and citable (markdown files) |
| Deterministic secrets/eval/except vs LLM for nuance | Reliability where it's non-negotiable, flexibility where it's fuzzy |
| Tests gate success | A fix that breaks behavior is a failure, not a fix |
| Judge guardrails (constrained citations + evidence grounding) | Hallucinated findings are dropped by code, not trusted |
One LLM seam (LiteLLM behind LLMClient) |
Swapping provider — or going offline — is a config change |
| Sandboxed test run (subprocess + timeout) | Executing untrusted code is a security boundary |
Full detail — every alternative considered and every trade-off — in
DECISIONS.md.
Project layout
src/codepecker/
config.py env-driven model IDs + tuning constants
types.py LLM Protocols (DIP/ISP) + the Finding type
llm_client.py the only module that talks to a provider (LiteLLM)
vector_store.py ChromaDB adapter (RAG index)
knowledge/loader.py parse + embed the markdown knowledge banks
tools/
deterministic_checks.py code checks, keyed by rule id
judge.py batched, guardrailed LLM judge
run_tests.py sandboxed pytest runner
agent.py review_and_remediate() — the bounded loop
metrics.py append-only metrics log + summary
cli.py local demo runner
server.py FastMCP server (stdio)
knowledge_base/ the rules: security/ standards/ readiness/ sustainability/
eval/ golden samples + run_eval.py
tests/ the test suite
Testing
pytest -q # 85 offline tests (local embeddings, faked LLM)
pytest -m "live or not live" # + the 1 live acceptance test (needs GROQ_API_KEY)
The default suite is fully offline and deterministic; the one live test is opt-in.
Non-goals / next steps
MVP simplifications, called out honestly (see DECISIONS.md):
- Sandbox is a subprocess + timeout, not a container — production wants gVisor/a microVM with no network and resource limits.
- Deterministic checks are regex-based — production would use AST analysis.
- Local embeddings (all-MiniLM-L6-v2) trade recall for zero keys — swap in a hosted embedder for higher-quality retrieval at scale.
- Not yet: metadata-routed retrieval for very large rule sets, a metrics dashboard, real GitHub integration, runtime energy profiling, remote HTTP/Cloud Run deploy.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。