{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://minderhq.github.io/docs/schemas/declarative-manifest.v1alpha1.json",
  "title": "Minder Declarative Connector Manifest",
  "description": "A declarative (T0) connector: HTTP tools, actions, a schedule and an inbound webhook expressed as data, run by Minder's connector engine with no plugin code. This schema checks the structure. At load the engine also checks what JSON Schema cannot express: every base host is in the declared egress, placeholders and JMESPath expressions compile, auth fields fit the auth type, step names are unique, a minder_api step appears only in a tool that declares minder_scopes and its route has no empty, '.' or '..' segment, no minder_scopes entry is listed twice, measurements are declared, a webhook action exists and takes a 'body' parameter, and at most 32 tools and actions in total.",
  "type": "object",
  "required": [
    "apiVersion",
    "kind",
    "metadata",
    "spec"
  ],
  "properties": {
    "apiVersion": {
      "const": "minder.dev/v1alpha1"
    },
    "kind": {
      "const": "Plugin"
    },
    "metadata": {
      "type": "object",
      "required": [
        "name",
        "version"
      ],
      "properties": {
        "name": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_-]{0,63}$"
        },
        "version": {
          "type": "string",
          "minLength": 1,
          "maxLength": 64
        },
        "description": {
          "type": "string",
          "maxLength": 2000
        },
        "author": {
          "type": "string",
          "maxLength": 200
        },
        "stable_id": {
          "anyOf": [
            {
              "type": "string",
              "maxLength": 128
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "additionalProperties": false
    },
    "spec": {
      "type": "object",
      "required": [
        "runtime",
        "egress",
        "bases"
      ],
      "properties": {
        "runtime": {
          "type": "object",
          "required": [
            "kind"
          ],
          "properties": {
            "kind": {
              "const": "declarative"
            },
            "engine": {
              "const": 1,
              "default": 1
            }
          },
          "additionalProperties": false
        },
        "display": {
          "anyOf": [
            {
              "type": "object"
            },
            {
              "type": "null"
            }
          ]
        },
        "config_schema": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "key"
            ],
            "properties": {
              "key": {
                "type": "string",
                "pattern": "^[A-Za-z_][A-Za-z0-9_]{0,63}$"
              }
            }
          },
          "description": "Config fields, the same shape as a Python plugin's config_schema."
        },
        "egress": {
          "type": "array",
          "minItems": 1,
          "maxItems": 32,
          "items": {
            "$ref": "#/definitions/egressRule"
          }
        },
        "bases": {
          "type": "object",
          "minProperties": 1,
          "maxProperties": 16,
          "propertyNames": {
            "pattern": "^[a-z][a-z0-9_]{0,63}$"
          },
          "additionalProperties": {
            "$ref": "#/definitions/base"
          }
        },
        "limits": {
          "$ref": "#/definitions/limits"
        },
        "timeseries": {
          "anyOf": [
            {
              "type": "object",
              "required": [
                "measurements"
              ],
              "properties": {
                "measurements": {
                  "type": "array",
                  "minItems": 1,
                  "maxItems": 16,
                  "items": {
                    "type": "string",
                    "pattern": "^[a-z][a-z0-9_]{0,63}$"
                  }
                }
              },
              "additionalProperties": false
            },
            {
              "type": "null"
            }
          ]
        },
        "tools": {
          "type": "object",
          "propertyNames": {
            "pattern": "^[a-z][a-z0-9_]{0,63}$",
            "not": {
              "enum": [
                "analyze",
                "apply_config",
                "bind_context",
                "bind_timeseries",
                "collect_data",
                "connect",
                "engine",
                "handle_webhook",
                "health_check",
                "initialize",
                "manifest",
                "panels",
                "register",
                "schedule",
                "shutdown"
              ]
            }
          },
          "additionalProperties": {
            "allOf": [
              {
                "$ref": "#/definitions/operation"
              },
              {
                "properties": {
                  "timeseries": {
                    "type": "null"
                  }
                }
              }
            ]
          },
          "description": "AI tools. A tool declares no time-series write."
        },
        "actions": {
          "type": "object",
          "propertyNames": {
            "pattern": "^[a-z][a-z0-9_]{0,63}$",
            "not": {
              "enum": [
                "analyze",
                "apply_config",
                "bind_context",
                "bind_timeseries",
                "collect_data",
                "connect",
                "engine",
                "handle_webhook",
                "health_check",
                "initialize",
                "manifest",
                "panels",
                "register",
                "schedule",
                "shutdown"
              ]
            }
          },
          "additionalProperties": {
            "allOf": [
              {
                "$ref": "#/definitions/operation"
              },
              {
                "properties": {
                  "effect": {
                    "type": "null"
                  },
                  "minder_scopes": {
                    "maxItems": 0
                  },
                  "steps": {
                    "type": "array",
                    "items": {
                      "properties": {
                        "minder_api": {
                          "type": "null"
                        }
                      }
                    }
                  }
                }
              }
            ]
          },
          "description": "Actions (not exposed as AI tools). An action declares no effect, no minder_scopes and no minder_api step."
        },
        "schedule": {
          "anyOf": [
            {
              "$ref": "#/definitions/schedule"
            },
            {
              "type": "null"
            }
          ]
        },
        "webhook": {
          "anyOf": [
            {
              "$ref": "#/definitions/webhook"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "additionalProperties": false,
      "anyOf": [
        {
          "required": [
            "tools"
          ],
          "properties": {
            "tools": {
              "minProperties": 1
            }
          }
        },
        {
          "required": [
            "actions"
          ],
          "properties": {
            "actions": {
              "minProperties": 1
            }
          }
        },
        {
          "required": [
            "schedule"
          ],
          "properties": {
            "schedule": {
              "type": "object"
            }
          }
        }
      ]
    }
  },
  "additionalProperties": false,
  "definitions": {
    "egressRule": {
      "type": "object",
      "required": [
        "host"
      ],
      "properties": {
        "host": {
          "type": "string",
          "minLength": 1,
          "maxLength": 253,
          "description": "An exact DNS host, or '*.domain' for any subdomain of it (not the apex). No IP addresses."
        },
        "http": {
          "type": "boolean",
          "default": false,
          "description": "Allow plain http to this host."
        }
      },
      "additionalProperties": false
    },
    "auth": {
      "type": "object",
      "properties": {
        "type": {
          "enum": [
            "none",
            "api_key",
            "bearer",
            "basic"
          ],
          "default": "none"
        },
        "secret": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "in": {
          "enum": [
            "header",
            "query"
          ],
          "default": "header"
        },
        "name": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "username_secret": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "password_secret": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "additionalProperties": false,
      "description": "Engine-injected credentials. Secret names refer to secret config keys; the value never appears in the manifest."
    },
    "base": {
      "type": "object",
      "required": [
        "url"
      ],
      "properties": {
        "url": {
          "type": "string",
          "minLength": 1,
          "maxLength": 2048,
          "description": "https://host[:port][/path]. A leading host label may come from config: https://{config.LANG|en}.example.org"
        },
        "auth": {
          "$ref": "#/definitions/auth"
        }
      },
      "additionalProperties": false
    },
    "pagination": {
      "type": "object",
      "required": [
        "type"
      ],
      "properties": {
        "type": {
          "enum": [
            "cursor",
            "offset",
            "page",
            "link"
          ]
        },
        "max_pages": {
          "type": "integer",
          "minimum": 1,
          "maximum": 10,
          "default": 5
        },
        "items": {
          "anyOf": [
            {
              "type": "string",
              "description": "A JMESPath expression."
            },
            {
              "type": "null"
            }
          ]
        },
        "param": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "next": {
          "anyOf": [
            {
              "type": "string",
              "description": "A JMESPath expression."
            },
            {
              "type": "null"
            }
          ]
        },
        "size_param": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "size": {
          "anyOf": [
            {
              "type": "integer",
              "minimum": 1,
              "maximum": 1000
            },
            {
              "type": "null"
            }
          ]
        },
        "start": {
          "anyOf": [
            {
              "type": "integer",
              "minimum": 0
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "additionalProperties": false
    },
    "body": {
      "type": "object",
      "properties": {
        "json": {
          "description": "A JSON body; string leaves are templates."
        },
        "form": {
          "anyOf": [
            {
              "type": "object",
              "additionalProperties": {
                "type": [
                  "string",
                  "number",
                  "boolean"
                ]
              }
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "additionalProperties": false,
      "description": "Exactly one of json or form."
    },
    "xml": {
      "type": "object",
      "properties": {
        "namespaces": {
          "enum": [
            "drop",
            "keep"
          ],
          "default": "drop"
        },
        "prefixes": {
          "type": "object",
          "maxProperties": 16,
          "additionalProperties": {
            "type": "string"
          }
        }
      },
      "additionalProperties": false
    },
    "request": {
      "type": "object",
      "required": [
        "base"
      ],
      "properties": {
        "method": {
          "enum": [
            "GET",
            "POST",
            "PUT",
            "PATCH",
            "DELETE",
            "HEAD"
          ],
          "default": "GET"
        },
        "base": {
          "type": "string",
          "description": "A name declared in spec.bases."
        },
        "path": {
          "type": "string",
          "maxLength": 2048,
          "default": ""
        },
        "query": {
          "type": "object",
          "additionalProperties": {
            "type": [
              "string",
              "number",
              "boolean"
            ]
          }
        },
        "headers": {
          "type": "object",
          "additionalProperties": {
            "type": "string"
          }
        },
        "body": {
          "anyOf": [
            {
              "$ref": "#/definitions/body"
            },
            {
              "type": "null"
            }
          ]
        },
        "response": {
          "enum": [
            "json",
            "xml",
            "text"
          ],
          "default": "json"
        },
        "xml": {
          "anyOf": [
            {
              "$ref": "#/definitions/xml"
            },
            {
              "type": "null"
            }
          ]
        },
        "empty_body": {
          "enum": [
            "null",
            "error"
          ],
          "default": "null"
        },
        "follow_redirects": {
          "anyOf": [
            {
              "type": "boolean"
            },
            {
              "type": "null"
            }
          ]
        },
        "paginate": {
          "anyOf": [
            {
              "$ref": "#/definitions/pagination"
            },
            {
              "type": "null"
            }
          ]
        },
        "accept_status": {
          "type": "array",
          "items": {
            "type": "integer"
          }
        }
      },
      "additionalProperties": false
    },
    "minderApi": {
      "type": "object",
      "description": "A call to Minder's own API through the platform's minder.api capability, as the invoking user and for the tool's approved minder_scopes. Not external egress.",
      "required": [
        "route"
      ],
      "properties": {
        "route": {
          "type": "string",
          "minLength": 4,
          "maxLength": 2048,
          "pattern": "^/v1/[^?#]*$",
          "description": "A plugin-callable Minder route, starting with '/v1/'; placeholders are path-encoded."
        },
        "method": {
          "enum": [
            "GET",
            "POST"
          ],
          "default": "GET"
        },
        "query": {
          "type": "object",
          "additionalProperties": {
            "type": [
              "string",
              "number",
              "boolean"
            ]
          }
        },
        "body": {
          "description": "The JSON request body (POST only); string values are placeholders."
        }
      },
      "additionalProperties": false,
      "if": {
        "properties": {
          "method": {
            "const": "GET"
          }
        }
      },
      "then": {
        "properties": {
          "body": {
            "type": "null"
          }
        }
      }
    },
    "step": {
      "type": "object",
      "required": [
        "name"
      ],
      "properties": {
        "name": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]{0,63}$"
        },
        "request": {
          "anyOf": [
            {
              "$ref": "#/definitions/request"
            },
            {
              "type": "null"
            }
          ]
        },
        "minder_api": {
          "anyOf": [
            {
              "$ref": "#/definitions/minderApi"
            },
            {
              "type": "null"
            }
          ]
        },
        "when": {
          "anyOf": [
            {
              "type": "string",
              "description": "A JMESPath expression."
            },
            {
              "type": "null"
            }
          ]
        },
        "foreach": {
          "anyOf": [
            {
              "type": "string",
              "description": "A JMESPath expression."
            },
            {
              "type": "null"
            }
          ]
        },
        "max_items": {
          "type": "integer",
          "minimum": 1,
          "maximum": 20,
          "default": 10
        },
        "select": {
          "anyOf": [
            {
              "type": "string",
              "description": "A JMESPath expression."
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "additionalProperties": false,
      "oneOf": [
        {
          "required": [
            "request"
          ],
          "properties": {
            "request": {
              "type": "object"
            }
          }
        },
        {
          "required": [
            "minder_api"
          ],
          "properties": {
            "minder_api": {
              "type": "object"
            }
          }
        }
      ],
      "description": "One step: an HTTP 'request' through the plugin's egress, or a 'minder_api' call to Minder's own API (not egress). Exactly one of the two."
    },
    "timeseriesWrite": {
      "type": "object",
      "required": [
        "measurement",
        "points"
      ],
      "properties": {
        "measurement": {
          "type": "string",
          "description": "One of spec.timeseries.measurements."
        },
        "points": {
          "type": "string",
          "description": "A JMESPath expression."
        },
        "tags": {
          "type": "object",
          "maxProperties": 16,
          "propertyNames": {
            "pattern": "^[A-Za-z_][A-Za-z0-9_.\\-]{0,63}$",
            "not": {
              "enum": [
                "owner_id",
                "plugin"
              ]
            }
          },
          "additionalProperties": {
            "type": "string",
            "description": "A JMESPath expression."
          },
          "description": "Tags merged into every point (JMESPath over the root). owner_id and plugin are set by the platform."
        }
      },
      "additionalProperties": false
    },
    "operation": {
      "type": "object",
      "required": [
        "description",
        "steps"
      ],
      "properties": {
        "description": {
          "type": "string",
          "minLength": 1,
          "maxLength": 2000
        },
        "parameters": {
          "type": "object",
          "required": [
            "type"
          ],
          "properties": {
            "type": {
              "const": "object"
            }
          },
          "description": "A JSON Schema (type: object) for the parameters."
        },
        "vars": {
          "type": "object",
          "maxProperties": 16,
          "propertyNames": {
            "pattern": "^[a-z][a-z0-9_]{0,63}$"
          },
          "additionalProperties": {
            "type": "string",
            "description": "A JMESPath expression."
          },
          "description": "Named JMESPath expressions, evaluated before the steps."
        },
        "steps": {
          "type": "array",
          "minItems": 1,
          "maxItems": 3,
          "items": {
            "$ref": "#/definitions/step"
          }
        },
        "output": {
          "anyOf": [
            {
              "type": "string",
              "description": "A JMESPath expression."
            },
            {
              "type": "null"
            }
          ]
        },
        "on_error": {
          "description": "The fixed result when a step fails."
        },
        "error_output": {
          "anyOf": [
            {
              "type": "string",
              "description": "A JMESPath expression."
            },
            {
              "type": "null"
            }
          ]
        },
        "read_only": {
          "anyOf": [
            {
              "type": "boolean"
            },
            {
              "type": "null"
            }
          ]
        },
        "admin_only": {
          "type": "boolean",
          "default": false
        },
        "timeseries": {
          "anyOf": [
            {
              "$ref": "#/definitions/timeseriesWrite"
            },
            {
              "type": "null"
            }
          ]
        },
        "effect": {
          "anyOf": [
            {
              "enum": [
                "read",
                "write",
                "send",
                "destructive"
              ]
            },
            {
              "type": "null"
            }
          ]
        },
        "minder_scopes": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "enum": [
              "conversation.read_current",
              "kb.documents.ingest",
              "kb.read_passage",
              "kb.search",
              "ticket.create_internal",
              "user.profile.basic"
            ]
          },
          "description": "Tools only: the Minder API scopes its minder_api steps use."
        }
      },
      "additionalProperties": false
    },
    "schedule": {
      "type": "object",
      "required": [
        "steps",
        "measurement",
        "points"
      ],
      "properties": {
        "cron": {
          "anyOf": [
            {
              "type": "string",
              "pattern": "^\\s*[0-9*/,\\-]+( [0-9*/,\\-]+){4}\\s*$",
              "description": "Five-field cron expression, e.g. '0 * * * *'."
            },
            {
              "type": "null"
            }
          ]
        },
        "vars": {
          "type": "object",
          "maxProperties": 16,
          "propertyNames": {
            "pattern": "^[a-z][a-z0-9_]{0,63}$"
          },
          "additionalProperties": {
            "type": "string",
            "description": "A JMESPath expression."
          },
          "description": "Named JMESPath expressions, evaluated before the steps."
        },
        "steps": {
          "type": "array",
          "minItems": 1,
          "maxItems": 3,
          "items": {
            "allOf": [
              {
                "$ref": "#/definitions/step"
              },
              {
                "properties": {
                  "minder_api": {
                    "type": "null"
                  }
                }
              }
            ]
          },
          "description": "The schedule's steps; no minder_api step (that is for AI tools only)."
        },
        "measurement": {
          "type": "string",
          "description": "One of spec.timeseries.measurements."
        },
        "points": {
          "type": "string",
          "description": "A JMESPath expression."
        },
        "tags": {
          "type": "object",
          "maxProperties": 16,
          "propertyNames": {
            "pattern": "^[A-Za-z_][A-Za-z0-9_.\\-]{0,63}$",
            "not": {
              "enum": [
                "owner_id",
                "plugin"
              ]
            }
          },
          "additionalProperties": {
            "type": "string",
            "description": "A JMESPath expression."
          },
          "description": "Tags merged into every point (JMESPath over the root). owner_id and plugin are set by the platform."
        },
        "output": {
          "anyOf": [
            {
              "type": "string",
              "description": "A JMESPath expression."
            },
            {
              "type": "null"
            }
          ]
        },
        "error_output": {
          "anyOf": [
            {
              "type": "string",
              "description": "A JMESPath expression."
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "additionalProperties": false
    },
    "webhook": {
      "type": "object",
      "required": [
        "action",
        "secret"
      ],
      "properties": {
        "action": {
          "type": "string",
          "description": "A declared, non-admin-only action with a 'body' parameter."
        },
        "secret": {
          "type": "string",
          "pattern": "^[A-Za-z_][A-Za-z0-9_]{0,63}$",
          "description": "The per-tenant secret that signs each delivery (HMAC). Required."
        }
      },
      "additionalProperties": false
    },
    "limits": {
      "type": "object",
      "properties": {
        "timeout_s": {
          "type": "number",
          "exclusiveMinimum": 0,
          "maximum": 30,
          "default": 10
        },
        "max_response_bytes": {
          "type": "integer",
          "minimum": 1024,
          "maximum": 5242880,
          "default": 2097152
        },
        "max_concurrency": {
          "type": "integer",
          "minimum": 1,
          "maximum": 8,
          "default": 4
        },
        "rate_per_minute": {
          "type": "integer",
          "minimum": 1,
          "maximum": 600,
          "default": 120
        }
      },
      "additionalProperties": false,
      "description": "A manifest may only lower the engine's caps."
    }
  }
}
