Gemara MCP服务器

Gemara MCP服务器是一个最小化的MCP风格服务器,通过SSE公开Gemara创作和转换工具,并将请求代理到Gemara HTTP后端。

  • by gvauter
  • Go
  • 云端部署
  • 更新于
在 GitHub 查看 gvauter/gemara-mcp-server

使用说明

Gemara MCP服务器(SSE适配器)

最小的MCP风格服务器,通过SSE公开Gemara创作和转换工具,并将请求代理到您的Gemara HTTP后端。

端点(MCP适配器)

  • GET /sse:宣布可用工具(MCP兼容的SSE)。
  • POST /message:使用JSON有效载荷按名称调用工具并返回结果。

工具(通用、层无关)

  • convert_to_gemara:
    • args: { "layer": 1|2|3, "framework": "string", "text": "string" }
    • 结果:Gemara工件(从YAML解析的JSON)。
    • description:将源文本(例如,从PDF/DOCX中提取)转换为指定层的Gemara工件。使用具有严格CUE模式验证和修复循环(在后端)的LLM。
    • MCP呼叫有效载荷示例:
      {
        "id": "1",
        "tool": "convert_to_gemara",
        "args": {
          "layer": 1,
          "framework": "PCI DSS",
          "text": "1. Install and maintain a firewall configuration...\n1.1 Establish and implement firewall rules..."
        }
      }
      
    • 示例用户提示(用于MCP感知助手):“将此PCI部分转换为有效的Gemara Layer 1 YAML工件。”
  • author_gemara:
    • args: { "layer": 1|2|3, "framework": "string", "instructions": "string" }
    • 结果:Gemara伪影。
    • description:根据自然语言指令(无源文本)为指定层编写一个新的Gemara工件。在后端强制只输出YAML和严格的模式。
    • MCP呼叫有效载荷示例:
      {
        "id": "2",
        "tool": "author_gemara",
        "args": {
          "layer": 2,
          "framework": "OSPS Baseline",
          "instructions": "Create 3 concise controls for CI pipeline security: signed artifacts, dependency scanning, and SBOM publication."
        }
      }
      
    • 示例用户提示:“为具有3个控件的CI管道安全编写Gemara Layer 2控件集。”
  • validate_gemara:
    • args: { "layer": 1|2|3, "artifact": { ... } }
    • 结果: { "ok": true } 或 { "ok": false, "error": "..." }.
    • description:根据指定层的Gemara CUE模式验证工件。需要 GEMARA_SCHEMA_DIR 在后端配置。对于第1层,后端也可以进行结构回退。
    • MCP呼叫有效载荷示例:
      {
        "id": "3",
        "tool": "validate_gemara",
        "args": {
          "layer": 1,
          "artifact": {
            "$schema": "https://github.com/ossf/gemara/schemas/layer1",
            "framework": "PCI DSS",
            "guidelines": [{ "id": "1", "title": "Install and maintain a firewall", "text": "" }]
          }
        }
      }
      
    • 示例用户提示:“检查此Gemara文档是否对第1层有效。”
  • repair_gemara:
    • args: { "layer": 1|2|3, "framework": "string", "yaml": "string", "error": "string" }
    • 结果:Gemara伪影。
    • 描述:给定无效的Gemara YAML和验证错误消息,要求LLM最低限度地修复YAML,然后重新验证。
    • MCP呼叫有效载荷示例:
      {
        "id": "4",
        "tool": "repair_gemara",
        "args": {
          "layer": 3,
          "framework": "Security Policy",
          "yaml": "framework: Security Policy\npolicies:\n- title: Missing id\n",
          "error": "policies[0].id is required"
        }
      }
      
    • 示例用户提示:“修复此第3层YAML,使其通过模式验证。只有最小的更改。”
  • merge_gemara:
    • args: { "layer": 1|2|3, "framework": "string", "artifacts": [ ... ] }
    • 结果:Gemara伪影(针对第1层实现)。
    • description:将多个工件合并为一个工件。目前为第1层实现(按id+title进行重复数据消除,保留框架(如果提供))。
    • MCP呼叫有效载荷示例:
      {
        "id": "5",
        "tool": "merge_gemara",
        "args": {
          "layer": 1,
          "framework": "PCI DSS",
          "artifacts": [
            { "$schema": ".../layer1", "framework": "PCI DSS", "guidelines": [{ "id": "1", "title": "Firewall", "text": "" }] },
            { "$schema": ".../layer1", "framework": "PCI DSS", "guidelines": [{ "id": "1", "title": "Firewall", "text": "" }, { "id": "2", "title": "Passwords", "text": "" }] }
          ]
        }
      }
      
    • 示例用户提示:“合并这两个第1层片段并删除重复片段。”

工具(L1遗留,为兼容而保留)

  • convert_to_layer1, author_layer1, repair_layer1, validate_layer1, merge_layer1.
    • description:上述通用工具的第1层特定变体。适用于较旧的客户端设置。更喜欢通用工具,以防未来。

需求

  • 正在运行的Gemara HTTP后端(来自Gemara cli cmd/server)暴露:
    • /v1/convert_to_gemara, /v1/author_gemara, /v1/validate_gemara, /v1/repair_gemara, /v1/merge_gemara,加上传统的L1端点。
  • 严格的架构验证(推荐):
    • 集 GEMARA_SCHEMA_DIR 对于Gemara模式根的后端(例如。 /home/.../ossf/gemara/schemas).

跑

  1. 启动Gemara后端(在Gemara-cli仓库中):
export GEMARA_SCHEMA_DIR=/path/to/ossf/gemara/schemas
./bin/server
  1. 启动MCP适配器(此仓库):
./bin/gemara-mcp --addr :8090 --backend http://localhost:8080

您还可以设置 GEMARA_HTTP_BACKEND_URL 而不是 --backend.

快速测试(无MCP主机)

  • 列出工具(浏览器中的SSE流或curl): http://localhost:8090/sse
  • 调用工具:
curl -s http://localhost:8090/message \
  -H 'Content-Type: application/json' \
  -d '{
        "id":"1",
        "tool":"convert_to_gemara",
        "args":{
          "layer":1,
          "framework":"PCI DSS",
          "text":"1. Install and maintain a firewall configuration..."
        }
      }'

MCP主机配置(示例)

将支持MCP的客户端指向SSE端点,例如:

{
  "mcpServers": {
    "gemara": {
      "url": "http://localhost:8090/sse"
    }
  }
}

此适配器仅代理请求;所有模式实施和LLM工作都由Gemara HTTP后端执行。