Code Auditor Mcp

io.github.BenAHammond由 GitHub 账号 BenAHammond 发布v5.0.2更新于 Oct 24, 2026

Enforces architectural invariants and code quality rules inside your AI agent's edit loop.

已验证Streamable HTTP可网页运行知识与记忆开发者工具

概览

AI 生成的概览

Code Auditor MCP 提供规则查询、问题症状解释和安装命令,服务于在 AI 代理编辑流程中执行项目规则的代码审计工具。

可以做什么
  • 查询 Code Auditor 规则与分析器,返回类型、说明、默认严重级别、检测方式和阈值
  • 把自然语言描述的问题(如应用变慢、硬编码密码)映射到相关规则及修复建议
  • 提交新规则请求,并提示先确认无重复规则、提供最小正反示例
  • 按指定 AI 代理或全部代理返回准确的安装命令
适用场景
当你已使用或准备使用 Code Auditor,希望助手解释其规则、把描述的代码问题对应到具体规则、提出新规则,或生成针对某个代理的安装命令时适用。
运行要求
可作为远程端点运行,也可作为本地 npm 包通过 stdio 运行。README 说明需 Node 18+,Node 23.4+ 可免原生编译;更早版本需批准可选的 better-sqlite3 依赖。MCP 服务器本身未声明认证或环境变量。
安装前请注意
该服务器主要返回参考与安装信息,但底层工具会向你的 AI 编程工具写入配置和钩子,并可能阻止编辑。README 描述了可选的匿名反馈服务(CODE_AUDITOR_TELEMETRY),会发送忽略理由和结构签名,默认关闭。应用生成的配置前请先检查。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Code Auditor Mcp,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Web executable,通过 Streamable HTTP。 远程服务在工作区中配置后即可从网页运行时运行。

交给智能体安装

把这段提示词粘贴到 Claude Code、Codex、Cursor 等智能体,或 SourceWeft 对话中。智能体会读取该服务器的安装指南,先向你展示发布者、端点和登录方式,经你同意后再把它添加到你的客户端。密钥不会写进任何命令。

阅读 https://sourceweft.com/mcp/io.github.BenAHammond%2Fcode-auditor-mcp/install.md,并按其中说明把这个 MCP 服务器接入我的客户端。修改任何配置之前,先告诉我它的发布者、端点和登录方式,等我确认。不要把 API 密钥写进命令或我会提交的文件;问我密钥应从哪里获取。

查看智能体所依据的安装指南

其他 MCP 客户端

把它添加到你客户端的 mcpServers 配置中。

{
  "mcpServers": {
    "code-auditor": {
      "type": "http",
      "url": "https://www.codeauditormcp.com/api/mcp"
    }
  }
}

README

Code Auditor

Architectural invariants enforced inside your AI agent's edit loop. When the agent writes code that breaks a project rule, Code Auditor catches it and blocks the edit. The agent sees the rule's message and fixes itself.

Install

bash
npm install -g code-auditor-mcpcode-audit install --agent all

Two commands to install everywhere. code-audit install --agent all copies the skill to every AI coding tool on your machine. Use --agent for specific tools.

What you get per tool: the skill (SKILL.md), MCP server access, and hook wiring where the tool supports it (blocking on Claude Code and Codex, advisory on Cursor).

bash
code-audit install --list   # see the support matrix

Claude Code users can also install via plugin:

bash
claude plugin marketplace add BenAHammond/code-auditor-mcpclaude plugin install code-auditor

The hook auto-installs the auditor on first use via npx.

Requirements

  • Node 18+ to run. Node 23.4+ gets the zero-native-install path: Code Auditor uses the built-in node:sqlite module, so nothing needs to compile or download a prebuilt binary on install.
  • On older Node (18–23.3), Code Auditor falls back to better-sqlite3, an optional dependency whose install script must be approved once on npm 11.2+/12 (they block dependency install scripts by default): npm install-scripts approve better-sqlite3 && npm rebuild better-sqlite3 (with pnpm: pnpm approve-builds, then select better-sqlite3).

Configuration

