Skip to main content

Connector Contract

This page is for the developers who write a connector. It describes what Core expects from the connector: the manifest, the verbs, the credential it receives, the verify checks, and how a failure shows up for the admin. Build a Connector Image covers the steps: create, test locally, and build.

The scaffold (kz-ext create --type connector) and the SQLite example (kz-ext create --type connector --example sqlite) already follow this contract. Two files are yours:

FileWhat it holds
src/provider.pyThe manifest: identity, settings, credential, and the surfaces and verbs the connector offers
src/dispatcher.pyThe handlers: ping, the verbs, and verify

src/server.py passes both to the SDK's create_connector_app, which serves the HTTP endpoints Core calls and checks what your handlers return:

EndpointWhat it does
GET /healthzAnswers {"status": "ok"} when the server is up
GET /manifestReturns the manifest
POST /v1/verifyRuns your verify handler
POST /v1/executeRuns the handler for one verb

The manifest​

The manifest is declared in code, in Provider.spec(), and nowhere else. The server returns it at GET /manifest. Core reads it when the connector type is registered, to build the admin's settings form, route calls and deploy the pod. The scaffold's kamiwaza.json carries no manifest; kz-ext validate says where it comes from, and kz-ext dev local checks it.

The parts you change:

FieldWhat it is
connector_typeThe connector's identifier. The scaffold sets it from --name.
config_schema()The settings an admin enters, besides the credential. Each is a ConfigField.
auth_modelThe credential, as in Settings and credentials.
deploymentThe image and port. secret_delivery="direct" makes Core send the credential to the pod with each call.
surfacesWhat the connector offers. Each SurfaceDescriptor has a name, a display_label, and the verbs it supports in operations.

The verbs​

A surface's operations pair each verb with the op name Core sends in /v1/execute, for example ("query", "records.query"). Leave out a verb your source can't support; the scaffold's verify then drops its check too.

