AI治理策略生成器

GlassTape Policy Builder是一款开源MCP服务器,可将自然语言安全需求转换为Cerbos YAML策略,并提供自动化验证、测试和红队分析功能,适用于AI代理和应用程序的策略即代码集成。

  • by GlassTape
  • Python
  • 本地部署
  • 3 星标
  • 更新于
在 GitHub 查看 GlassTape/agent-policy-builder-mcp

使用说明

🧩 GlassTape策略生成器MCP服务器

将自然语言转化为生产就绪的人工智能治理政策。

玻璃胶带 策略生成器 是一个开源 MCP服务器 将自然语言安全要求转换为 Cerbos YAML政策 通过自动化验证、测试和红队。
它使安全和工程团队能够整合 AI代理和应用程序 随着 政策即代码 框架——为工具调用拦截、数据访问和模型工作流带来零信任护栏。

🚀 特性

  • ⚙️ 自然语言政策 –使用Claude或AWS Q从简单的英语生成Cerbos策略
  • 🧠 自动验证 –使用Cerbos CLI(cerbos compile, cerbos test)用于语法和逻辑检查
  • 🧪 红队分析 –6点安全分析,自动提出改进建议
  • 🧩 MCP集成 –在IDE中原生工作,如 光标, 泽德,以及 克劳德桌面
  • 🔒 气隙操作 –本地优先设计,无外部依赖
  • 🏷️ 基于主题的治理 –40多个安全分类的内容主题
  • 🧾 合规性模板 –SOX、HIPAA、PCI-DSS和欧盟AI法案的内置模板

🚀 快速开始

1.先决条件

安装Cerbos CLI (政策验证所需):

# macOS
brew install cerbos/tap/cerbos

# Linux
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

# Verify installation
cerbos --version

2.从源代码安装

# Clone the repository
git clone https://github.com/glasstape/glasstape-policy-builder-mcp.git
cd glasstape-policy-builder-mcp/agent-policy-builder-mcp

# Basic installation
pip install -e .

# With optional LLM support (for server-side natural language parsing)
pip install -e ".[anthropic]"  # Anthropic Claude
pip install -e ".[openai]"     # OpenAI GPT
pip install -e ".[llm]"        # All LLM providers

# Development installation
pip install -e ".[dev]"

3.配置您的MCP客户端

克劳德桌面 (~/Library/Application Support/Claude/claude_desktop_config.json):

{
  "mcpServers": {
    "glasstape-policy-builder": {
      "command": "glasstape-policy-builder-mcp"
    }
  }
}

光标/Zed:在IDE的MCP设置中添加类似的配置。

可选:服务器端LLM (用于自然语言处理):

{
  "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已安装并位于您的PATH中
  • 跑 cerbos --version 验证安装(注意: --version 不 version)

MCP服务器未连接:

  • 检查您的MCP客户端配置
  • 配置更改后重新启动IDE
  • 验证命令路径是否正确: which glasstape-policy-builder-mcp

安装失败,显示“无法确定要发送哪些文件”:

  • 这是一个已知的舱口构建问题-确保您在正确的目录中
  • 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中的入口点是否配置正确

🦭 可用工具

通过MCP连接时,您可以在Claude或IDE中使用这些工具:

工具 它做什么
generate_policy 转换自然语言→ 使用主题治理验证Cerbos YAML
validate_policy 使用检查策略语法 cerbos compile
test_policy 根据策略运行测试套件 cerbos compile
suggest_improvements 6点安全分析,并自动提出改进建议
list_templates 浏览内置模板(金融、医疗保健、人工智能安全)

工作流程示例:

1. "Generate a payment policy for AI agents with $50 limit..."
   → Claude calls generate_policy
   
2. "Show me available financial templates"
   → Claude calls list_templates
   
3. "Test this policy with the test suite"
   → Claude calls test_policy
   
4. "Analyze this policy for security issues"
   → Claude calls suggest_improvements
   
5. "Validate the policy syntax"
   → Claude calls 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."

生成带有主题治理的策略:

# policies/payment_policy.yaml
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
  • ✅ 6点安全分析
  • ✅ 已准备好部署捆绑包

📋 完整示例

类别 示例 描述
金融 payment_policy.md 有限额的付款执行
医疗保健 phi_access_policy.md 符合HIPAA标准的PHI访问
AI安全 ai_modelinvocation_policy.md 带护栏的模型调用
数据访问 pii_rexport_policy.md 符合GDPR的PII出口管制
系统 admin_access_policy.md 使用MFA进行管理员访问

看 示例/README.md 查看完整示例。

🧱 建筑

flowchart TD
  A["Natural-language policy request"] --> B["GlassTape MCP Server"]
  B --> C["Intermediate Canonical Policy - JSON"]
  C --> D["Cerbos YAML policy generation"]
  D --> E["Cerbos CLI validation + testing"]
  E --> F["Ready-to-deploy policy bundle"]

关键创新: ICP(Intermediate Canonical Policy)是一种与语言无关的中间表示,支持确定性生成、策略可移植性和形式验证。

🧪 发展

# Clone and setup
git clone https://github.com/glasstape/glasstape-policy-builder-mcp.git
cd glasstape-policy-builder-mcp
pip install -e ".[dev]"

# Run tests
pytest

# Format code
black src/ tests/

🤝 贡献

我们欢迎捐款!看 贡献.md 作为指导方针。

快速链接:


💪 许可证

根据 Apache 2.0许可证. ©2025 GlassTape,股份有限公司。


💡 链接


内置❤️ 通过 玻璃胶带 — 默认情况下使AI代理安全。