mcpField
L
Llm Guard Privacy Gateway

Llm Guard Privacy Gateway

Local
github.com/AmywithAI & Agents0Updated 47w ago

About Llm Guard Privacy Gateway

Llm Guard Privacy Gateway is an MCP-based privacy gateway for developers who need to inspect and filter sensitive content in LLM applications. It detects personal information and keys, applies blacklist rules, and processes data locally.

Key features

  1. 01Redact Chinese names, phone numbers, and emails
  2. 02Detect API keys, Alibaba Cloud keys, and RSA private keys
  3. 03Block content using blacklist terms
  4. 04Return JSON with detection and sanitization results
  5. 05Use regex detection when dependencies are unavailable

Use cases

  1. 01Removing personal information before sending prompts
  2. 02Blocking key exposure in prompt text
  3. 03Rejecting content based on a custom blacklist

MCP support

It exposes a sanitize_prompt tool to MCP clients, accepting prompt text and returning JSON with detection and sanitization results. Data processing takes place locally.

Configuration

Local server config is the same for every client. Copy it into your client’s MCP config file.

No install method listed yet

We haven’t collected a package or remote endpoint for this server. Follow the instructions in the project README.

Repository

Tools

No tool list yet

Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.

Details

From the project README

LLM-Guard 隐私网关

一个基于MCP协议的隐私保护网关,用于在LLM应用中检测和过滤敏感信息。

功能特性

  1. PII脱敏:自动识别文本中的中文人名、手机号、邮箱,并将其替换为占位符
  2. 密钥拦截:检测常见的API Key、阿里云AccessKey以及RSA私钥
  3. 商业阻断:定义黑名单列表,如果文本包含这些词,直接返回拦截状态
  4. MCP封装:将上述逻辑封装为MCP工具,返回JSON格式的处理结果

安装

pip install -r requirements.txt
关于spaCy模型下载问题

如果您在下载spaCy中文语言模型时遇到网络问题(如连接被远程主机关闭),可以尝试以下解决方案:

解决方案1:使用国内镜像源
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple spacy
解决方案2:手动下载模型

访问 https://github.com/explosion/spacy-models/releases 下载对应的模型文件,然后本地安装:

pip install path/to/zh_core_web_sm-3.x.x.tar.gz
解决方案3:使用其他镜像站点
# 使用清华镜像
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ spacy
python -m spacy download zh_core_web_sm --index-url https://pypi.tuna.tsinghua.edu.cn/simple/

使用方法

基本用法
from llm_guard import sanitize_prompt_mcp

prompt = "你好,我是张三,我的电话是13812345678"
result = sanitize_prompt_mcp(prompt)
print(result)
在MCP服务中使用
from llm_guard import LLMSanitizer

sanitizer = LLMSanitizer()
result = sanitizer.sanitize_prompt("你的提示文本")

MCP服务部署

本项目支持MCP协议,可以作为MCP工具服务器运行。在这种架构下,工具注册在云端,但数据处理完全在本地进行,确保数据隐私。

运行MCP服务
python mcp_server.py
Docker部署

构建Docker镜像:

docker build -t llm-guard-mcp .

运行容器:

docker run -it --rm llm-guard-mcp
MCP工具说明

MCP服务提供以下工具:

sanitize_prompt

用于清洗提示文本,移除敏感信息。

参数:

  • prompt (string, required): 需要清洗的提示文本

返回值:

  • JSON格式的结果,包含原始文本、清洗后的文本、检测到的敏感信息等

插件市场上架

本项目支持发布到蚂蚁百宝箱插件市场,具体步骤如下:

1. 准备材料
2. 创建MCP插件

参考文档: https://alipaytbox.yuque.com/sxs0ba/huntb8/hwhtg4sp1mdppsib

3. 上架插件市场

参考文档: https://alipaytbox.yuque.com/sxs0ba/huntb8/ohqgnh2gt1qhymqb

返回格式

函数会返回一个JSON对象,包含以下字段:

  • original_prompt: 原始提示文本
  • sanitized_prompt: 处理后的提示文本
  • pii_detected: 检测到的PII信息列表
  • api_keys_detected: 检测到的API密钥列表
  • blacklist_words_found: 发现的黑名单词汇
  • status: 处理状态 ("allowed" 或 "blocked")
  • message: 处理消息

自定义配置

可以通过修改 llm_guard.py 中的 LLMSanitizer 类来自定义黑名单词汇或其他规则。

错误处理与降级机制

本实现具备完善的错误处理和降级机制:

  1. 即使presidio库未安装或无法初始化,系统也会使用内置的正则表达式进行检测
  2. 当网络问题导致spaCy模型无法下载时,系统仍然能够运行(虽然精度可能略有下降)
  3. 所有异常都被适当捕获,不会导致整个应用程序崩溃

这种设计确保了系统在网络受限或依赖库缺失的环境中仍能正常工作。

Comments

Markdown supported

New to MCP?

From what the protocol is to installing your first server, these answers cover most first questions.

An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.