Verbparams the handler getsWhat it returns
list (browse)container_id (null for the top level), page_size, page_token{"items": [...], "next_page_token": ...}
searchquery, plus the browse fields. Set search_supported=True on the surface.The same shape as list
content (fetch)node_id (an item's id), and mime_type when the caller wants a format{"content_base64", "content_type", "filename", "item"}
querysurface, query, parameters, row_limit, timeout_msQueryResponse: columns, rows, row_count, truncated

Every item that list and search return needs an id. It can also carry label, kind, is_container, container_id, modified_at, and content: {filename, mime_type} when it can be fetched.

content returns the fetched item in item, in the same shape as a list item, read from the source at fetch time. item["id"] must equal node_id. Core's content policy judges the fetch on the item's fields, so a field a policy reads, such as a marking, must be a top-level key. Without item, a policy that needs an item field refuses the fetch.

query​

query runs a query in the source's own language. The surface declares the language with a QueryDescriptor; a surface with a query operation needs one, and the other way round:

QueryDescriptor(
language="sql",
row_limit=1000,
description="One table, incidents(id, severity, opened). opened is an ISO date.",
)
FieldWhat it is
languagesql, opensearch-dsl or other
dialectOptional, for example postgresql
descriptionWhat the agent reads to write a correct query: the tables, the columns and any rules. Kaizen puts it in the query tool's description.
row_limitThe most rows the connector returns for one query

The SDK's create_connector_app lowers each request's row_limit to the declared one, fills in timeout_ms when the request has none, and refuses a response that breaks the QueryResponse shape. Raise InvalidQuery for a query the source rejects (400 invalid_query) and QueryTimeout when it runs out of time (504 timeout); the message goes back to the agent so it can fix the query. Build the response with QueryResponse.from_rows.

Core never reads or rewrites the query, so read-only is the connector's job. Use a read-only account at the source, and a read-only session where the source has one. Bind parameters as the source's bind parameters; never paste them into the query text. The SQLite example shows all of this in src/dispatcher.py.

Settings and credentials​

Settings. Declare only non-secret fields in config_schema(). The pod receives them as JSON in the KAMIWAZA_CONNECTOR_SETTINGS environment variable; the scaffold reads them into its Settings class. A field marked secret=True never reaches your code: Core leaves it out of that variable, and the SDK passes the handlers only the fields of the credential below. Put a secret in one of the credential kinds instead.

Credentials. Declare the credential on the auth model, and the SDK adds its fields to the admin's form, all secret. A credential needs direct mode: the SDK refuses ServiceToken(credential=...) without secret_delivery="direct" on the deployment.

auth_model=ServiceToken(credential="client_certificate"),
deployment=DeploymentDescriptor(..., secret_delivery="direct"),
credentialFields the admin fills inWhat the handler gets
basicusername, passwordBasic: .username, .password
bearerservice_tokenBearer: .token
client_certificateclient_certificate, client_key, and optionally ca_bundle (the CA that signed the source's certificate), all PEMClientCertificate: .certificate, .private_key, .ca_bundle, and .ssl_context()

Don't declare these fields in config_schema() as well. In direct mode, Core sends the credential with each call, and the SDK passes it to every handler, verify included, as the typed object in credentials. A call that lacks a field fails with a config error naming the field. Connector code never reads a credential from the environment.

ClientCertificate.ssl_context() returns a TLS client context that presents the certificate. When ca_bundle is set, the context trusts only that CA, not the system's trusted CAs; without it, it trusts the system's. Pass it to your client library: httpx.AsyncClient(verify=credentials.ssl_context()), or the ssl argument of an asyncpg connection. On Linux the private key is loaded from memory and never written to a file.

The admin pastes each PEM into the connection's settings. For kz-ext dev local, a certificate field in .kz-ext/connection.json can be the PEM text or a path to a file in the project, as in the scaffold's connection.example.json.

A connector that needs no credential, such as the SQLite example, uses NoAuth(), and its handlers get no credentials argument.

Verify​

Core calls POST /v1/verify when an admin creates or tests a connection. Your verify handler returns a VerifyResponse with one VerifyCheck per thing it probed:

VerifyCheck fieldWhat it is
capabilityWhat the check is about, for example source or a surface name
okWhether it passed
labelThe check's name in the admin's view. Without one, Core uses the label of the surface named by capability, and hides a check that matches no surface.
detailWhy it failed, in words an operator can act on, for example cannot reach acme-db:5432
http_statusThe source's HTTP status on a failure, as in Errors
reasonThe source's own error code, read with http_status

VerifyResponse.from_checks(checks) sets the overall status from the checks: success when every check passed, failure when none did, partial otherwise. A response needs at least one check. A response that breaks this shape fails the call with a 500, so the mistake shows up in kz-ext dev local rather than as an empty list in Core.

The scaffold's verify is already written. It runs ping as a check labelled "Connect and sign in", then one tiny request per verb the surface declares ("Browse", "Search", "Fetch", "Query"). kz-ext dev local prints the checks, so you can watch them pass as you fill in the handlers.

Errors​

On a failed check, report the source's HTTP status in http_status, and the source's error code in reason when it has one. Core files each failed check as permanent or transient, and returns that as the check's failure_kind in the verify response:

http_statusfailure_kind
401permanent: the credential was rejected
403 with reason accessNotConfigured or SERVICE_DISABLEDpermanent: an API that is turned off at the source
Any other status, or nonetransient

So report 401 whenever the source rejected the credential, whatever status the source answered with.

A connection with a shared credential, or none, is what this page builds. For it, any failed check makes verify return connection_status failed, with a message that lists each failing check as its label and detail. Core uses failure_kind to decide on re-authentication (needs_reauth) only for connections where each user signs in with their own account.

The scaffold's _check sets http_status for you, from the error the probe raised:

  1. A ConnectorError subclass that sets its own status reports that status. To report a rejected credential, raise one with status = 401.
  2. Otherwise, the HTTP client error the failure was raised from: urllib's HTTPError.code, or the status_code on an httpx or requests error or its response. raise ConnectorError(...) from exc keeps it.
  3. Otherwise, a plain ConnectorError reports its status, 502.
class Rejected(ConnectorError):
status = 401

try:
(await client.get("/health")).raise_for_status()
except httpx.HTTPStatusError as exc:
if exc.response.status_code == 403:
raise Rejected("the source refused the certificate") from exc
raise ConnectorError(f"health check failed: {exc}") from exc

This is in the scaffold from SDK 1.4.1. In a project created with SDK 1.4.0, copy _check and _http_status, with the helpers _http_status calls, from a new scaffold's src/dispatcher.py.

For the verbs, raise a ConnectorError subclass and set its status and kind; the scaffold's classify_error returns them to Core.

Which failure shows where​

What went wrongWhat the admin sees
The pod can't start: the image can't be pulled, or the server crashesCore's Connectors page shows the connector as Workload error, with the reason in its tooltip, and Test is unavailable. In the API, the connection's status is degraded and status_reason says why. Kaizen's admin lists it as unavailable.
The pod runs but can't reach or sign in to its sourceThe connector looks healthy everywhere (its status is ready), and every call fails with a generic error. Open Connectors and select Test: verify lists each check with its label and detail, for example "Records: cannot reach acme-db:5432". Verify returns connection_status failed.

The second row is why each check's detail should say what failed. It's the only place the admin sees the cause. For the pod's own log and the audit event for each call, see Troubleshooting in Run Your Own Connector.