{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.anguskit.com/schema/anguscopilot/1.0.0/mcp.json",
  "title": "MCP Configuration",
  "description": "MCP（Model Context Protocol）配置块。声明本 Agent 作为 MCP 客户端消费的服务，以及作为 MCP Server 暴露的能力。",
  "type": "object",
  "properties": {

    "client": {
      "description": "本 Agent 作为 MCP 客户端，连接的外部 MCP 服务列表。",
      "type": "array",
      "items": {
        "type": "object",
        "required": ["name", "transport"],
        "properties": {
          "name": { "$ref": "common.json#/$defs/Identifier" },
          "transport": {
            "type": "string",
            "enum": ["stdio", "http", "sse"]
          },
          "command": {
            "description": "stdio 传输的启动命令。",
            "type": "string"
          },
          "args": {
            "description": "stdio 传输的启动参数。",
            "type": "array",
            "items": { "type": "string" }
          },
          "url": {
            "description": "http / sse 传输的服务 URL。",
            "type": "string",
            "format": "uri"
          },
          "credentialRef": { "$ref": "common.json#/$defs/SecretRef" },
          "timeout": { "$ref": "common.json#/$defs/Duration" },
          "namespace": {
            "description": "导入到本地 CapabilityRegistry 的命名空间前缀。",
            "$ref": "common.json#/$defs/Identifier"
          }
        },
        "$comment": "transport=stdio 必须有 command；transport=http/sse 必须有 url。",
        "allOf": [
          {
            "if": { "properties": { "transport": { "const": "stdio" } }, "required": ["transport"] },
            "then": { "required": ["command"] }
          },
          {
            "if": { "properties": { "transport": { "enum": ["http", "sse"] } }, "required": ["transport"] },
            "then": { "required": ["url"] }
          }
        ],
        "unevaluatedProperties": false
      },
      "uniqueItems": true
    },

    "server": {
      "description": "将本 Agent 暴露为 MCP Server。",
      "type": "object",
      "properties": {
        "enabled": { "type": "boolean", "default": false },
        "transport": {
          "type": "array",
          "items": { "type": "string", "enum": ["stdio", "http", "sse"] },
          "uniqueItems": true,
          "minItems": 1
        },
        "exposeCapabilities": {
          "description": "暴露的 Capability 标签过滤；空数组等于全部暴露。",
          "type": "array",
          "items": { "type": "string" }
        },
        "exposeMemory": {
          "description": "是否将 Memory 暴露为 MCP Resources。",
          "type": "boolean",
          "default": false
        },
        "exposePrompts": {
          "description": "是否将提示词模板暴露为 MCP Prompts。",
          "type": "boolean",
          "default": false
        },
        "auth": {
          "description": "外部 MCP 客户端访问本 Server 的鉴权策略。",
          "type": "object",
          "properties": {
            "mode": {
              "type": "string",
              "enum": ["none", "api-key", "oauth2", "mtls"],
              "default": "none"
            },
            "credentialRef": { "$ref": "common.json#/$defs/SecretRef" }
          },
          "$comment": "mode!=none 时必须配置 credentialRef。",
          "if": {
            "properties": { "mode": { "not": { "const": "none" } } },
            "required": ["mode"]
          },
          "then": { "required": ["credentialRef"] },
          "unevaluatedProperties": false
        },
        "tenantTag": {
          "description": "外部客户端被视为独立 tenant 时的标签前缀，用于 QuotaGuard 与 AuditSink 隔离。",
          "type": "string",
          "default": "mcp-external"
        }
      },
      "$comment": "enabled=true 时必须声明 transport。",
      "if": { "properties": { "enabled": { "const": true } }, "required": ["enabled"] },
      "then": { "required": ["transport"] },
      "unevaluatedProperties": false
    }
  },
  "patternProperties": {
    "^x-": true
  },
  "unevaluatedProperties": false
}
