⚠️ 安全和隐私警告⚠️
使用前请仔细阅读
使用此MCP服务器检测PII涉及向Presidio引擎发送文本数据。当处理在容器或python进程内本地发生时, 通过LLM代理(如Claude、ChatGPT等)使用此工具意味着要分析的文本正在与该LLM共享。
风险:
- PII泄漏: 如果您要求LLM“检查此文本中的PII”或“匿名化此文本”,则您发送的是潜在的敏感文本 *LLM提供者* 首先,他们可以构造工具调用。
- 上下文保留: PII可能会保留在LLM的聊天记录、培训数据或日志中。
- 传输的上下文: PII将成为通过网络传输的提示上下文的一部分。
推荐使用:
- 本地LLM: 与本地托管的LLM一起使用,数据不会离开您的基础架构。
- 私人/企业代理: 在具有严格数据隐私协议的经批准的企业环境中使用。
- 非LLM集成: 如果需要严格的隐私,可以直接在代码中使用底层库,而无需LLM中介。
替代架构: 考虑使用Presidio作为过滤器 *之前* LLM。工具如 文学硕士 可以集成Presidio来净化输入 *之前* 它到达LLM提供商,防止PII离开您的控制。此MCP服务器专为 *能动性* LLM决定检查PII的工作流程,PII本身就带有上述风险。
MCP主席团
一种模型上下文协议(MCP)服务器,使用以下方式提供全面的PII(个人身份信息)检测和匿名化功能 微软普雷西迪奥该服务器通过检测文本和结构化数据中的PII并使其匿名,使LLM能够安全地处理敏感数据。
特性
核心能力
- PII检测:识别25种以上类型的个人身份信息,包括姓名、电子邮件、电话号码、信用卡、社会安全号码、地址等
- 文本匿名化:多种匿名化策略(替换、编辑、哈希、掩码、加密)
- 结构化数据支持:递归分析和匿名JSON/字典数据
- 批处理:在批处理操作中高效处理多个文本
- 自定义识别器:使用正则表达式添加特定于域的PII模式
- 多语言支持:检测多种语言的PII
- 验证工具:使用指标测试和验证检测准确性
可用的MCP工具
- analyze_text -使用置信度分数检测文本中的PII实体
- 匿名文本 -使用各种运算符匿名化PII
- get_supported_entities -列出所有支持的PII实体类型
- add_custom_recognator -添加自定义PII检测模式
- 批次分析 -分析PII的多个文本
- batch_匿名化 -匿名多个文本
- 匿名操作员 -列出可用的匿名化方法
- 分析结构化数据 -检测JSON/结构化数据中的PII
- 匿名结构化数据 -在结构化数据中匿名化PII
- 验证检测 -使用指标验证检测准确性
安装
选择您喜欢的安装方法:
有关Docker部署的详细说明,请参阅 医生.md.
先决条件
对于Python安装:
- Python 3.10或更高版本
- pip或uv包管理器
对于Docker安装:
- Docker 20.10或更高版本
- Docker Compose(可选,便于管理)
Docker安装(推荐用于生产环境)
Docker提供了一个自包含、可复制的环境,其中预装了所有依赖项。
Docker快速入门
# Clone the repository
git clone https://github.com/cmalpass/mcp-presidio.git
cd mcp-presidio
# Build the Docker image
docker build -t mcp-presidio .
# Run the container with stdio (default)
docker run -i mcp-presidio使用Docker Compose
# Clone the repository
git clone https://github.com/cmalpass/mcp-presidio.git
cd mcp-presidio
# Build and start the container
docker-compose up -d
# View logs
docker-compose logs -f
# Stop the container
docker-compose down使用Docker配置Claude桌面
要在Claude Desktop中使用Docker容器,请更新您的 claude_desktop_config.json:
{
"mcpServers": {
"presidio": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"mcp-presidio:latest"
],
"env": {}
}
}
}或者,如果使用注册表中的预构建映像:
{
"mcpServers": {
"presidio": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"ghcr.io/cmalpass/mcp-presidio:latest"
],
"env": {}
}
}
}Docker镜像详细信息
Docker镜像包括:
- Python 3.11精简版
- 所有必需的依赖项(mcp、presidio分析器、presidio匿名器、spacy)
- 预装的英语语言模型(en_core_web_lg)
- 非root用户增强了安全性
- 多阶段构建,实现最小图像大小(~500MB)
高级Docker使用
交互式调试Shell:
docker run -it mcp-presidio bash自定义语言模型: 要包含其他语言模型,请修改Dockerfile:
# Add after the English model installation
RUN python -m spacy download es_core_news_lg # Spanish
RUN python -m spacy download fr_core_news_lg # French
RUN python -m spacy download de_core_news_lg # German然后重建映像:
docker build -t mcp-presidio:multilang .自定义配置的卷装:
docker run -i -v $(pwd)/config:/app/config:ro mcp-presidioPython安装(快速安装)
使用处理依赖关系和语言模型的交互式安装脚本:
Unix/Linux/macOS:
# Clone the repository
git clone https://github.com/cmalpass/mcp-presidio.git
cd mcp-presidio
# Run the installation script
./install.sh
# or
python install.py窗户:
# Clone the repository
git clone https://github.com/cmalpass/mcp-presidio.git
cd mcp-presidio
# Run the installation script
install.bat
# or
python install.py脚本将:
- 检查Python版本兼容性
- 安装基础依赖项(mcp、presidio分析器、presidio-anonymizer、spacy)
- 语言模型安装提示(英语、西班牙语、法语、德语等)
- 可选择安装开发依赖项
- 验证安装
- 测试基本功能
Python安装(手册)
如果您更喜欢手动安装:
# Clone the repository
git clone https://github.com/cmalpass/mcp-presidio.git
cd mcp-presidio
# Install the package
pip install -e .
# Download required spaCy language model (for English)
python -m spacy download en_core_web_lg对于其他语言,请下载相应的spaCy模型:
# Spanish
python -m spacy download es_core_news_lg
# French
python -m spacy download fr_core_news_lg
# German
python -m spacy download de_core_news_lg用法
运行服务器
服务器使用stdio传输运行,适用于MCP客户端:
mcp-presidio或者直接用Python运行:
python -m mcp_presidio.server使用Claude Desktop进行配置
添加到您的Claude Desktop配置(claude_desktop_config.json):
{
"mcpServers": {
"presidio": {
"command": "python",
"args": ["-m", "mcp_presidio.server"],
"env": {}
}
}
}或者,如果作为脚本安装:
{
"mcpServers": {
"presidio": {
"command": "mcp-presidio",
"args": [],
"env": {}
}
}
}LLM会话中的示例用法
检测PII:
User: Can you check this text for PII? "My name is John Smith and my email is john@example.com"
LLM: I'll analyze that text for PII using the analyze_text tool.
[Tool calls analyze_text with the text]
Result: Found 2 PII entities:
- PERSON: "John Smith" (confidence: 0.85)
- EMAIL_ADDRESS: "john@example.com" (confidence: 1.0)匿名文本:
User: Can you anonymize this customer feedback? "I'm Jane Doe, call me at 555-123-4567"
LLM: I'll anonymize the PII in that text.
[Tool calls anonymize_text]
Result: "I'm
, call me at
"使用结构化数据:
User: Check this JSON for PII: {"user": "bob@email.com", "phone": "555-0100"}
LLM: I'll analyze the structured data.
[Tool calls analyze_structured_data]
Result: Found PII in 2 fields:
- .user: EMAIL_ADDRESS
- .phone: PHONE_NUMBER支持的PII实体类型
服务器支持25种以上的PII实体类型,包括:
- 个人:人,日期时间
- 联系:电子邮件地址、电话号码、网址
- 金融的:信用卡、IBAN_CODE、US_BANK_NUMBER、加密货币
- 政府ID:US_SSN、US_PASSPORT、US_DRIVER_LICENSE、UK_NHS
- 国际ID:SG_NRIC_FIN、IN-PAN、IN-AADHAAR、AU_ABN、AU_TFN、AU_MEDICARE
- 位置:位置,IP_ADDRESS
- 医学的:医学执照
- 其他:以及更多针对特定国家的标识符
使用 get_supported_entities 工具查看您语言的所有可用类型。
匿名化操作员
服务器支持多种匿名化策略:
- 替换 -用占位符文本替换PII(例如。, ``)
- 修订 -从文本中完全删除PII
- 哈希 -替换为加密哈希(SHA-256)
- 面具 -掩码字符(例如。,
***-**-1234) - 加密 -使用AES加密对PII进行加密
- 保持 -保持PII原样(用于选择性匿名化)
高级功能
自定义识别器
添加特定于域的PII模式:
# Example: Detect custom employee IDs
add_custom_recognizer(
name="employee_id_recognizer",
entity_type="EMPLOYEE_ID",
patterns=[
{"name": "emp_pattern", "regex": "EMP-\\d{6}", "score": 0.9}
],
context=["employee", "staff", "worker"]
)批处理
高效处理多个文档:
# Analyze multiple texts
batch_analyze(
texts=["Text 1...", "Text 2...", "Text 3..."],
entities=["PERSON", "EMAIL_ADDRESS"],
score_threshold=0.5
)语言支持
指定不同的语言:
analyze_text(
text="Me llamo María García",
language="es"
)验证和测试
验证检测精度:
validate_detection(
text="John lives at 123 Main St",
expected_entities=[
{"entity_type": "PERSON", "start": 0, "end": 4},
{"entity_type": "LOCATION", "start": 14, "end": 27}
]
)
# Returns precision, recall, and F1 score建筑
此MCP服务器集成了:
- MCP快速MCP:提供MCP协议实现
- Presidio分析仪:使用NLP和模式匹配检测PII
- Presidio匿名者:通过各种操作员匿名检测到的PII
- 缥缈虚幻的:为NLP引擎提供动力,实现准确的实体识别
安全注意事项
- 所有处理都在本地进行,没有数据发送到外部服务
- 服务器使用stdio传输与MCP客户端进行安全通信
- 多种匿名化策略可用于不同的隐私要求
- 支持合规要求(GDPR、HIPAA、CCPA)
- Docker部署通过容器化提供了额外的隔离和安全性
- 容器以非root用户身份运行,以增强安全性
发展
运行测试
# Install dev dependencies
pip install -e ".[dev]"
# Run tests
pytest tests/项目结构
mcp-presidio/
├── src/
│ └── mcp_presidio/
│ ├── __init__.py
│ └── server.py # Main MCP server implementation
├── tests/ # Test suite
├── Dockerfile # Docker container definition
├── docker-compose.yml # Docker Compose configuration
├── docker-entrypoint.sh # Container entrypoint script
├── .dockerignore # Docker build exclusions
├── pyproject.toml # Project configuration
├── README.md # This file
├── DOCKER.md # Detailed Docker deployment guide
└── .gitignore许可证
MIT许可证-有关详细信息,请参阅许可证文件
贡献
欢迎投稿!请随时提交问题或拉取请求。
致谢
支持
有关问题、疑问或贡献,请访问 .
