sensitive-info-mcp
The sensitive-info-mcp server detects and masks sensitive information in text and files using regular expressions, validation algorithms, and optional AI-based semantic detection. It supports 14+ types of sensitive data (phone numbers, ID cards, bank cards, emails, API keys, JWTs, private keys, AWS keys, GitHub tokens, passwords, etc.).
Scan text (
scan_text): Detect sensitive data in a string, returning JSON results.Mask text (
mask_text): Detect and redact sensitive info using configurable strategies:mask,replace,hash,keep_format, orredact.Generate report (
scan_report): Produce a Markdown-formatted report of all findings in a given text.Scan file (
scan_file): Analyze a file for sensitive information and return JSON-formatted results.Mask file (
mask_file): De-identify sensitive content in a file, saving to a new path or overwriting in place.List rules (
list_rules): Retrieve all built-in detection rules currently configured.AI semantic detection: Optionally enable LLM-based detection (via
OPENAI_API_KEY) to catch obfuscated or context-dependent sensitive info.Batch scan & unified reporting: Prescreen code/config snippets and combine rule-based and LLM-based findings into a single report.
Integration options: Python SDK, CLI, and GitHub Action support.
Leverages OpenAI's LLM for AI-enhanced semantic detection of sensitive information, identifying context-based privacy risks.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@sensitive-info-mcp mask my phone number 13812345678"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
🔒 Sensitive Info MCP
规则驱动的敏感信息检测与数据脱敏 MCP 服务器 + LLM Skill 协同
一个 Model Context Protocol (MCP) 服务器,用于检测和脱敏文本/文件/代码中的敏感信息。支持 14+ 类敏感信息识别,结合正则规则 + 校验算法做基础检测,并提供掩码、替换、哈希等多种脱敏策略。LLM 语义检测通过 Skill 编排 AI 助手完成(MCP 不内置 LLM 调用)。
✨ 特性
全面检测:手机号、身份证、银行卡、邮箱、API Key、JWT、私钥、AWS Key、GitHub Token 等 14+ 类
智能校验:身份证校验位算法、银行卡 Luhn 校验,降低误报
MCP/Skill 分工:基础检测在 MCP(快、确定性),LLM 语义检测在 Skill(识别变形/拆分/上下文隐私),职责清晰
灵活脱敏:5 种策略(掩码/替换/哈希/保留格式/删除),支持按类型自定义
中文友好:所有正则使用 lookaround 断言,完美兼容中文环境
多形态使用:MCP Server(Claude/Cursor/CodeBuddy)、CLI 命令行、Python SDK、GitHub Action
Related MCP server: MCP Presidio
📦 安装
pip install -e .🚀 快速开始
1. CLI 命令行
# 检测敏感信息
sensitive-info-mcp "我的手机号是13812345678"
# 脱敏输出
sensitive-info-mcp "我的手机号是13812345678" --mask
# 生成 Markdown 报告
sensitive-info-mcp "身份证:110101199003071233" --report
# 扫描文件
sensitive-info-mcp --file ./config.yaml --mask2. MCP Server(Claude Desktop / Cursor / CodeBuddy)
在客户端配置文件中添加:
Claude Desktop (claude_desktop_config.json):
{
"mcpServers": {
"sensitive-info": {
"command": "sensitive-info-mcp",
"args": []
}
}
}Cursor / CodeBuddy (.codebuddy/mcp.json 或对应配置):
{
"mcpServers": {
"sensitive-info": {
"command": "python3",
"args": ["-m", "sensitive_info_mcp.server"]
}
}
}配置后,AI 助手即可调用以下工具:
工具 | 功能 |
| 检测文本中的敏感信息(基础规则) |
| 检测并脱敏文本 |
| 生成单文本 Markdown 扫描报告 |
| 扫描文件 |
| 脱敏文件并保存 |
| 列出所有检测规则 |
| 批量对多个代码/配置片段做基础初筛(配合 Skill) |
| 汇总 rule + llm 来源检测结果生成统一报告(配合 Skill) |
3. Python SDK
from sensitive_info_mcp.scanner import Scanner
scanner = Scanner()
# 检测
findings = scanner.detect("联系我:13812345678 或 test@qq.com")
for f in findings:
print(f"[{f.type.value}] {f.value} → 风险:{f.risk_level.value}")
# 脱敏
masked, findings = scanner.mask("手机号13812345678")
print(masked) # 手机号138****5678
# 完整报告
report = scanner.report("身份证:110101199003071233")
print(report.to_markdown())🔧 配置
脱敏策略
策略 | 说明 | 示例 |
| 使用各类型默认策略 | 手机号→掩码,API Key→替换 |
| 部分掩码 |
|
| 完全替换 |
|
| SHA256 哈希 |
|
| 保留格式 |
|
| 完全删除 |
|
from sensitive_info_mcp.types import MaskConfig, MaskStrategy
from sensitive_info_mcp.scanner import Scanner
# 全局强制使用替换策略
scanner = Scanner(mask_config=MaskConfig(strategy=MaskStrategy.REPLACE))
# 按类型自定义
scanner = Scanner(mask_config=MaskConfig(
type_overrides={
"phone": {"strategy": "hash"},
"email": {"strategy": "keep_format"},
}
))🤝 结合 Skill 做 LLM 语义检测
本 MCP 仅做基础检测(正则 + 校验算法),不内置 LLM 调用。LLM 语义检测(识别变形/拆分敏感信息、非标准命名的硬编码凭据、内网信息、上下文隐私等)通过 Skill 编排 AI 助手完成 —— 因为 AI 助手本身就在执行 LLM,无需 MCP 再调外部 API。
工作流
代码 / 配置片段
│
├─ codegraph 取常量/变量定义 + Glob/Read 取配置文件
▼
┌───────────────────────┐
│ MCP scan_snippets │ ── rule 初筛 ──┐
│ (正则 + 校验算法) │ │
└───────────────────────┘ │
│ 初筛未命中片段 │
▼ │
┌───────────────────────┐ │
│ AI 助手 LLM 二次筛选 │ ── llm findings│
│ (Skill 识别规则) │ ──────────────►│
└───────────────────────┘ │
▼ ▼
┌───────────────────────┐
│ MCP build_report │ → 统一 Markdown 报告(区分 rule/llm 来源)
└───────────────────────┘安装 Skill
将 skills/sensitive-info-scan/SKILL.md 复制到 CodeBuddy / Cursor 的 skills 目录:
# CodeBuddy
mkdir -p ~/.codebuddy/skills/sensitive-info-scan
cp skills/sensitive-info-scan/SKILL.md ~/.codebuddy/skills/sensitive-info-scan/SKILL.md
# 或 Cursor / Claude Code 对应 skills 目录重启会话后,对用户说"扫描代码中的敏感信息",AI 助手会自动按 Skill 工作流执行:codegraph 取片段 → MCP 初筛 → LLM 二筛 → build_report 生成报告。
Skill 也可在无 codegraph 环境下工作(回退为 Grep 赋值行收集片段),详见 SKILL.md。
📋 支持的敏感信息类型
类型 | 标识 | 风险等级 | 校验 |
手机号 |
| 高 | - |
身份证号 |
| 严重 | ✅ 校验位 |
银行卡号 |
| 严重 | ✅ Luhn |
邮箱 |
| 中 | - |
API Key |
| 高 | - |
AWS Key |
| 严重 | - |
GitHub Token |
| 严重 | - |
JWT |
| 严重 | - |
私钥 |
| 严重 | - |
密码 |
| 高 | - |
URL 凭据 |
| 高 | - |
IP 地址 |
| 低 | - |
社会保障号 |
| 高 | - |
LLM 检测 |
| 中-严重 | - (Skill 二次筛选产生) |
添加自定义规则
from sensitive_info_mcp.detectors.rules import Rule, RuleDetector
from sensitive_info_mcp.types import SensitiveType, RiskLevel
import re
custom = Rule(
type=SensitiveType.CUSTOM,
pattern=re.compile(r"(?<!\d)EMP\d{6}(?!\d)"), # 员工号 EMP123456
risk_level=RiskLevel.MEDIUM,
confidence=0.9,
description="内部员工编号",
)
scanner = Scanner(extra_rules=[custom])🏗️ 架构
输入文本 / 文件 / 代码片段
│
▼
┌───────────────────┐
│ 规则检测器 │ 正则 + 校验算法(身份证校验位 / 银行卡 Luhn)
│ (RuleDetector) │ → 14+ 类已知格式敏感信息
└────────┬──────────┘
│
▼
┌───────────────────┐
│ 脱敏处理器 │ 掩码 / 替换 / 哈希 / 保留格式 / 删除
│ (Masker) │
└────────┬──────────┘
▼
脱敏文本 + 检测报告
┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
LLM 语义检测(在 Skill 层,不在 MCP 内):
codegraph 取片段 → scan_snippets 初筛 → AI 助手 LLM 二筛 → build_report📁 项目结构
sensitive-info-mcp/
├── src/sensitive_info_mcp/
│ ├── server.py # MCP Server + CLI 入口(8 个工具)
│ ├── scanner.py # 扫描器(基础规则检测 + 脱敏)
│ ├── types.py # 类型定义
│ ├── detectors/
│ │ ├── base.py # 检测器基类
│ │ └── rules.py # 规则检测引擎(14+ 类)
│ └── maskers/
│ └── processor.py # 脱敏处理器
├── skills/
│ └── sensitive-info-scan/
│ └── SKILL.md # LLM 语义检测 Skill(codegraph + MCP + AI 助手协同)
├── action.yml # GitHub Action
├── examples/ # 使用示例
├── tests/ # 测试用例
└── pyproject.toml🧪 测试
python tests/test_core.py📄 License
MIT
Available Tools
6 toolslist_rulesA
列出当前所有内置检测规则
Returns: JSON 格式的规则列表
Inputs: no named parameters. Returns: result
mask_fileB
脱敏文件内容并保存
Args: file_path: 输入文件路径 output_path: 输出文件路径(与 inplace 互斥) mask_strategy: 脱敏策略 enable_ai: 是否启用 AI 检测 inplace: 是否原地覆盖(慎用)
Returns: 操作结果 JSON
Inputs: file_path (required), output_path, mask_strategy, enable_ai, +1 more. Returns: result
mask_textB
检测并脱敏文本,返回脱敏后的文本
Args: text: 待脱敏文本 mask_strategy: 脱敏策略 mask|replace|hash|keep_format|redact enable_ai: 是否启用 AI 语义检测
Returns: 脱敏后的文本
Inputs: text (required), mask_strategy, enable_ai. Returns: result
scan_fileB
扫描文件中的敏感信息
Args: file_path: 文件路径 enable_ai: 是否启用 AI 检测 mask_strategy: 脱敏策略
Returns: JSON 格式的检测结果
Inputs: file_path (required), enable_ai, mask_strategy. Returns: result
scan_reportB
生成完整的 Markdown 扫描报告
Args: text: 待扫描文本 enable_ai: 是否启用 AI 检测 mask_strategy: 脱敏策略
Returns: Markdown 格式的扫描报告
Inputs: text (required), enable_ai, mask_strategy. Returns: result
scan_textA
检测文本中的敏感信息
Args: text: 待检测文本 enable_ai: 是否启用 AI 语义检测(需配置 OPENAI_API_KEY 环境变量) mask_strategy: 脱敏策略,可选 mask|replace|hash|keep_format|redact
Returns: JSON 格式的检测结果列表
Inputs: text (required), enable_ai, mask_strategy. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 6 tools
Each tool has a clearly distinct purpose: listing rules, masking files/text, scanning files/text, and generating reports. The only potential overlap (scan_text vs. scan_report) is resolved by different return formats (JSON vs. Markdown).
All tool names follow a consistent verb_noun pattern in snake_case (e.g., list_rules, mask_file, scan_text). No mixing of conventions or irregular names.
Six tools is an appropriate number for a sensitive info scanning and masking server. Each tool covers a necessary operation without redundancy or excessive specialization.
The tool set covers core workflows: scanning (file and text), masking (file and text), report generation, and rule listing. A minor gap is the lack of rule management tools (add/modify rules), but the primary detection and masking functionality is complete.
Maintenance
Related MCP Connectors
Zero-log MCP server with 49 tools for AI guardrails, secret scanning, MCP linting & EU compliance.
MCP server for detecting and redacting PII (Personally Identifiable Information) in PDF documents.
MCP gateway: one connection for your AI apps, with tool policies, PII redaction and audit logs.
Scan prompts for injection attacks, redact PII, and audit LLM SDK usage from any MCP client
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceAn MCP proxy that pseudo-anonymizes PII before data reaches external AI providers like Claude, ChatGPT, or Gemini.18MIT
- AlicenseAqualityDmaintenanceAn MCP server that enables LLMs to detect and anonymize over 25 types of Personally Identifiable Information (PII) using Microsoft Presidio. It supports various redaction strategies and can process both plain text and structured data to help ensure data privacy.10MIT
- FlicenseNot gradedqualityDmaintenanceMCP server for automatic detection and redaction of PII in text, with anonymization and deanonymization capabilities, all local processing.1-
- AlicenseAqualityDmaintenanceMCP server providing on-prem PII detection and anonymization tools (scan and is_sensitive) for AI agents, ensuring data stays local.4MIT