mcp质量门
](https://www.npmjs.com/package/mcp-quality-gate)   ](https://nodejs.org/) 
MCP服务器的质量门。 喜欢 npm audit 对于包裹,但对于 模型上下文协议 服务器。
当LLM连接到您的MCP服务器时,它信任您公开的任何内容。错误的工具模式意味着错误的工具调用。缺少描述意味着模型只能猜测。50多种工具充斥着上下文窗口。泄露的环境变量暴露了秘密。mcp质量门在一个命令中捕获所有这些。
npx mcp-quality-gate validate "npx -y @modelcontextprotocol/server-filesystem /tmp"一个命令。四个维度。0-100分。
它捕获了什么
mcp质量门在四个维度上对每个mcp服务器进行评分:
| 尺寸 | 重量 | 它检查什么 | 为什么重要 |
|---|---|---|---|
| 合规 | 40pts | 协议一致性——初始化、工具列表、工具调用、资源、提示、错误处理 | 不符合规范的服务器会破坏每个客户端 |
| 质量 | 25分 | 参数描述、描述长度、弃用工具、重复模式、模式一致性 | LLM需要良好的描述才能进行正确的工具调用。72%未记录的参数=72%的猜测 |
| 安全 | 20分 | 环境变量暴露、代码执行表面、无警告的破坏性操作 | 工具在用户权限下运行。A. get-env 工具泄露了机器上的每一个秘密 |
| 效率 | 15分 | 工具计数,模式令牌总成本 | 每个工具模式都会占用上下文。21个工具,3000个代币,实际对话的空间更小 |
安装
npm install -g mcp-quality-gate需要Node.js>=22。
用法
# Test any stdio MCP server
mcp-quality-gate validate "npx -y @modelcontextprotocol/server-filesystem /tmp"
# Test with environment variables
mcp-quality-gate validate "npx -y @supabase/mcp-server-supabase@latest --read-only --project-ref REF" \
--env "SUPABASE_ACCESS_TOKEN=your-token"
# JSON output for CI/CD pipelines
mcp-quality-gate validate "./my-server" --reporter json --output report.json
# Fail CI if score is below threshold
mcp-quality-gate validate "./my-server" --threshold 80
# Test HTTP/SSE servers
mcp-quality-gate validate "http://localhost:3000/mcp" --transport http真实世界基准
针对官方MCP参考服务器进行了测试(2026年4月)。这些是来自实时服务器连接的真实结果,而不是合成数据:
| 服务器 | 得分 | 合规性 | 质量 | 效率 | 安全性 | mcp质量门发现了什么 |
|---|---|---|---|---|---|---|
| 记忆 | 98 | 40/40 | 23/25 | 15/15 | 20/20 | 50%的参数没有描述——LLM必须猜测参数格式 |
| 顺序思维 | 98 | 40/40 | 23/25 | 15/15 | 20/20 | 500+字符描述--在单个工具上浪费上下文标记 |
| 一切 | 88 | 40/40 | 23/25 | 15/15 | 10/20 | get-env 工具泄漏环境变量。跨工具的模式重复 |
| 文件系统 | 81 | 40/40 | 11/25 | 15/15 | 15/20 | 72%的参数没有记录, read_file 标记为已弃用但仍在列出的重复架构 |
| 剧作家 | 81 | 40/40 | 19/25 | 12/15 | 10/20 | 21个工具消耗3000多个模式令牌、代码执行界面、简短描述 |
测试的服务器: @modelcontextprotocol/server-memory, @modelcontextprotocol/server-sequential-thinking, @modelcontextprotocol/server-everything, @modelcontextprotocol/server-filesystem, @anthropic/mcp-server-playwright.
输出示例
mcp-quality-gate v0.1.0
Server: npx -y @modelcontextprotocol/server-filesystem /tmp
lifecycle
PASS Server reports name and version (0ms)
PASS Server reports capabilities (0ms)
PASS Server responds to ping (1ms)
tools
PASS Server lists tools without error (5ms)
PASS Tool definitions have required fields (6ms)
PASS Tool names follow naming convention (8ms)
PASS Tool inputSchema has type object (4ms)
PASS Can call a listed tool (10ms)
PASS Calling nonexistent tool returns error (1ms)
PASS Tool descriptions are present (8ms)
resources
SKIP Server lists resources without error
SKIP Resource definitions have required fields
SKIP Resource descriptions are present
SKIP Can read a listed resource
prompts
SKIP Server lists prompts without error
SKIP Prompt definitions have required fields
SKIP Can get a listed prompt
efficiency
14 tools, ~3057 schema tokens
quality
Param description coverage: 28%
Deprecated: read_file
Duplicates: read_file, read_text_file
CRIT 18 of 25 parameters lack descriptions (72%)
CRIT 1 deprecated tool(s) still listed: read_file
WARN Tools with identical schemas: read_file, read_text_file
security
WARN "write_file" performs destructive operations — description warns of risk
Results: 10 passed, 7 skipped (45ms)
Score: 81/100
compliance 40/40 | quality 11/25 | efficiency 15/15 | security 15/20合规性测试(17)
mcp质量门连接到您的服务器,进行真正的协议调用,并验证行为。这不是静态分析,而是一个实时测试套件,它实际上用生成的参数调用您的工具。
| 类别 | 测试 | 已验证的内容 |
|---|---|---|
| 生命周期 | 3 | 服务器初始化(名称、版本、功能),ping响应 |
| 工具 | 7 | 工具列表、必填字段、命名约定、模式结构、, 使用自动生成的参数进行实时工具调用,不存在的工具的错误处理,描述存在 |
| 资源 | 4 | 资源列表、必填字段、描述、资源读取 |
| 提示 | 3 | 提示列表、必填字段、提示检索 |
当服务器没有通告功能时,会跳过测试(而不是失败)。仅使用工具的服务器不会因缺少资源而失去分数。
完整测试参考
| ID | 测试 | 严重性 |
|---|---|---|
lifecycle-init-01 | 服务器报告名称和版本 | 严重 |
lifecycle-init-02 | 服务器报告功能 | 关键 |
lifecycle-init-03 | 服务器响应ping | 高 |
tools-list-01 | 服务器列出的工具没有错误 | 严重 |
tools-list-02 | 工具定义有必填字段 | 关键 |
tools-list-03 | 工具名称遵循命名约定 | 中等 |
tools-list-04 | 工具输入模式的类型为“object” | 高 |
tools-call-01 | 可以调用列出的工具 | 关键 |
tools-call-02 | 调用不存在的工具返回错误 | 高 |
tools-call-03 | 工具说明存在 | 中等 |
resources-list-01 | 服务器列出资源时没有错误 | 严重 |
resources-list-02 | 资源定义有必填字段 | 关键 |
resources-list-03 | 存在资源描述 | 中等 |
resources-read-01 | 可以读取列出的资源 | 关键 |
prompts-list-01 | 服务器列出的提示没有错误 | 严重 |
prompts-list-02 | 提示定义有必填字段 | 关键 |
prompts-get-01 | 可以得到列出的提示 | 严重 |
质量分析
检查您的工具模式如何帮助LLM理解和使用您的工具:
| 检查 | 它捕获了什么 |
|---|---|
| 参数描述覆盖率 | 没有描述的参数——LLM工具调用错误的首要原因 |
| 描述质量(短) | 20个字符以下的描述——对于LLM来说太简短了,无法理解意图 |
| 描述质量(冗长) | 超过500个字符的描述——浪费上下文标记 |
| 弃用工具检测 | 标记为弃用但仍在列表中的工具--混淆了工具选择 |
| 重复工具检测 | 具有相同输入模式的工具——建议使用冗余或版本化的工具 |
| 必需/默认不匹配 | 具有默认值的必需参数——相互矛盾的模式信号 |
证券分析
对工具定义进行静态分析,以检测常见的安全反模式:
| 检查 | 它捕获了什么 |
|---|---|
| 环境变量暴露 | 工具如 get-env 向法学硕士泄露秘密 |
| 代码执行检测 | 接受工具 code, script,或 eval 参数--任意执行曲面 |
| 危险的默认模式 | 没有适当警告说明的破坏性操作(写入、删除、删除) |
效率分析
捕获工具激增和模式膨胀——MCP服务器LLM性能不佳的主要原因:
| 度量 | 警告 | 严重 | 为什么 |
|---|---|---|---|
| 工具数量 | >20 | >50 | 更多的工具=每个请求中更多的令牌=更少的对话空间 |
| 架构令牌 | >10000 | >30000 | 令牌预算有限。模式开销与实际内容竞争 |
令牌估计使用 chars/4 启发式(JSON模式的准确率约为15%,而tiktoken的准确率为15%)。
评分
综合0-100分。每个维度从其最大值开始,并根据发现进行推断:
| 尺寸 | 最大值 | 扣除额 |
|---|---|---|
| 合规性 | 40 | (passed / total_run) * 40 |
| 质量 | 25 | -5个/关键,-2个/警告 |
| 效率 | 15 | -8次/临界,-3次/警告 |
| 安全 | 20 | -10个/关键,-5个/警告 |
跳过维度 --skip-* 旗帜意味着这些积分不会被授予。具有以下功能的服务器 --skip-security 最多可以得分80分。
CLI 参考
| 标志 | 描述 | 默认值 |
|---|---|---|
-t, --transport | 运输类型(stdio 或 http) | stdio |
-r, --reporter | 输出格式(console 或 json) | console |
-o, --output | 将报告写入文件 | |
--threshold | 最低及格分数(0-100)——如果低于1,则退出1 | |
--timeout | 测试超时(毫秒) | 30000 |
--skip | 要跳过的逗号分隔的测试ID | |
--only | 要运行的逗号分隔的测试ID | |
-e, --env | 环境变量为 KEY=VAL,KEY2=VAL2 | |
--max-tools | 刀具计数的临界阈值 | 50 |
--max-schema-tokens | 架构令牌的临界阈值 | 30000 |
--skip-efficiency | 跳过效率分析 | |
--skip-quality | 跳过质量分析 | |
--skip-security | 跳过安全分析 |
CI/CD集成
添加到GitHub操作工作流:
- name: Test MCP Server
run: npx mcp-quality-gate validate "./my-server" --threshold 80 --reporter json --output mcp-quality-gate-report.json当分数低于1时,mcp质量门以代码1退出 --threshold,CI步骤失败。
程序化API
import {
createMCPClient,
listAllTools,
runTests,
complianceTests,
analyzeEfficiency,
analyzeQuality,
analyzeSecurity,
ConsoleReporter,
} from "mcp-quality-gate";
const client = await createMCPClient({
command: "node",
args: ["./my-server.js"],
transport: "stdio",
});
const tools = await listAllTools(client);
const efficiency = analyzeEfficiency(tools);
const quality = analyzeQuality(tools);
const security = analyzeSecurity(tools);
const result = await runTests(
complianceTests,
{ client, timeout: 10000 },
undefined,
"my-server",
efficiency,
quality,
security,
);
console.log(new ConsoleReporter().format(result));
await client.close();建筑
mcp-quality-gate
├── CLI (Commander) → parse args, orchestrate
├── MCP Client Wrapper → connect via stdio or HTTP, manage lifecycle
├── Compliance Tests (17) → live protocol verification
│ ├── Lifecycle (3) → init, capabilities, ping
│ ├── Tools (7) → list, fields, naming, schema, call, errors, descriptions
│ ├── Resources (4) → list, fields, descriptions, read
│ └── Prompts (3) → list, fields, get
├── Quality Analyzer → param descriptions, description length, deprecated, duplicates
├── Security Analyzer → env exposure, code execution, dangerous defaults
├── Efficiency Analyzer → tool count, schema token estimation
├── Score Calculator → 4-dimension weighted composite (40+25+15+20=100)
└── Reporters → console (colored), JSON (CI/CD)发布
mcp质量门如下 语义版本控制:
- 0.x.y -在1.0之前,API可能会在次要版本之间发生变化
- 补丁 (0.x.Y)--错误修复、新的合规性测试、文档更新
- 次要的 (0.X.0)--新的分析器维度、新的报告器、CLI标志
- 重大 (X.0.0)-突破API变化,评分公式变化
发布工作原理
- 碰撞
version在package.json - 更新
CHANGELOG.md使用新版本条目 - 合并到
main - CI自动运行:运行lint+test+build,发布到带有出处的npm,创建带有标签的GitHub Release
v{version}
这 prepublishOnly 脚本运行 lint && build && test 作为安全门。看 贡献.md 获取完整的发布说明。
路线图
- \[x\] v0.1 --合规性测试(生命周期、工具、资源、提示)、质量+安全+效率分析、四维评分、CI/CD工作流程
- \[ \] v0.2 --传输合规性测试(HTTP/SSE边缘情况)、响应模式验证、能力拒绝测试
- \[ \] v0.3 —
mcp-quality-gate init脚手架、GitHub CI行动、性能基准测试 - \[ \] v1.0 -动态安全测试,MCP服务器注册表扫描,稳定的API
贡献
看 贡献.md 用于开发设置、代码标准以及如何添加测试。
安全
看 安全.md 用于报告漏洞。
