{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://orgrelay.com/schemas/connector-manifest-1.json",
  "title": "OrgRelay Connector Manifest",
  "description": "业务系统接入 OrgRelay 时，通过 MCP 资源 orgrelay://connector/manifest 返回的说明文件（规范见 docs/connector-spec.md）。",
  "type": "object",
  "required": [
    "spec",
    "name"
  ],
  "properties": {
    "spec": {
      "const": "orgrelay-connector/1",
      "description": "规范版本，固定写 orgrelay-connector/1"
    },
    "name": {
      "$ref": "#/$defs/localized",
      "description": "系统名称，显示在 OrgRelay 后台和 AI 回答里"
    },
    "description": {
      "$ref": "#/$defs/localized",
      "description": "一句话说明这个系统管什么"
    },
    "version": {
      "type": "string",
      "minLength": 1,
      "maxLength": 40,
      "description": "连接器版本，例如 1.0.0"
    },
    "vendor": {
      "type": "string",
      "maxLength": 80,
      "description": "提供方名称（选填）"
    },
    "homepage": {
      "type": "string",
      "format": "uri",
      "description": "说明页地址（选填）"
    },
    "logo": {
      "type": "string",
      "description": "logo：data:image/(png|jpeg|webp|svg+xml);base64,… 或 http(s) 地址（可以是相对 MCP 地址的路径）。不超过 200 KB，建议正方形 128×128 以上。OrgRelay 绑定时下载一次存起来，不会每次去拉。"
    },
    "auth": {
      "type": "object",
      "required": [
        "type"
      ],
      "properties": {
        "type": {
          "type": "string",
          "description": "system 只能是 bearer / oauth2_client_credentials；channel / social 写平台自己的方式（如 bot_token、access_token）"
        },
        "token_url": {
          "type": "string",
          "description": "oauth2_client_credentials 时的令牌地址，可以是相对路径"
        },
        "scopes": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "additionalProperties": false
    },
    "tools": {
      "type": "array",
      "minItems": 1,
      "maxItems": 100,
      "items": {
        "type": "object",
        "required": [
          "name",
          "access"
        ],
        "properties": {
          "name": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9]{1,23}\\.[a-z][a-z0-9_]{1,39}$",
            "description": "领域.动作，例如 orders.search、inventory.adjust、seo.keyword_rankings。必须和 tools/list 里的名字完全一样"
          },
          "title": {
            "$ref": "#/$defs/localized",
            "description": "工具的中文名，例如“查询订单”"
          },
          "description": {
            "$ref": "#/$defs/localized",
            "description": "工具做什么、返回什么，AI 靠它决定什么时候用"
          },
          "access": {
            "enum": [
              "read",
              "write"
            ],
            "description": "read = 只读；write = 会改数据（OrgRelay 一律先生成待审批单，老板批准后才调用）"
          },
          "inputSchema": {
            "type": "object",
            "description": "社交媒体内置适配器在 manifest 里直接给参数格式；业务系统的参数格式以 tools/list 为准"
          }
        },
        "additionalProperties": false
      }
    },
    "type": {
      "enum": [
        "system",
        "channel",
        "social"
      ],
      "default": "system",
      "description": "system = 业务系统（MCP 服务，默认）；channel = 通讯渠道；social = 社交媒体。channel / social 由 OrgRelay 内置适配器实现（adapters/ 目录）"
    },
    "id": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9_]{1,31}$",
      "description": "channel / social 适配器的编号"
    },
    "status": {
      "enum": [
        "available",
        "planned",
        "unsupported"
      ],
      "description": "available 已接通；planned 待接入（只有说明，不能绑定）；unsupported 不支持（必须写 reason）"
    },
    "reason": {
      "$ref": "#/$defs/localized",
      "description": "status = unsupported 时说明原因"
    },
    "webhooks": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "name"
        ],
        "properties": {
          "name": {
            "type": "string"
          },
          "methods": {
            "type": "array",
            "items": {
              "enum": [
                "GET",
                "POST"
              ]
            }
          },
          "verify": {
            "type": "string"
          },
          "auto": {
            "type": "boolean"
          },
          "subscribe": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      },
      "description": "需要平台回调的地址；OrgRelay 为每个连接生成随机地址 /hooks/<随机>/<name>"
    },
    "scopes": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "fields": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "key",
          "label"
        ],
        "properties": {
          "key": {
            "type": "string"
          },
          "label": {
            "$ref": "#/$defs/localized"
          },
          "secret": {
            "type": "boolean"
          },
          "required": {
            "type": "boolean"
          },
          "advanced": {
            "type": "boolean"
          },
          "placeholder": {
            "type": "string"
          }
        }
      }
    },
    "capabilities": {
      "type": "object",
      "properties": {
        "groups": {
          "type": "boolean"
        },
        "buttons": {
          "type": "boolean"
        },
        "max_len": {
          "type": "integer"
        }
      }
    },
    "guide": {
      "type": "object",
      "propertyNames": {
        "enum": [
          "zh-CN",
          "zh-TW",
          "en",
          "id"
        ]
      },
      "additionalProperties": {
        "type": "array",
        "items": {
          "type": "string"
        }
      }
    },
    "docs_url": {
      "type": "string"
    }
  },
  "additionalProperties": false,
  "$defs": {
    "localized": {
      "oneOf": [
        {
          "type": "string",
          "minLength": 1,
          "maxLength": 600
        },
        {
          "type": "object",
          "minProperties": 1,
          "propertyNames": {
            "enum": [
              "zh-CN",
              "zh-TW",
              "en",
              "id"
            ]
          },
          "additionalProperties": {
            "type": "string",
            "minLength": 1,
            "maxLength": 600
          }
        }
      ]
    }
  },
  "allOf": [
    {
      "if": {
        "anyOf": [
          {
            "not": {
              "required": [
                "type"
              ]
            }
          },
          {
            "properties": {
              "type": {
                "const": "system"
              }
            },
            "required": [
              "type"
            ]
          }
        ]
      },
      "then": {
        "required": [
          "version",
          "auth",
          "tools"
        ]
      }
    },
    {
      "if": {
        "properties": {
          "status": {
            "const": "unsupported"
          }
        },
        "required": [
          "status"
        ]
      },
      "then": {
        "required": [
          "reason"
        ]
      }
    }
  ]
}