Project-level settings live in .codeauditor.json (invariant rules, analyzer settings, and thresholds). Eleven environment variables additionally tune process-scoped behavior — worker pool size, daemon and job-queue timeouts, the index location, the SQLite backend, and the UI port.

VariablePurposeAccepted valuesDefault
CODE_AUDITOR_WORKERSPhase-model worker pool size for per-file fan-out. 1 forces the serial path for byte-identical reports.Positive integermax(1, cpus − 1)
CODE_AUDITOR_RULE_TIMINGPer-rule wall-time accounting (one accumulated timer per rule ID, surfaced in the report).1 enables; unset disablesOff
CODE_AUDITOR_DAEMON_IDLE_MSIdle timeout before the daemon shuts down.Positive finite ms; invalid → default300000 (5 min)
CODE_AUDITOR_DAEMON_LEASE_TTL_MSDaemon heartbeat lease TTL.Finite ms; blank/0 → default60000 (60 s)
CODE_AUDITOR_DATA_DIROverrides the code-index database directory.Directory path (trimmed; blank → default)user-level OS cache
CODE_AUDITOR_EXIT_ON_FATALExit the MCP server on an uncaught exception / unhandled rejection.1 or trueOff
CODE_AUDITOR_JOB_TIMEOUT_MSPer-job timeout for queued audits.Finite ms, clamped to 60s–4h; below the floor → default1800000 (30 min)
CODE_AUDITOR_JOB_LEASE_TTL_MSHeartbeat lease TTL for reclaiming stale running job rows.Strictly positive finite ms; invalid → default30000 (30 s)
CODE_AUDITOR_MAX_RUNNING_JOBSMax concurrently running queued audit jobs.Integer ≥ 1; invalid → default1
CODE_AUDITOR_SQLITE_BACKENDForces a SQLite backend. An invalid value is reported as invalid and rejected — never silently probed past.node-sqlite | better-sqlite3Auto (probe)
MCP_UI_PORTHTTP UI server port (--ui).Port number; invalid → default3001

When CODE_AUDITOR_DATA_DIR is set, the index is scoped per project (<dir>/projects/<sha256(root)[:16]>/index.db) so projects can't leak data into each other. When unset, the index lives in a user-level OS cache (<os_cache>/code-auditor/projects/<hash>/index.db) so it never lands inside the audited repo.

Prompt examples

"Index the codebase and run a full audit, then walk the violations file-by-file with code-audit next-file."

"Create a .codeauditor.json that bans lodash imports and prevents src/languages/ from importing anything in src/analyzers/."

"Run a full audit, fix the highest-priority file, and repeat code-audit next-file until the tree is clean."

"Sync the code index and audit only what changed vs main."

"Add an ast-pattern rule that blocks new Function(...)."

"Add a naming rule requiring hooks in src/hooks/ to start with use."

"Add a call-constraint so chargeCustomer() in src/services/payment.ts can only be called from src/api/."

Rule kinds

Seven kinds. The agent writes them to .codeauditor.json. Bad configs fail the audit, not silently.

KindWhat it blocks
import-banBanned module imports
call-constraintFunction calls from unauthorized files
module-boundaryImports across module boundaries
namingExported symbols not matching a pattern
ast-patternAST nodes matching an ast-grep pattern
style-mechanismUnapproved style mechanisms per file/glob
no-raw-valuesHardcoded values for specific CSS properties

Works with your agent

One skill, one CLI, one MCP server. Every agent gets the same audit engine — the hook contract is the only difference.

AgentSkillHooks / BlockingMCPVerified
Claude CodePlugin or code-audit installYes — blockingYes2026-07-19
Cursorcode-audit install --agent cursor (project-only)AdvisoryYes2026-07-19
Codexcode-audit install --agent codex + pluginYes — blockingYes2026-07-19
Gemini CLIcode-audit install --agent geminiNoYes2026-07-19
VS Code / Copilotcode-audit install --agent agentsNoYes2026-07-19
Other SKILL.md toolscode-audit install --agent agentsNoYes2026-07-19
ZCodecode-audit install --agent zcodeNo (plugin-scoped)Yes2026-09-10

