{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://cdphub.com/cdp-agent-0.1.schema.json",
  "title": "CDP Agent Manifest 0.1",
  "description": "The file a customer data platform hosts at /.well-known/cdp-agent.json so AI agents can call it: the API call for each of five everyday jobs, how to authenticate, and the required fields. Spec: https://cdphub.com/cdp-agent-manifest. This schema is CC0 1.0.",
  "type": "object",
  "required": ["cdp_agent", "name", "updated", "docs", "jobs"],
  "properties": {
    "$schema": { "type": "string" },
    "cdp_agent": { "const": "0.1", "description": "The version of this spec the file follows." },
    "name": { "type": "string", "minLength": 1, "maxLength": 120, "description": "The CDP's name as its customers know it." },
    "provider": {
      "type": "object",
      "description": "The company behind the CDP, when its name differs.",
      "properties": {
        "name": { "type": "string", "minLength": 1, "maxLength": 120 },
        "url": { "$ref": "#/$defs/https" }
      },
      "additionalProperties": false
    },
    "updated": { "$ref": "#/$defs/date", "description": "The day the file was last checked against the docs (YYYY-MM-DD)." },
    "docs": { "$ref": "#/$defs/https", "description": "The developer docs' home page." },
    "contact": {
      "type": "string",
      "pattern": "^(https://|mailto:)\\S+$",
      "description": "Where to report a wrong entry: a page or a mailto: address."
    },
    "links": {
      "type": "object",
      "description": "Other machine-readable descriptions of the CDP's APIs.",
      "properties": {
        "openapi": { "$ref": "#/$defs/https", "description": "An OpenAPI description." },
        "mcp": { "$ref": "#/$defs/https", "description": "An MCP server, or its server card." },
        "llms_txt": { "$ref": "#/$defs/https", "description": "The docs' llms.txt." },
        "status": { "$ref": "#/$defs/https", "description": "The API status page." }
      },
      "additionalProperties": { "$ref": "#/$defs/https" }
    },
    "variables": {
      "type": "object",
      "description": "The account values the templates use, by name: {NAME} in a url, header, query value or credential.",
      "propertyNames": { "pattern": "^[A-Z][A-Z0-9_]*$" },
      "additionalProperties": { "$ref": "#/$defs/variable" }
    },
    "auth": {
      "type": "object",
      "description": "The ways to authenticate, by id; each job names the ones it takes.",
      "propertyNames": { "pattern": "^[a-z][a-z0-9_]*$" },
      "additionalProperties": { "$ref": "#/$defs/scheme" }
    },
    "jobs": {
      "type": "object",
      "minProperties": 1,
      "description": "The five jobs, each the documented call or why there is none. A job left out is one the file says nothing about.",
      "propertyNames": { "pattern": "^(send_event|upsert_profile|send_batch|read_profile|delete_user|x-[a-z0-9_-]+)$" },
      "properties": {
        "send_event": { "$ref": "#/$defs/job", "description": "Send one event for a known person." },
        "upsert_profile": { "$ref": "#/$defs/job", "description": "Create or update a person's profile." },
        "send_batch": { "$ref": "#/$defs/job", "description": "Send several events (or profiles) in one request." },
        "read_profile": { "$ref": "#/$defs/job", "description": "Read a person's profile by an identifier." },
        "delete_user": { "$ref": "#/$defs/job", "description": "Delete a person (a privacy erasure)." }
      },
      "additionalProperties": { "$ref": "#/$defs/job" }
    }
  },
  "patternProperties": { "^x-": {} },
  "additionalProperties": false,
  "$defs": {
    "https": { "type": "string", "pattern": "^https://\\S+$" },
    "date": { "type": "string", "pattern": "^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\\d|3[01])$" },
    "template": { "type": "string", "maxLength": 2000, "description": "Text in which {NAME} stands for a variable and {name} for a request parameter." },
    "templates": { "type": "object", "additionalProperties": { "$ref": "#/$defs/template" } },
    "variable": {
      "type": "object",
      "required": ["description"],
      "properties": {
        "description": { "type": "string", "minLength": 1, "maxLength": 500, "description": "What the value is and where an account finds it." },
        "secret": { "type": "boolean", "description": "True for a credential, which an agent must not log or show." },
        "example": { "type": "string", "maxLength": 300 }
      },
      "additionalProperties": false
    },
    "scheme": {
      "type": "object",
      "required": ["type"],
      "properties": {
        "type": { "enum": ["basic", "bearer", "header", "query", "body", "none"] },
        "description": { "type": "string", "maxLength": 1000 },
        "docs": { "$ref": "#/$defs/https" },
        "username": { "$ref": "#/$defs/template" },
        "password": { "$ref": "#/$defs/template" },
        "token": { "$ref": "#/$defs/template" },
        "token_url": { "type": "string", "pattern": "^(https://|\\{[A-Z][A-Z0-9_]*\\})\\S*$" },
        "grant": { "enum": ["client_credentials", "authorization_code", "password", "refresh_token", "jwt_bearer", "other"] },
        "scopes": { "type": "array", "items": { "type": "string", "minLength": 1 } },
        "name": { "type": "string", "minLength": 1, "maxLength": 200 },
        "value": { "$ref": "#/$defs/template" }
      },
      "additionalProperties": false,
      "allOf": [
        { "if": { "properties": { "type": { "const": "basic" } } }, "then": { "required": ["username", "password"] } },
        { "if": { "properties": { "type": { "const": "bearer" } } }, "then": { "required": ["token"] } },
        { "if": { "properties": { "type": { "enum": ["header", "query", "body"] } } }, "then": { "required": ["name", "value"] } }
      ]
    },
    "requiredItem": {
      "oneOf": [
        { "type": "string", "minLength": 1, "maxLength": 300 },
        {
          "type": "object",
          "required": ["one_of"],
          "properties": { "one_of": { "type": "array", "minItems": 2, "items": { "type": "string", "minLength": 1, "maxLength": 300 } } },
          "additionalProperties": false
        }
      ]
    },
    "requiredList": { "type": "array", "items": { "$ref": "#/$defs/requiredItem" } },
    "job": {
      "type": "object",
      "required": ["status"],
      "properties": { "status": { "enum": ["api", "workflow", "app", "none"] } },
      "if": { "properties": { "status": { "const": "api" } } },
      "then": { "$ref": "#/$defs/apiJob" },
      "else": { "$ref": "#/$defs/otherJob" }
    },
    "apiJob": {
      "type": "object",
      "required": ["status", "method", "url", "auth", "docs"],
      "properties": {
        "status": { "const": "api" },
        "method": { "enum": ["GET", "POST", "PUT", "PATCH", "DELETE"] },
        "url": { "type": "string", "pattern": "^(https://|\\{[A-Z][A-Z0-9_]*\\})\\S+$", "maxLength": 2000 },
        "hosts": { "type": "array", "items": { "type": "string", "pattern": "^[A-Za-z0-9.{}_-]+$" }, "description": "Other hosts that take the same call, such as other regions'." },
        "auth": {
          "type": "array",
          "description": "The ways to authenticate this call: each option lists the auth ids sent together. An empty list means no credential.",
          "items": { "type": "array", "minItems": 1, "items": { "type": "string", "pattern": "^[a-z][a-z0-9_]*$" } }
        },
        "headers": { "$ref": "#/$defs/templates", "description": "Headers to send besides the credential." },
        "query": { "$ref": "#/$defs/templates", "description": "Query parameters to send besides the credential." },
        "params": {
          "type": "object",
          "description": "The request's own values in the url or query, by name: {name}.",
          "propertyNames": { "pattern": "^[a-z][a-z0-9_]*$" },
          "additionalProperties": { "type": "string", "minLength": 1, "maxLength": 500 }
        },
        "content_type": { "type": "string", "minLength": 3, "maxLength": 200 },
        "required": {
          "type": "object",
          "description": "What the call can't do without: body paths (a[].b is b in each item of the list a), query parameters and headers.",
          "properties": {
            "body": { "$ref": "#/$defs/requiredList" },
            "query": { "$ref": "#/$defs/requiredList" },
            "headers": { "$ref": "#/$defs/requiredList" }
          },
          "additionalProperties": false
        },
        "fields": {
          "type": "object",
          "description": "Where each part of the shared example goes (the CDP API Cookbook's names: user_id, email, event, time, order_id, total, currency, first_name, last_name, plan, events, product_id, lookup, identifier).",
          "additionalProperties": { "type": "string", "maxLength": 500 }
        },
        "example": {
          "type": "object",
          "description": "A whole request with the shared example: credentials as {VARIABLES}.",
          "properties": {
            "headers": { "type": "object", "additionalProperties": { "type": "string" } },
            "query": { "type": "object", "additionalProperties": { "type": "string" } },
            "body": {}
          },
          "additionalProperties": false
        },
        "notes": { "type": "array", "items": { "type": "string", "minLength": 1, "maxLength": 1000 } },
        "docs": { "$ref": "#/$defs/https" }
      },
      "patternProperties": { "^x-": {} },
      "additionalProperties": false
    },
    "otherJob": {
      "type": "object",
      "required": ["status", "note"],
      "properties": {
        "status": { "enum": ["workflow", "app", "none"] },
        "note": { "type": "string", "minLength": 1, "maxLength": 1000, "description": "How the job is done instead (several calls, or in the vendor's app), or why it isn't offered." },
        "docs": { "$ref": "#/$defs/https" }
      },
      "patternProperties": { "^x-": {} },
      "additionalProperties": false
    }
  }
}
