MCP 服务器的安全网关——每次工具调用都要在门口接受检查。
CI npm License: Apache-2.0 PRs welcome
mcp-doorman 是一个即插即用代理,位于你的 AI 智能体(Claude Desktop、Claude Code、Cursor、VS Code 或任何 MCP 客户端)与其使用的 MCP 服务器之间。一条命令,零基础设施,每个 tools/list 和 tools/call 都会经过一个防护管道:
每个人都只差一个 npx some-random-mcp-server 就能将一个未经审查的进程交给他们的 API 密钥,并让该进程直接访问模型上下文窗口。已记录的几类攻击是真实的,而非假设:
企业级 MCP 网关针对拥有 Kubernetes 集群的平台团队存在。没有轻量级方案保护个体开发者的笔记本电脑——而这里正是 99% 的 MCP 服务器实际运行的地方。 这正是本项目填补的空白。
# 1. Create a config
npx -y mcp-doorman init
# 2. Edit doorman.config.json — put your real servers in it
# 3. Pin the current tool definitions (trust on first use)
npx -y mcp-doorman pin --config doorman.config.json
然后让你的客户端将网关作为替代你的服务器来指向。Claude Desktop / Claude Code / Cursor:
// BEFORE — every server talks straight to the model
{
"mcpServers": {
"github": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-github"] },
"filesystem": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-filesystem", "/repos"] }
}
}
// AFTER — one doorman guards them all
{
"mcpServers": {
"doorman": {
"command": "npx",
"args": ["-y", "mcp-doorman", "run", "--config", "/absolute/path/to/doorman.config.json"]
}
}
}
工具会以命名空间形式显示,如 github__create_issue、filesystem__read_file 等,另外还有两个内置工具:doorman__status 和 doorman__recent_events(可以询问你的智能体*“doorman 最近阻止了什么?”*)。
Windows 提示: 如果服务器条目直接使用
npx,请通过 cmd 启动:"command": "cmd", "args": ["/c", "npx", "-y", "..."]。
git clone https://github.com/Sushank05/mcp-doorman && cd mcp-doorman
npm install
npm run demo
演示会将网关连接到一个故意行为异常的服务器(examples/demo-server.mjs),该服务器会泄露虚假凭证、提供提示注入载荷,并提供一个破坏性工具——同时展示每个防护如何捕获它们。
flowchart LR
A["MCP client\n(Claude Desktop, Cursor, ...)"] -- stdio --> D
subgraph D [mcp-doorman]
direction TB
P[policy] --> R[rate limit] --> AP[approval] --> RD[redaction] --> I[injection scan] --> AU[(audit log)]
end
D -- stdio --> S1[github server]
D -- stdio --> S2[filesystem server]
D -- streamable HTTP --> S3[remote server]网关对于你的客户端来说是一个 MCP 服务器,对于每个上游(stdio 子进程或可流式 HTTP 端点)来说是一个 MCP 客户端,将所有服务器聚合到一个连接后面。它基于官方 TypeScript SDK 构建。
所有内容都存放在一个 JSON 文件中。完整示例包含所有选项:
{
"servers": {
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": { "GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_TOKEN}" } // ${VAR} = read from gateway env
},
"remote": { "url": "https://mcp.example.com/mcp", "headers": { "Authorization": "Bearer ${MCP_TOKEN}" } }
},
"policy": {
"defaultAction": "allow", // "allow" | "deny" | "approve"
"rules": [ // first match wins, evaluated top-down
{ "match": "*__delete*", "action": "deny", "reason": "no destructive tools" },
{ "match": ["github__create_*", "*__send_*"], "action": "approve" },
{ "match": "filesystem__*", "action": "allow" }
]
},
"redaction": {
"enabled": true,
"disable": [], // built-in rule names to turn off
"enableOptIn": ["email"], // opt-ins: "email", "us-ssn", "ipv4"
"custom": [{ "name": "acme-id", "pattern": "ACME-[0-9]{6}" }],
"redactArguments": false // also scrub model-supplied arguments
},
"injection": {
"action": "flag", // "flag" (warn the model) | "block" | "off"
"scanToolDescriptions": true, // tool-poisoning check on tools/list
"custom": []
},
"pinning": {
"enabled": true,
"onNewTool": "pin", // "pin" (TOFU) | "block" (until `mcp-doorman pin`)
"onChangedTool": "block" // "block" | "warn"
},
"rateLimit": { "perMinute": 120, "perTool": { "*__send_*": 5 } },
"approval": { "fallback": "deny", "timeoutMs": 120000 }, // fallback when client lacks elicitation
"audit": { "enabled": true, "includeArguments": true, "includeResults": false },
"logLevel": "info"
}
固定状态和审计日志默认存储在配置文件旁边的 <config-name>.pins.json / <config-name>.audit.jsonl 中。
| 命令 | 功能 |
|---|---|
mcp-doorman run --config <path> | 通过 stdio 启动网关(默认命令) |
mcp-doorman pin --config <path> | 连接到所有上游并固定(信任)其当前工具定义 |
mcp-doorman init | 使用合理的默认值写入一个入门配置 |
过度宣传的安全工具比没有更糟糕。请阅读这部分。
deny/approve 策略作为硬边界;筛查只是纵深防御。approval.fallback(默认 deny)。resources/* 和 prompts/* 代理(目前仅支持工具)doorman-rules-finance、doorman-rules-healthcare……)mcp-doorman audit 子命令:格式化输出并查询 JSONL 日志挑选上述任意一项,或从 [good first issue](https://github.com/YOUR_GITHUB_USERNAME/mcp-doorman/labels/good%20first%20issue) 开始。新增检测规则是最容易的贡献:一条正则表达式 + 两个测试。请参阅 CONTRIBUTING.md 和 docs/detection-rules.md。
npm install
npm test # 69 tests: unit + full stdio e2e
npm run build
npm run demo # watch the guards fire live
Apache-2.0 — 可自由用于任何用途,并明确授予专利许可。
| 攻击类型 | 运作方式 |
|---|
| 工具投毒 | 恶意的指令隐藏在工具的描述中,在大多数客户端 UI 中不可见 |
| 拉地毯(Rug pull) | 服务器第一天呈现无害工具,在你批准后悄悄替换定义 |
| 间接提示注入 | 由合法工具获取的网页/问题/邮件包含针对模型的指令 |
| 秘密信息泄露 | 一个工具结果中泄露的凭证 + 一条注入指令 = 你的密钥出现在别人的服务器上 |
| 失控循环 | 被混淆或劫持的智能体批量删除、批量发送邮件、批量抓取 |