MCP config generation covers a wider set than skill install. The MCP server's generate tool writes a client config file for any of claude, codex, cursor, gemini, copilot, continue, awsq (AWS Q Developer), codeium (Codeium/Windsurf), vscode, cline, and zcode. Four of those — Continue, AWS Q Developer, Codeium/Windsurf, and Cline — are MCP-only: they have no file-based skill or hook path, so they connect through the generate tool rather than code-audit install.

Hook behavior: Blocking means the diff-scoped changed gate is tripped — an invariant rule that declares gating: true (a binary, per-rule flag, independent of severity) blocks the edit from landing (the agent sees the violation and fixes inline). Advisory means violations are reported through the strongest available feedback channel but the edit has already occurred. Cursor's afterFileEdit hook is fire-and-forget with no output consumption. MCP is available everywhere for shell-less use.

Findings: Deterministic vs Advisory

Code Auditor's built-in rules fall into two categories:

CategoryMeaningExamples
DeterministicStructural fact — an engineer would act on every findingsingle-responsibility (300-line functions), solid/method-complexity (cyclomatic complexity > 20), solid/class-size (40+ method classes), dependency-inversion (concrete imports where an interface exists)
AdvisoryHeuristic signal — may be wrong depending on domainsql-injection-risk (AST-level string-pattern matching without type info), missing-org-filter (domain-specific — assumes SaaS tenant isolation), unknown-table (requires user-provided schema), dry/duplicate (token-identical blocks)

Deterministic rules ship at critical or severe. Advisory rules ship at severe or high. Rules proven near-zero precision on a real corpus are disabled by default (off) — users opt in when the rule matches their domain.

Recalibration

Built-in severity defaults are recalibrated from real-corpus triage. The current defaults reflect measurement on three corpora: this tool's own codebase, Gin, and Excalidraw. Six data-access rules that produced near-zero precision across all three corpora are disabled by default.

Every disabled rule documents what corpus it would be useful on. Users can restore any rule via severityOverrides in .codeauditor.json:

json
{  "severityOverrides": {    "sql-injection-risk": "critical",    "missing-org-filter": "severe",    "loop-query": "severe"  }}

Severity overrides apply globally (before per-directory path profile caps). Setting a rule to "off" removes it from the output entirely.

SQL Injection Detection

