🚀 🧩 GlassTape策略构建器MCP服务器
GlassTape策略构建器是一个开源的MCP服务器,它能够将自然语言形式的安全要求转化为Cerbos YAML策略,并具备自动验证、测试和红队分析功能。它让安全和工程团队能够将AI代理和应用程序与策略即代码框架集成,为工具调用拦截、数据访问和模型工作流提供零信任防护。
🚀 快速开始
1. 前提条件
安装Cerbos CLI(策略验证必需):
brew install cerbos/tap/cerbos
curl -L https://github.com/cerbos/cerbos/releases/latest/download/cerbos_Linux_x86_64 \
-o /usr/local/bin/cerbos && chmod +x /usr/local/bin/cerbos
cerbos --version
2. 从源代码安装
git clone https://github.com/glasstape/glasstape-policy-builder-mcp.git
cd glasstape-policy-builder-mcp/agent-policy-builder-mcp
pip install -e .
pip install -e ".[anthropic]"
pip install -e ".[openai]"
pip install -e ".[llm]"
pip install -e ".[dev]"
3. 配置MCP客户端
Claude Desktop (~/Library/Application Support/Claude/claude_desktop_config.json):
{
"mcpServers": {
"glasstape-policy-builder": {
"command": "glasstape-policy-builder-mcp"
}
}
}
Cursor/Zed:在IDE的MCP设置中添加类似配置。
可选:服务器端大语言模型(用于自然语言处理):
{
"mcpServers": {
"glasstape-policy-builder": {
"command": "glasstape-policy-builder-mcp",
"env": {
"LLM_PROVIDER": "anthropic",
"ANTHROPIC_API_KEY": "sk-ant-your-key"
}
}
}
}
4. 使用示例
生成策略(在Claude Desktop或支持MCP的IDE中):
Create a payment policy for AI agents:
- Allow payments up to $50
- Block sanctioned entities
- Limit to 5 transactions per 5 minutes
列出可用模板:
list_templates
验证策略:
validate_policy with policy_yaml: "<your-cerbos-yaml>"
5. 故障排除
未找到Cerbos CLI:
- 确保Cerbos CLI已安装并在系统路径中
- 运行
cerbos --version 验证安装(注意:是 --version 而非 version)
MCP服务器无法连接:
- 检查MCP客户端配置
- 配置更改后重启IDE
- 验证命令路径是否正确:
which glasstape-policy-builder-mcp
安装失败,提示 "Unable to determine which files to ship":
- 这是已知的hatch构建问题 - 确保你在正确的目录中
- pyproject.toml 应包含
[tool.hatch.build.targets.wheel] 配置
MCP导入错误:
- 确保你有正确的MCP导入:
from mcp.server import Server
- 尝试重新安装:
pip install -e . --force-reinstall
策略验证失败:
- 检查生成策略的YAML语法
- 确保Cerbos CLI正常工作:
cerbos compile --help
- 查看错误消息以确定具体问题
安装后命令未找到:
- 确保你使用的是Python 3.10或更高版本
- 检查pyproject.toml中的入口点是否正确配置
✨ 主要特性
- ⚙️ 自然语言转策略 – 使用Claude或AWS Q从纯英文生成Cerbos策略
- 🧠 自动验证 – 使用Cerbos CLI (
cerbos compile, cerbos test) 进行语法和逻辑检查
- 🧪 红队分析 – 六点安全分析并提供自动改进建议
- 🧩 MCP集成 – 可在Cursor、Zed和Claude Desktop等IDE中原生使用
- 🔒 离线操作 – 本地优先设计,无外部依赖
- 🏷️ 基于主题的治理 – 40多个内容主题,具备安全分类
- 🧾 合规模板 – 内置SOX、HIPAA、PCI-DSS和欧盟AI法案的合规模板
📦 安装指南
从源代码安装
git clone https://github.com/glasstape/glasstape-policy-builder-mcp.git
cd glasstape-policy-builder-mcp/agent-policy-builder-mcp
pip install -e .
pip install -e ".[anthropic]"
pip install -e ".[openai]"
pip install -e ".[llm]"
pip install -e ".[dev]"
💻 使用示例
基础用法
生成策略(在Claude Desktop或支持MCP的IDE中):
Create a payment policy for AI agents:
- Allow payments up to $50
- Block sanctioned entities
- Limit to 5 transactions per 5 minutes
高级用法
列出可用模板:
list_templates
验证策略:
validate_policy with policy_yaml: "<your-cerbos-yaml>"
📚 详细文档
可用工具
当通过MCP连接时,你可以在Claude或IDE中使用以下工具:
| 工具 |
功能 |
generate_policy |
将自然语言转换为经过验证的Cerbos YAML策略,并进行主题治理 |
validate_policy |
使用 cerbos compile 检查策略语法 |
test_policy |
使用 cerbos compile 对策略运行测试套件 |
suggest_improvements |
六点安全分析并提供自动改进建议 |
list_templates |
浏览内置模板(金融、医疗、AI安全等) |
示例工作流程:
1. "Generate a payment policy for AI agents with $50 limit..."
→ Claude调用generate_policy
2. "Show me available financial templates"
→ Claude调用list_templates
3. "Test this policy with the test suite"
→ Claude调用test_policy
4. "Analyze this policy for security issues"
→ Claude调用suggest_improvements
5. "Validate the policy syntax"
→ Claude调用validate_policy
示例输出
输入:
"Allow AI agents to execute payments up to $50. Block sanctioned entities.
Limit cumulative hourly amount to $50. Maximum 5 transactions per 5 minutes."
生成的带主题治理的策略:
apiVersion: api.cerbos.dev/v1
resourcePolicy:
version: "1.0.0"
resource: "payment"
rules:
- actions: ["execute"]
effect: EFFECT_ALLOW
condition:
match:
expr: >
request.resource.attr.amount > 0 &&
request.resource.attr.amount <= 50 &&
!(request.resource.attr.recipient in request.resource.attr.sanctioned_entities) &&
(request.resource.attr.cumulative_amount_last_hour + request.resource.attr.amount) <= 50 &&
request.resource.attr.agent_txn_count_5m < 5 &&
has(request.resource.attr.topics) &&
"payment" in request.resource.attr.topics &&
!("adult" in request.resource.attr.topics)
- actions: ["*"]
effect: EFFECT_DENY
附加特性:
- ✅ 基于主题的治理(支付、PII检测)
- ✅ 安全分类(G/PG/PG_13/R/成人内容)
- ✅ 15多个自动测试用例
- ✅ 由
cerbos compile 验证
- ✅ 六点安全分析
- ✅ 可直接部署的捆绑包
完整示例
| 类别 |
示例 |
描述 |
| 金融 |
payment_policy.md |
带限制的支付执行 |
| 医疗 |
phi_access_policy.md |
符合HIPAA的PHI访问 |
| AI安全 |
ai_model_invocation_policy.md |
带防护栏的模型调用 |
| 数据访问 |
pii_export_policy.md |
符合GDPR的PII导出控制 |
| 系统 |
admin_access_policy.md |
带MFA的管理员访问 |
查看 examples/README.md 获取完整示例。
🔧 技术细节
架构
flowchart TD
A["自然语言策略请求"] --> B["GlassTape MCP服务器"]
B --> C["中间规范策略 - JSON"]
C --> D["Cerbos YAML策略生成"]
D --> E["Cerbos CLI验证 + 测试"]
E --> F["可部署的策略捆绑包"]
关键创新:
ICP(中间规范策略)作为一种与语言无关的中间表示,支持确定性生成、策略可移植性和形式验证。
开发
git clone https://github.com/glasstape/glasstape-policy-builder-mcp.git
cd glasstape-policy-builder-mcp
pip install -e ".[dev]"
pytest
black src/ tests/
🤝 贡献
我们欢迎贡献!请查看 CONTRIBUTING.md 获取贡献指南。
快速链接:
📄 许可证
本项目基于 Apache 2.0许可证 发布。
© 2025 GlassTape, Inc.
💡 链接
由 GlassTape 用心打造 — 让AI代理默认安全。