MCP Presidio灵敏度扫描仪
一 主控程序 对文本有效载荷进行分类的服务器 为了提高数据敏感性,使用 微软Presidio. 专为在存储前必须扫描有效载荷的AI代理管道而设计, 例如发送、转发或进一步处理。
它做什么
将任何文本有效负载发送到 classify_payload_sensitivity MCP工具和获取 返回一个有界的结果:是否发现了敏感数据,哪些类别 (信用卡、电子邮件、SSN等)、严重级别和允许/标记/拒绝 决定。有效载荷内容从不记录、存储或返回到 回应。
Input: "Call Jane Smith at 555-867-5309, email jane@example.com"
Output: {
"sensitivity_detected": true,
"decision": "flag",
"max_severity_band": "MEDIUM",
"matched_categories": ["PERSON", "PHONE_NUMBER", "EMAIL_ADDRESS"],
"entity_summary": {"PERSON": 1, "PHONE_NUMBER": 1, "EMAIL_ADDRESS": 1},
"confidence_summary": {"highest_score": 0.85, "findings_count": 3}
}建筑
+-----------------+
| Keycloak |
| (OAuth 2.0) |
+--------+--------+
|
JWT validation (JWKS)
|
Agent ──── POST /mcp ───> MCP Server ──── POST /scan ───> Presidio Worker
(client) (FastAPI + (internal) (Presidio engine)
FastMCP)
|
Audit trail
OTel traces → Jaeger
Prometheus metrics → Grafana- MCP 服务器 --FastAPI应用程序公开了一个MCP工具。JWT手柄
身份验证、作用域强制、审计日志记录和RFC 9728发现。
- 主席团工作人员 --运行Microsoft Presidio的内部服务
分析仪引擎。未直接暴露;只能从MCP服务器访问 (由NetworkPolicy强制执行)。
- 钥匙锁 --OAuth 2.0授权服务器。发布短期JWT
(60s TTL)通过客户端凭据授予。
安全属性
- 有效载荷内容从不被记录、在响应中返回或存储
- 具有作用域强制的JWT身份验证(
tools:classify.submit) - 每次扫描的审计跟踪(仅追加,无有效载荷内容)
- NetworkPolicy仅限制工作人员访问MCP服务器Pod
- 非根容器,无特权升级
- 有界响应模型:没有匹配的子字符串、偏移或摘录
快速开始
先决条件
| 工具 | 版本 |
|---|---|
| Docker | 29.x |
| 种类 | 0.23.x |
| kubectl | 1.35.x |
| 舵 | 3.20.x |
在WSL2(Ubuntu)上,将您的用户添加到docker组:
sudo usermod -aG docker $USER
newgrp docker设置
cd projects/mcp-presidio-sensitivity
./scripts/setup-local.sh # bootstrap kind cluster + full stack
./scripts/keycloak-admin.sh set-ttl 60 # enforce 60s token TTL
./scripts/status.sh # confirm everything is healthy对有效载荷进行分类
./scripts/classify.sh "My SSN is 123-45-6789 and my email is john@example.com"该脚本自动执行完整的RFC 9728发现链:发现 认证服务器从MCP服务器的受保护资源元数据中获取 令牌,打开MCP会话,并调用该工具。
您还可以通过管道输入:
echo "Call Jane at 555-867-5309" | ./scripts/classify.sh
cat document.txt | ./scripts/classify.sh运行演示
./scripts/demo.sh a # all cases: auth boundary, PII detection, enforcement
./scripts/demo.sh 1 # single case (e.g. credit card detection)工具接口
classify_payload_sensitivity
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
content | string | 必填 | 要分类的文本。从未登录或返回。 |
content_type | string | 必需 | MIME类型(text/plain 或 application/json) |
language | 字符串 | "en" | 分析仪的语言代码 |
tenant_policy | 字符串 | "default" | 策略配置文件标识符 |
threshold_profile | 字符串 | "default" | 阈值配置文件标识符 |
workflow_id | string | null | 可选的调用者工作流ID,用于可追溯性 |
响应
| 字段 | 类型 | 描述 |
|---|---|---|
scan_id | UUID | 唯一扫描标识符 |
status | 字符串 | "completed" |
sensitivity_detected | boolean | 是否找到任何PII实体 |
max_severity_band | string | 最高严重性: LOW, MEDIUM, HIGH, CRITICAL |
matched_categories | string\[\] | 找到实体类型(例如。 PERSON, EMAIL_ADDRESS) |
entity_summary | object | 按实体类型计数 |
decision | 字符串 | allow, flag,或 deny |
confidence_summary | 对象 | highest_score (浮动)和 findings_count (int) |
policy_profile | string | 用于扫描的策略 |
detector_version | string | Presidio引擎版本 |
timestamp | string | ISO 8601扫描时间戳 |
可观测性
| 服务 | URL | 描述 |
|---|---|---|
| 格拉法娜 | http://localhost:3000 | 操作仪表板(6行,14个面板) |
| 普罗米修斯 | http://localhost:9090 | 指标存储 |
| 耶格尔 | http://localhost:16686 | 分布式跟踪 |
这两个服务都暴露 /metrics 普罗米修斯刮。Grafana仪表板 自动配置面板,涵盖请求率、错误率、延迟 百分位数、扫描决策分布、授权边界度量、Presidio 分析仪内部和Jaeger跟踪可视化。
发展
./scripts/status.sh # start of session health check
./scripts/rebuild.sh # after source changes (rebuilds + redeploys)
./scripts/test.sh # run unit tests (42 tests, Docker-based)
./scripts/auth-test.sh # auth enforcement matrix (5 cases)
./scripts/validate-networkpolicy.sh # NetworkPolicy verification看 scripts/README.md 了解每个脚本的详细用法。
项目结构
src/
mcp_server/ # MCP server (FastAPI + FastMCP)
auth/ # JWT middleware, token verifier, error types
authorization/ # Scope enforcement policy
audit/ # Append-only audit trail
backend/ # Worker HTTP client
tools/ # classify_payload_sensitivity handler
observability/ # Logging, tracing, Prometheus metrics
worker/ # Presidio worker (FastAPI)
observability/ # Logging, tracing, Prometheus metrics
helm/ # Helm charts (mcp-server, presidio-worker)
infrastructure/ # kind config, Keycloak, Jaeger, Prometheus, Grafana
keycloak/ # Realm import JSON
scripts/ # Dev scripts (setup, rebuild, test, demo, etc.)
planning/ # Specs, decision log, pipeline, auth flows