The sql-injection-risk rule is disabled by default (off) after recalibration. On the self-audit corpus, it produced 0% precision — the rule misinterpreted TypeScript pattern-matching code (string constants like 'SELECT', 'FROM', 'WHERE' used for the tool's own SQL detection) as database queries. On the Gin and Excalidraw corpora, precision was also near zero.

When to re-enable it: your project's SQL is constructed via string concatenation or template literals in functions whose sole purpose is query assembly. The rule detects those patterns. For codebases using ORMs or parameterized queries exclusively, the rule produces noise.

To re-enable and block on SQL injection:

json
{  "severityOverrides": {    "sql-injection-risk": "critical"  }}

With sql-injection-risk: critical (and the rule marked gating), your agent's hook will block edits that introduce AST-level SQL injection patterns.

Dismissals

Every finding is a measurement, not a verdict — but measurements are occasionally wrong. When the agent hits a false positive (the rule is right in general, wrong for this specific code), it can dismiss that one instance rather than work around it:

bash
code-audit dismiss <fingerprint> --reason "generated code, not hand-written"

The <fingerprint> comes from the JSON report (every violation carries a fingerprint field). A written --reason is required, and the dismissal clears exactly one finding — rule + file + symbol — so the same rule still fires everywhere else. Dismissals live in a committed .codeauditor.dismissals.json, reviewable in a diff.

Anonymous dismissal feedback (opt-in)

The reason an agent gives for dismissing a finding is the most useful signal for improving the rules. Code Auditor can send dismissed findings to an anonymous feedback service that collects them.

It is off by default and turned on only by an explicit opt-in, via any of three methods (in precedence order):

  1. per-invocation — code-audit dismiss --telemetry … sends just that one dismissal; --no-telemetry suppresses one.
  2. environment — CODE_AUDITOR_TELEMETRY=1 (or 0) as a machine-level default for headless/CI runs.
  3. persisted — code-audit telemetry status|enable|disable (or the telemetry MCP tool), which records the choice in your user config dir.

telemetry enable needs no arguments: it opts in against the built-in service endpoint (overridable for self-hosting). Opting in generates an anonymous install ID: a random value generated locally, never derived from your machine, user, or project, used only to group submissions by source.

What is sent — the tool version, the rule ID, the urgency level, the dismissal reason exactly as typed, a structural AST signature (grammar kinds only, never their contents), a coarse language hint, a timestamp, and the anonymous install ID. What is never sent — source code, identifiers, literals, file paths, or anything derived from your code or environment. Sending is best-effort: offline or an unreachable endpoint is silent and never blocks an edit or fails a gate.

Style Intelligence

Code Auditor indexes every style declaration in your project — CSS, SCSS, Tailwind, inline styles, and CSS-in-JS. The styles rules read global distributions and flag fragmentation that no single-file linter can see.

7 detectors, 10 rule IDs:

DetectorWhat it finds
Value driftNear-duplicate color values (delta-E < 2.0) and exact-value outliers where one value dominates
Off-scaleMargin/padding/gap/font-size values not on the inferred project scale
Undefined classclassName values with no matching CSS selector or Tailwind utility
Token bypassHardcoded values that match a design token but don't reference it
Mechanism fragmentationSame (property, value) delivered via ≥ 3 mechanisms (CSS, inline, Tailwind)
Declaration-set similarityTwo CSS rule blocks with > 90% identical declarations
Z-index sprawlProject-wide z-index inventory — too many distinct values or orphan singletons

The styles rules read from a project-wide SQLite index, so scoped runs (changed files only) still compare against the full project baseline. A fresh #273828 drift color in a scoped run is caught against the full corpus of #1e2328 values.

Style invariant rules:

json
{  "rules": [    {      "kind": "style-mechanism",      "message": "Only Tailwind in src/components/",      "allow": ["tailwind"],      "path": "src/components/**"    },    {      "kind": "no-raw-values",      "message": "No raw colors in src/pages/ — use design tokens",      "properties": ["color", "background-color"],      "path": "src/pages/**"    }  ]}

Style search operators — search by property, value, mechanism, or token:

bash
code-audit search "css:margin-top value:16px"          # specific valuecode-audit search "mechanism:inline css:color"          # inline color declarationscode-audit search "token:--color-primary"                # bypassing a design token

The React rules also gain raw-element detection: if your project has a Button wrapper, raw <button> usages outside Button's definition become severe findings.

License

MIT

来源:README.md,提交 b792894

工具

4

get_install_commands

Get Install Commands

Return the exact install commands for Code Auditor for a given AI agent. Call this when a user asks how to install Code Auditor, or asks for the command for a specific agent (claude, cursor, codex, gemini, agents, zcode, or all).

输入参数agent必填

lookup_rule

Look Up Rule

Return the rule kind, description, default severity, detection method, and threshold for a given Code Auditor rule or analyzer. Call this when a user asks what a specific rule does (e.g. import-ban, sql-injection, n+1).

输入参数rule_id必填

explain_symptom

Explain Symptom

Map a natural-language symptom (e.g. 'my app is slow', 'hardcoded password', 'infinite react loop') to the relevant Code Auditor rule(s) and their fixes. Call this when a user describes a problem rather than naming a rule.

输入参数symptom必填

request_rule

Request Rule

Request a new Code Auditor rule. Call lookup_rule or explain_symptom first to confirm no existing rule covers it. Provide a minimal example that should be flagged and a corrected example that should not. Reduce both to the smallest code that shows the difference, and remove secrets and proprietary identifiers. Returns a receipt id.

输入参数title必填signal必填symptom必填languages必填toolVersioncleanExample必填firingExample必填

版本历史

3
  1. v5.0.2最新Oct 10, 2026
  2. v5.0.1Oct 9, 2026
  3. v2.0.2Sep 16, 2026

评分

已满足适用检查项的 100%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通必需25 分
  • 已声明认证方式必需10 分
  • 已列出工具必需15 分
  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分