mcp评分引擎
一个独立的评分引擎,用于评估 模型上下文协议(MCP) 服务器。纯Python,没有框架依赖关系——只有数据类、评分逻辑和网络探测。
用于生产 MCP记分牌 对数千台MCP服务器进行分级。
安装
pip install mcp-scoring-engine快速开始
从GitHub仓库中对服务器进行评分(静态分析)
from mcp_scoring_engine import ServerInfo, analyze_repo, compute_score
server = ServerInfo(
name="my-mcp-server",
description="A tool server for doing useful things",
repo_url="https://github.com/owner/my-mcp-server",
)
static = analyze_repo(server.repo_url)
result = compute_score(server, static_result=static)
print(result.composite_score) # 0–100
print(result.grade) # "A+", "B", "D", etc.
print(result.score_type) # "partial" (1 tier) or "full" (2+ tiers)探测正在运行的服务器
from mcp_scoring_engine import (
ServerInfo, probe_server, deep_probe_server, compute_score
)
# Fast health check (~10s) — connection, initialize, ping
fast = probe_server("https://my-server.example.com/mcp")
print(fast.is_reachable, fast.connection_ms)
# Deep protocol probe (~30s) — schema validation, error handling, fuzz testing
deep = deep_probe_server("https://my-server.example.com/mcp")
print(deep.tools_count, deep.schema_valid, deep.fuzz_score)
# Score with the probe results
server = ServerInfo(name="my-server", description="...", repo_url="...")
static = analyze_repo(server.repo_url)
result = compute_score(server, static_result=static, deep_probe=deep)
print(result.grade)探测stdio服务器
from mcp_scoring_engine import probe_server_stdio, deep_probe_server_stdio
fast = probe_server_stdio(["npx", "-y", "@modelcontextprotocol/server-memory"])
deep = deep_probe_server_stdio(["python", "-m", "my_mcp_server"])对服务器进行分类
from mcp_scoring_engine import classify_server, ServerInfo
server = ServerInfo(
name="stripe-mcp",
description="MCP server for Stripe payment processing",
repo_url="https://github.com/stripe/stripe-mcp",
)
category, targets = classify_server(server)
print(category) # "finance"
print(targets) # ["Stripe"]检测stdio服务器的入口点
from mcp_scoring_engine import detect_entry_point, make_github_file_reader
# With a GitHubPublicClient (from your own GitHub API code)
file_reader = make_github_file_reader(client)
tree = client.get_tree()
result = detect_entry_point(tree, file_reader)
# {"language": "python", "run_cmd": ["python", "-m", "my_server"],
# "install_cmd": "uv pip install -e .",
# "source": "pyproject.toml [project.scripts]", "confidence": "high"}入口点检测解析构建元数据以推断如何运行MCP服务器:
- python:
pyproject.toml脚本,setup.cfg/setup.pyconsole_scripts,__main__.py - 节点:
package.jsonbin字段,scripts.start,main领域
当通过拨打电话时 analyze_repo(),检测以零额外API成本搭载在已提取的文件树上。结果存储在 StaticAnalysis.details["entry_point"].
检测危险信号
from mcp_scoring_engine import detect_flags, ServerInfo
server = ServerInfo(
name="sketchy-server",
description="A MCP server",
repo_url="",
remote_endpoint_url="http://localhost:3000/mcp",
)
flags = detect_flags(server)
for flag in flags:
print(f"[{flag.severity}] {flag.label}: {flag.description}")
# [critical] No Source Code: No repository URL or source link provided
# [warning] Staging Artifact: Endpoint URL contains localhost or staging reference建筑
引擎评估跨服务器 三个数据层:
| 层级 | 来源 | 衡量什么 |
|---|---|---|
| 第1层——静态分析 | GitHub repo | 架构完整性、描述质量、文档、维护脉冲、依赖关系健康、许可证清晰度、版本卫生 |
| 第2层——协议探测 | 实时服务器 | 连接健康、工具模式验证、错误处理、模糊弹性、身份验证发现 |
| 第3级——可靠性 | 滚动窗口 | 正常运行时间百分比,p50/p95延迟 |
综合得分是五个类别的加权混合:
| 类别 | 重量 |
|---|---|
| 架构和文档 | 25% |
| 协议合规性 | 20% |
| 可靠性 | 20% |
| 维护 | 15% |
| 安全 | 20% |
分数类型:
partial--只有1个数据层可用。数字分数,但没有字母等级。full--2+数据层。A+至F级。
API 参考
核心
| 功能 | 说明 |
|---|---|
compute_score(server, static_result?, deep_probe?, reliability?) | 计算加权综合得分→ ScoreResult |
score_to_grade(score) | 转换0到100→ 字母等级(A+、A、B、C、D、F) |
classify_server(server) | 对服务器进行分类→ (category, target_platforms) |
detect_flags(server, context?) | 检测危险信号→ list[Flag] |
generate_badges(server, static_result?, deep_probe?, reliability?, flags?) | 生成展示徽章→ dict |
探针
| 功能 | 说明 | |
|---|---|---|
probe_server(url) | 通过HTTP进行快速健康检查→ FastProbeResult | |
probe_server_stdio(command) | 性病快速健康检查→ FastProbeResult | |
deep_probe_server(url) | HTTP上的完整协议探测→ DeepProbeResult | |
deep_probe_server_stdio(command) | stdio上的完整协议探测→ DeepProbeResult | |
analyze_repo(repo_url) | GitHub仓库的静态分析→ StaticAnalysis | |
detect_entry_point(file_tree, file_reader) | 从仓库元数据检测如何运行服务器→ `dict \ | None` |
make_github_file_reader(client) | 创建可从GitHub API客户端调用的file_reader→ Callable | |
compute_reliability_score(data) | 正常运行时间+延迟得分→ int |
类型
所有输入和输出都是纯数据类:
ServerInfo--输入服务器元数据(名称、描述、repo_url等)ScoreResult--完整的评分输出(综合得分、等级、类别得分、旗帜、徽章)FastProbeResult--健康检查结果(可获取,计时)DeepProbeResult--协议合规性结果(模式、错误处理、模糊)StaticAnalysis--回购分析结果(7个指标得分+GitHub元数据)ReliabilityData--预先计算的可靠性指标(正常运行时间、延迟)Flag--危险信号(关键、严重性、标签、描述)Badge--显示徽章(钥匙、标签、级别)
许可证
麻省理工学院
