MCP-Gatekeeper
🛡️ MCP-Gatekeeper
适用于模型上下文协议(MCP)客户端和上游服务器的运行时安全网关和 FastMCP 服务器。
MCP-Gatekeeper 是一个纵深防御代理和 FastMCP 服务器,可检查 100% 的工具列表刷新和工具响应,防止工具投毒、响应型提示注入(例如 MCPoison / CurXecute 攻击)、静默工具模式修改("rug pulls")以及未经授权的高风险操作。
专为即时部署到 fastmcp.cloud 或通过 fastmcp CLI 在本地执行而设计。
🚀 主要特性和功能
FastMCP 云就绪:单文件 FastMCP 入口点(
server.py),可直接部署到 fastmcp.cloud,支持 SSE 和 HTTP 传输。Rug-Pull 模式保护:连接时捕获工具模式基线;将 100% 的工具列表刷新与已批准的基线进行差异比较,并默认阻止未经批准的工具更改。
两阶段响应注入扫描器:
阶段 1:高性能基于规则的预过滤器,针对已知的指令劫持、数据外泄陷阱和 shell 注入。
阶段 2:深度语义 LLM 分类,利用任何兼容 OpenAI 的 API(来自
.env的LLM_API_KEY,支持 OpenAI、Grok、DeepSeek、Anthropic 或本地 Ollama)。
故障关闭安全设计:任何分类器故障、网络超时或未处理的异常默认阻止有效负载并创建安全事件。
策略引擎:可配置的按工具和按服务器规则评估(
allow、block、confirm、rate_limit)。人工确认门:将高风险操作挂起等待管理员批准;如果在可配置超时内未响应,则故障关闭(拒绝)。
防篡改审计跟踪:每次调用、响应、策略裁决和管理员决策都通过 SHA-256 哈希链 存储。
云控制中心仪表板:通过 FastMCP 在
/dashboard直接提供实时 HTML 管理仪表板。
Related MCP server: guardrails-mcp-server
🛠️ 架构概述
高级系统架构
flowchart TD
subgraph Clients["AI Clients & Interfaces"]
C1["Claude Desktop"]
C2["Claude Code CLI"]
C3["Google Antigravity"]
C4["ChatGPT / Custom App"]
end
subgraph Gateway["🛡️ MCP-Gatekeeper (FastMCP Cloud)"]
direction TB
S["FastMCP Server\nserver.py"]
subgraph Engine["Security & Policy Engines"]
B["Schema Baseline Manager\n(Rug-Pull Detector)"]
POL["Policy Engine\n(Allow/Block/Confirm/Rate-Limit)"]
CONF["Confirmation Manager\n(Human Approval Gate)"]
subgraph Classifier["Two-Stage Response Classifier"]
R1["Stage 1: Rule Prefilter\n(Fast Pattern Match)"]
R2["Stage 2: LLM Classifier\n(OpenAI / Grok / DeepSeek / Ollama)"]
end
end
UI["Admin Control Center UI\n/dashboard"]
end
subgraph External["Upstream Services & AI APIs"]
UP["Upstream MCP Servers\n(GitHub, SQL, Web Search, APIs)"]
LLM["LLM Classifier API\n(OpenAI / Grok / DeepSeek / Ollama)"]
end
subgraph Storage["Datastore & Audit"]
DB[("PostgreSQL / SQLite DB")]
AUDIT[("Tamper-Evident Audit Log\n(SHA-256 Hash Chained)")]
end
Clients -->|MCP SSE / stdio / JSON-RPC| S
S --> B
S --> POL
POL -->|Held Action| CONF
POL -->|Allowed| UP
UP -->|Tool Response| Classifier
Classifier --> R1
R1 -->|Ambiguous / Suspicious| R2
R2 -->|API Query| LLM
Classifier -->|Clean / Safe| Clients
Classifier -->|Malicious / Timeout| Block["Fail-Closed Block Response"]
UI -->|Manage Policies & Baselines| DB
Engine -->|Record Calls & Incidents| DB
Engine -->|Write Chain Record| AUDIT详细执行流程和安全管道
sequenceDiagram
autonumber
actor Client as AI Agent Client
participant FastMCP as FastMCP Server (server.py)
participant Base as Schema Baseline Manager
participant Policy as Policy Engine
participant Gate as Human Confirmation Gate
participant Admin as Admin Dashboard (/dashboard)
participant Upstream as Upstream MCP Server
participant Stage1 as Stage 1: Rule Prefilter
participant Stage2 as Stage 2: LLM Classifier
participant Audit as SHA-256 Audit Log
Client->>FastMCP: 1. Request check_tool_security (tool_name, payload)
FastMCP->>Base: 2. Check tool baseline schema status
alt Schema modified or unapproved (Rug-Pull)
Base-->>FastMCP: Flagged schema mismatch
FastMCP->>Audit: Log Rug-Pull Incident
FastMCP-->>Client: Return Error: Tool schema unapproved
else Approved Baseline
Base-->>FastMCP: Baseline OK
end
FastMCP->>Policy: 3. Evaluate Call Policy
alt Policy = Blocked / Rate-Limited
Policy-->>FastMCP: Action Blocked
FastMCP-->>Client: Return Error: Blocked by security policy
else Policy = Held for Confirmation
Policy->>Gate: 4. Create Pending Approval Request
Gate->>Admin: Notify Admin on Dashboard
Admin->>Gate: 5. Admin Approves / Denies (or Timeout)
alt Denied or Timed Out (Fail-Closed)
Gate-->>FastMCP: Action Denied
FastMCP-->>Client: Return Error: High-risk action denied
else Approved
Gate-->>FastMCP: Action Approved
end
end
FastMCP->>Stage1: 6. Scan Response (Stage 1 Rule Prefilter)
alt Stage 1 Matches Known Attack Vector
Stage1-->>FastMCP: Verdict: Malicious
FastMCP->>Audit: Record Security Incident & Audit Log
FastMCP-->>Client: Return Safe Error: Response blocked
else Stage 1 Suspicious / Ambiguous
FastMCP->>Stage2: 7. Escalate to Stage 2 LLM Classifier
Stage2-->>FastMCP: Verdict & Reason (or Fail-Closed on Error)
alt Verdict = Malicious / Error
FastMCP->>Audit: Record Security Incident & Audit Log
FastMCP-->>Client: Return Safe Error: Response blocked
else Verdict = Clean
FastMCP->>Audit: Write Hash-Chained Audit Entry
FastMCP-->>Client: 8. Return Verified Clean Response
end
else Stage 1 Clean
FastMCP->>Audit: Write Hash-Chained Audit Entry
FastMCP-->>Client: 8. Return Verified Clean Response
end🔑 环境配置(.env)
网关从 .env 读取通用 LLM 环境配置:
# LLM Security Classifier API Key (Supports OpenAI, DeepSeek, Grok, Ollama)
LLM_API_KEY="your-llm-api-key-here"
LLM_API_URL="https://api.openai.com/v1/chat/completions" # or https://api.x.ai/v1/chat/completions, https://api.deepseek.com/v1/chat/completions
LLM_MODEL="gpt-4o-mini" # or grok-2-latest, deepseek-chat, llama3, etc.
ADMIN_API_KEY="trust-gateway-admin-key-secret"
DATABASE_URL="sqlite+aiosqlite:///mcp_trust_gateway.db"
FAIL_CLOSED=true
CLASSIFIER_TIMEOUT_SECONDS=3.0
CONFIRMATION_TIMEOUT_SECONDS=60☁️ 部署和客户端集成
1. 部署到 FastMCP 云
将此仓库推送到 GitHub。
转到 fastmcp.cloud 并创建新服务器:
入口点:
server.py环境变量:
LLM_API_KEY=your-api-key-here
点击 部署。FastMCP 云提供您的端点:
MCP SSE 服务器:
https://mcp.fastmcp.cloud/your-username/mcp-trust-gateway/sse管理仪表板:
https://mcp.fastmcp.cloud/your-username/mcp-trust-gateway/dashboard
2. 客户端配置
🤖 Google Antigravity 和 Claude Desktop(mcp_config.json)
{
"mcpServers": {
"mcp-trust-gateway": {
"url": "https://mcp.fastmcp.cloud/your-username/mcp-trust-gateway/sse"
}
}
}💻 Claude Code(CLI)
claude mcp add mcp-trust-gateway --transport sse \
https://mcp.fastmcp.cloud/your-username/mcp-trust-gateway/sse🧪 测试和对抗性回归套件
运行完整的 pytest 套件,包括对抗性回归测试套件:
pytest -v达到的指标
📊 对抗性捕获率:100%(目标:≥95%)
📊 误报率:0%(目标:<2%)
📝 设计决策
故障关闭默认值:所有模糊响应、分类器超时、网络问题或未经批准的模式修改均故障关闭(阻止操作并提醒管理员)。
凭据编辑:与敏感键匹配的密钥、API 令牌和密码在保存到审计存储之前会自动编辑。
阶段 1 快速过滤器 + LLM 升级:已知的恶意模式由阶段 1 立即拦截,消除了明显攻击的延迟和 API 开销,同时利用 LLM 进行复杂的语义分析。
防篡改哈希链:每个日志条目计算
SHA256(actor | action | target | details | prev_hash | timestamp),确保不可否认性和日志篡改检测。
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- AlicenseNot gradedqualityAmaintenanceSecurity gateway for MCP tool calls. Sits between your LLM client and MCP servers, enforcing per-tool policies (allow/block/approve/read-only), logging every call, and pausing dangerous operations for human approval in terminal or Slack.21MIT
- AlicenseNot gradedqualityCmaintenanceMCP server for AI agent security guardrails. Provides input validation, prompt injection detection, PII redaction, output filtering, policy enforcement, rate limiting, and comprehensive audit logging.451MIT
- AlicenseNot gradedqualityAmaintenanceA zero-trust security gateway for MCP tool calls, inspecting tool identity, arguments, execution decisions, and returned content before risk reaches your coding agent.Apache 2.0
- AlicenseNot gradedqualityDmaintenanceA defensive gateway and firewall for AI agents using MCP servers, scanning tool calls, responses, and manifests for prompt injection, secrets, dangerous commands, and drift before allowing execution.MIT
Related MCP Connectors
Security firewall for AI agents — scans MCP calls for injection, secrets, and risks.
Security scanner for MCP servers. Detect vulnerabilities, prompt injection, and tool poisoning.
Scans MCP servers for tool poisoning, prompt injection and supply chain risks.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/sudo-hrmn/MCP-Gatekeeper'
If you have feedback or need assistance with the MCP directory API, please join our Discord server