Skip to main content
Glama

Critic-MCP — 冷酷无情的代码评审官

一个开源的模型上下文协议 (MCP) 服务器,用于以只读方式审查其他AI编程助手(Cursor、OpenCode、Cline等)生成的代码。

Critic-MCP 是“第二双眼睛”:它从不修复你的代码,只冷酷无情地给出批评。它只暴露一个工具(review_code),并且完全没有写入文件的能力

它的作用是什么?

review_code 工具将你提交的代码与原始需求(意图)进行对比,并通过LLM生成一份包含以下部分的审查报告:

  • 裁决: APPROVED | MODIFICATION_REQUIRED | REJECTED

  • 缺失需求 — 意图与代码之间的差距

  • 安全问题 — SQL注入、XSS、权限提升、硬编码密钥

  • 边界情况问题 — 空/null输入、边界值、差一错误、竞态条件

  • 性能问题 — N+1查询、内存泄漏、冗余计算

  • 其他问题 + 必须修复项(按优先级排序)

安装 — 两步

要求:Node.js >= 20

步骤 1:身份验证(一次性)

运行交互式设置,其工作方式与 aws configuregh auth login 类似:

npx -y critic-mcp auth

它会询问你使用哪个提供商(gemini / openai / deepseek),提示你输入API密钥,然后将两者保存到你主目录下的 ~/.critic-mcp.json 文件中(Unix系统上权限为 0600)。

步骤 2:将其添加到你的IDE

仅将以下内容添加到你的IDE的MCP设置中:

{ "command": "npx", "args": ["-y", "critic-mcp"] }

请参阅 AI助手集成 部分以获取客户端特定详情。就是这样 — 你的密钥现在统一存放在一个位置,位于所有IDE配置之外。

密钥永远不会写入IDE配置。当服务器启动时,它首先检查 process.env,然后检查 ~/.critic-mcp.json;如果两个地方都找不到密钥,它会引导你运行 npx critic-mcp auth

本地开发(从源码安装)

git clone https://github.com/layermedya/Critic-MCP.git
cd Critic-MCP
npm ci
npm run build
node dist/index.js auth   # authenticate against your own build

命令

npm run build       # TypeScript compilation
npm run typecheck   # Type checking
npm test            # Vitest unit tests
npm run test:watch  # Tests in watch mode
npm start           # Start the server on stdio
npm run inspect     # Manual testing in the browser via MCP Inspector

环境变量(可选)

以下所有变量都是可选的;获取API密钥的正常途径是 npx critic-mcp auth。环境变量始终优先于配置文件(适用于CI/服务器环境)。

变量

描述

CRITIC_PROVIDER

geminiopenaideepseek(回退到 ~/.critic-mcp.json 中的选择,然后再回退到 gemini

GEMINI_API_KEY

Gemini 密钥(设置后将覆盖文件中的值)

OPENAI_API_KEY

OpenAI/DeepSeek 密钥(设置后将覆盖文件中的值)

GEMINI_MODEL

Gemini 模型名称(默认:gemini-3.6-flash

OPENAI_MODEL

模型名称(默认:gpt-4o-mini, deepseek 使用 deepseek-chat

OPENAI_BASE_URL

DeepSeek 等的基础URL(deepseek 默认为 https://api.deepseek.com

CRITIC_TIMEOUT_MS

LLM请求超时(默认:120000

CHUNK_SIZE

分块限制(默认:30000 个字符)

CRITIC_CONCURRENCY

分块审查期间的并行请求数(默认:3

CRITIC_CONFIG_PATH

覆盖配置文件位置(默认:~/.critic-mcp.json

AI助手集成

以下所有配置均不包含任何密钥;你通过上面的 auth 命令(步骤1)进行一次身份验证即可。npx 要求包已发布到npm;对于本地克隆,你可以改用 "command": "node", "args": ["ABSOLUTE_PATH/dist/index.js"]

Cursor

在项目级别的 .cursor/mcp.json(或全局的 ~/.cursor/mcp.json)中:

{
  "mcpServers": {
    "critic": {
      "command": "npx",
      "args": ["-y", "critic-mcp"]
    }
  }
}

或者:设置 → MCP → 添加新的MCP服务器,然后粘贴JSON。

OpenCode

在项目级别的 .opencode/opencode.json 或全局的 ~/.config/opencode/opencode.json 中:

{
  "mcp": {
    "critic": {
      "type": "local",
      "command": ["npx", "-y", "critic-mcp"],
      "enabled": true
    }
  }
}

OpenCode 使用 mcp 键(而非 mcpServers)和 environment 字段(而非 env);command 必须是一个数组。你不再需要将密钥写入 environment 块。

Cline(VS Code扩展)

打开Cline面板 → MCP 服务器 标签页 → 编辑全局MCP编辑项目MCP,然后编辑JSON:

{
  "mcpServers": {
    "critic": {
      "command": "npx",
      "args": ["-y", "critic-mcp"],
      "disabled": false,
      "autoApprove": ["review_code"]
    }
  }
}

autoApprove 允许 Cline 无需确认即可运行 review_code;这是安全的,因为该工具从不写入文件。

Continue.dev

将MCP服务器添加到 ~/.continue/config.json 中(无论你的Continue版本如何,都支持stdio传输):

{
  "experimental": {
    "modelContextProtocolServers": [
      {
        "transport": {
          "type": "stdio",
          "command": "npx",
          "args": ["-y", "critic-mcp"]
        }
      }
    ]
  }
}

手动测试场景

examples/bad_code.js 是一个Express示例,故意包含了SQL注入、XSS和N+1查询;examples/intent.txt 保存了原始需求。从任何客户端按如下方式调用它:

“使用 review_code 工具审查 examples/bad_code.js 中的代码。需求:examples/intent.txt”

期望审查官至少发现以下问题:

  • 严重: db.query("SELECT * FROM users WHERE email = '" ...) — SQL注入

  • 严重: res.send(comment.body) — 存储型XSS

  • 高: 每个用户一个单独的查询 — N+1问题

架构

src/index.ts   -> MCP server, zod validation, error handling + `auth` argv routing
src/cli.ts     -> Interactive authentication flow (`critic-mcp auth`)
src/config.ts  -> Global config (~/.critic-mcp.json) + credential resolution (env → file)
src/prompt.ts  -> Ruthless Critic system prompt + chunked-review prompts
src/llm.ts     -> Provider layer + timeout protection + map-reduce orchestration
src/chunker.ts -> Line-ending based chunking (for code above the limit)

分块审查(map-reduce)

code_snippet 超过 CHUNK_SIZE(默认 30,000 个字符)时,系统会自动切换到 map-reduce 流程:

  1. Map: 代码按行边界拆分;每个块同时发送给LLM(默认 3 个并行请求,可通过 CRITIC_CONCURRENCY 配置)。单个块的失败永远不会影响整个审查。

  2. Reduce: 所有返回的部分分析结果由“合成器”提示合并 — 它从不弱化发现结果,并且当有部分报告了严重问题时从不返回 APPROVED — 最终生成一份最终报告

服务器仅返回字符串报告;它没有写入文件的能力,也绝不向外暴露网络客户端。

许可证

MIT

-
license - not tested
-
quality - not tested
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

  • Hosted MCP server for structured code review passes on human- and AI-written code. Free tier.

  • Scans MCP servers for tool poisoning, prompt injection and supply chain risks.

  • Security scanner for MCP servers. Detect vulnerabilities, prompt injection, and tool poisoning.

View all MCP Connectors

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/layermedya/Critic-MCP'

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