{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://istointents.org/schemas/0.2/holder-descriptor.schema.json",
  "title": "Isto Intents holder descriptor",
  "description": "What an intent holder publishes about itself at /.well-known/isto-intents.json (registry chapter §2, v0.2 draft).",
  "type": "object",
  "required": [
    "specVersion",
    "type",
    "id",
    "created",
    "operator",
    "servers"
  ],
  "properties": {
    "specVersion": {
      "const": "0.2"
    },
    "type": {
      "const": "holder-descriptor"
    },
    "id": {
      "type": "string",
      "format": "uri",
      "pattern": "^https://[^/]+/\\.well-known/isto-intents\\.json$",
      "description": "the descriptor's own URL"
    },
    "created": {
      "$ref": "https://istointents.org/schemas/0.1/common.schema.json#/$defs/timestamp"
    },
    "updated": {
      "$ref": "https://istointents.org/schemas/0.1/common.schema.json#/$defs/timestamp"
    },
    "operator": {
      "$ref": "#/$defs/operator"
    },
    "servers": {
      "type": "array",
      "minItems": 1,
      "maxItems": 10,
      "items": {
        "$ref": "#/$defs/server"
      }
    },
    "registry": {
      "type": "object",
      "required": [
        "listing"
      ],
      "properties": {
        "listing": {
          "enum": [
            "requested",
            "withdrawn"
          ],
          "description": "requested asks the registry to list the host; withdrawn asks it to remove the entry"
        },
        "terms": {
          "type": "string",
          "format": "uri",
          "pattern": "^https://",
          "description": "URL of the registry terms the operator accepts"
        }
      },
      "if": {
        "properties": {
          "listing": {
            "const": "requested"
          }
        }
      },
      "then": {
        "required": [
          "terms"
        ]
      },
      "additionalProperties": false
    },
    "jwksUri": {
      "type": "string",
      "format": "uri",
      "pattern": "^https://",
      "description": "where the holder publishes its signing keys (spec §11)"
    },
    "extensions": {
      "type": "object",
      "propertyNames": {
        "pattern": "^(x-|https?://)"
      }
    }
  },
  "$defs": {
    "operator": {
      "type": "object",
      "description": "the organisation responsible for the servers",
      "required": [
        "name",
        "url",
        "contact",
        "country"
      ],
      "properties": {
        "name": {
          "type": "string",
          "minLength": 2,
          "maxLength": 120
        },
        "url": {
          "type": "string",
          "format": "uri",
          "pattern": "^https://"
        },
        "contact": {
          "type": "string",
          "format": "uri",
          "pattern": "^(mailto:|https://)",
          "description": "a role address, not a person's"
        },
        "country": {
          "$ref": "https://istointents.org/schemas/0.1/common.schema.json#/$defs/country"
        }
      },
      "additionalProperties": false
    },
    "server": {
      "description": "one intent server of the holder",
      "$ref": "#/$defs/serverFields",
      "unevaluatedProperties": false
    },
    "serverFields": {
      "type": "object",
      "description": "the fields of one intent server",
      "required": [
        "url",
        "binding",
        "transport",
        "profiles",
        "specVersions",
        "categories",
        "countries",
        "languages"
      ],
      "properties": {
        "url": {
          "type": "string",
          "format": "uri",
          "pattern": "^https://"
        },
        "binding": {
          "const": "mcp"
        },
        "transport": {
          "const": "streamable-http"
        },
        "profiles": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "anyOf": [
              {
                "const": "consent-link"
              },
              {
                "type": "string",
                "pattern": "^x-"
              }
            ]
          }
        },
        "specVersions": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "pattern": "^\\d+\\.\\d+$"
          }
        },
        "categories": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "$ref": "https://istointents.org/schemas/0.1/common.schema.json#/$defs/category"
          }
        },
        "countries": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "$ref": "https://istointents.org/schemas/0.1/common.schema.json#/$defs/country"
          }
        },
        "languages": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "$ref": "https://istointents.org/schemas/0.1/common.schema.json#/$defs/language"
          }
        },
        "title": {
          "type": "string",
          "maxLength": 120
        },
        "mcpRegistryName": {
          "type": "string",
          "pattern": "^[a-zA-Z0-9.-]+/[a-zA-Z0-9._-]+$",
          "description": "the server's name in the MCP Registry"
        },
        "deprecated": {
          "type": "boolean"
        },
        "successor": {
          "type": "string",
          "format": "uri",
          "pattern": "^https://"
        }
      }
    }
  },
  "additionalProperties": false
}
