mcp-gate
mcp-gate
一个路径就是一条请求。根目录边界就是保证。
MCP 文件访问服务器通过 根目录(roots)——一组已授权的目录——来规定模型可以访问哪些文件。mcp-gate 演示了 告诉 服务器停留在其根目录内与 强制执行 这一点之间的区别:同一套攻击测试会针对两个版本运行,一个版本只有一条指令,另一个版本在读取任何文件之前先对每个路径进行规范化,并检查它是否处于边界之内。一个会泄露,一个能守住。两个方向都在 CI 中得到验证。
这是对 Anthropic 高级 MCP 材料中概念的独立实现,旨在明确展示三件事:
能力 | 体现位置 |
高级 MCP 服务器 |
|
日志与进度 | 每个工具在运行时都会流式发送 MCP 日志通知( |
访问控制 |
|
两种模式
模式 | 判断方式 | 结果 |
| 系统提示词中的指令仅表示“只读取根目录下的文件”,但路径仍按原样打开。 | 泄露 —— 朴素的路径处理器是一个刻意设计的最坏情况对照。 |
| 每个路径先解码,然后通过 | 阻止 —— 越界请求在打开任何文件之前就会被拒绝。 |
攻击套件
攻击 |
|
|
| 已返回 ✓ | 已返回 ✓ |
| 泄露 | 已阻止 |
| 泄露 | 已阻止 |
| 泄露 | 已阻止 |
| 泄露 | 已阻止 |
direct_ask 在 两种 模式下都能成功,这正是“欺骗”之处:对提示层安全性进行快速的手动测试看起来是安全的,然后在你没有尝试过的攻击下失败。
Related MCP server: personal-mcp-bridge
门禁(CI 强制,双向)
python -m mcp_gate gate boundary # exit 0 only if 0 escapes
python -m mcp_gate gate prompt # exit 0 only if the leak is still demonstrated
python -m mcp_gate suite # both halves must hold如果 gate prompt 未能泄露,就意味着演示已经失去意义(如果非安全模式也能通过,“安全”结果也就毫无意义),所以 CI 同样会将该情况视为构建失败。
快速开始
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
pytest -q
python -m mcp_gate gate boundary
python -m mcp_gate gate prompt
python -m mcp_gate suite运行实时 MCP 服务器 + 客户端演示(需要 pip install -e ".[demo]" 并在环境变量中配置 ANTHROPIC_API_KEY 以支持采样工具):
python -m mcp_gate serve ./data/sandbox # start the server over stdio
python -m mcp_gate.client ./data/sandbox # drive it: logs, progress, sampling, a blocked attack参见 RESULTS.md 获取捕获的输出——其中每个代码块都是真实的命令输出,由 scripts/make_results.py 重新生成,从未手动编辑。
说明
data/下的所有数据都是虚构的;data/out_of_bounds/secret.txt是“服务器绝不能提供的文件”的替代品。属于
-gate家族:一切都要先通过门禁,否则不会发布。
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Bounded readonly SHA256 verification with the official MCP SDK. No code execution or model calls.
Read-only verifier for 25 ProofRelay MCP tools and non-confidential evidence bundles.
Read authorized Loam tables and supported external databases through a bounded MCP connection.
MCP enforcement layer that intercepts AI agent actions and blocks rule violations before execution.
Related MCP Servers
- AlicenseAqualityDmaintenanceProvides safe local file operations through MCP, including reading, writing, searching, organizing, and protected deletion with configurable path restrictions.121ISC
- AlicenseNot gradedqualityDmaintenanceEnables safe, read-only browsing of allowlisted local directories through MCP, providing tools to list roots, read files, and search text.MIT
- AlicenseNot gradedqualityDmaintenanceProvides safe, allowlisted local filesystem access for MCP-compatible AI clients, enabling directory listing, file reading/writing (with byte limits), and text search while blocking paths outside approved roots and symlink escapes.MIT
- FlicenseNot gradedqualityDmaintenanceEnables secure filesystem operations (read, write, list, move, search files/directories) through the Model Context Protocol, with dynamic directory access control via MCP Roots.-