模型上下文协议安全网关

MCP Sentinel Guard是一款基于Google Gemini AI的模型上下文协议安全网关,通过语义分析拦截恶意请求,提供实时警报和审计日志功能。

  • by KVRIND3S3N
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 KVRIND3S3N/mcp-sentinel-guard

使用说明

🛡️ MCP哨兵警卫

基于人工智能的模型上下文协议安全网关(MCP)

通过使用Google Gemini AI分析MCP流量,防止快速注入、未经授权的文件访问和恶意工具使用。


📖 概述

标准MCP服务器盲目执行LLM命令。 MCP哨兵警卫 引入了一个“Man-in-the-Middle”安全网关,该网关拦截主机(Claude/Cursor)和服务器之间的JSON-RPC通信。

使用 法学硕士作为法官 (Google Gemini 2.0 Flash)对每个请求进行语义分析。如果检测到威胁,它会阻止请求,记录事件,并向管理员发送实时电子邮件警报。

✨ 主要特点

🧠 Context-Aware Analysis: Uses LLM to detect semantic attacks (e.g., "Ignore previous instructions").

🛡️ Active Interception: Blocks malicious tools (delete_system_files) before they reach the backend.

📧 Real-Time Alerts: Sends HTML-formatted email alerts via SMTP upon attack detection.

📝 Audit Logging: Records every allowed/blocked transaction in security_log.txt.

🔌 Plug & Play: Works as a standard MCP server wrapper.


🚀 Installation
1. Clone the Repository

git clone [https://github.com/KVRIND3S3N/mcp-sentinel-guard.git](https://github.com/KVRIND3S3N/mcp-sentinel-guard.git)
cd mcp-sentinel-guard   

2. Install Dependencies

pip install mcp google-generativeai python-dotenv

3. Configuration (.env)

GOOGLE_API_KEY=your_gemini_api_key
GMAIL_USER=your_email@gmail.com
GMAIL_APP_PASSWORD=your_16_digit_app_password

Usage

Start the Gateway & Host Simulation
python attack_test.py


Project Structure

sentinel_gateway.py: Core Logic. Intercepts traffic and calls AI.

vulnerable_server.py: Backend. Simulates an unprotected MCP server.

notification_service.py: Alerts. Handles SMTP email dispatch.

attack_test.py: Client. Simulates Host behavior (Safe & Attack scenarios).