TE: tools engine
The tools engine (TE) is a Rust service that keeps a catalog of versioned business tools and runs them. Every call is authenticated, authorized by KATIBA policy, checked against the tool’s schemas, idempotent and audited.
TE is private. Your app never calls it. NAK, the agent runtime, calls it during a run when an agent uses a tool. TE is optional: the platform runs without it, and agents then have only knowledge search.
TE is not yet a production release. Its own docs say it is not approved for production tenant traffic until the open production gates are closed and the evidence is recorded. Read that page before you enable it.
How the platform uses TE
- An agent definition lists tools as exact
tool_id@versionnames, for exampleorders.status@2(at most 32). - The operator lists the tools NAK may offer in
NAK_TE_ALLOWED_TOOLS, also as exacttool_id@versionnames. An agent’stoolsshould be a subset of this list. - During a run, NAK offers only tools that are on the agent definition, on the allowlist, and read-only in TE’s catalog.
- For each TE request, NAK signs a fresh service assertion (
nak-te-assertion-v1) for the run’s user, workspace and appplatform. - TE verifies the assertion, checks KATIBA policy, validates the arguments and calls the provider.
If TE is unreachable, its tools are removed for that run. Knowledge search keeps working.
Tools that KATIBA marks as needing human approval are refused. NAK has no approval flow yet, and TE treats RequireApproval as a deny. Read-only, low-risk tools run.
The NAK service assertion
The assertion is an Ed25519 JWT. NAK signs one per request. Neither the user’s token nor NAK’s own credential is sent to TE or to a provider.
| Part | Value | TE check |
|---|---|---|
header alg / typ | EdDSA / nak-te-assertion+jwt | exact; crit is rejected |
header kid | key ID | listed in TE_NAK_ASSERTION_KEYS |
iss | e.g. ngamia-nak | equals TE_NAK_ASSERTION_ISSUER |
aud | e.g. ngamia-te | equals TE_NAK_ASSERTION_AUDIENCE |
sub, tenant_id | user and workspace NAK verified | 1–256 visible ASCII characters |
app_id | platform in this stack | listed in TE_NAK_ASSERTION_APPLICATIONS |
iat, exp | issue and expiry | at most 60 s apart, 5 s leeway |
jti | new UUID per assertion | never seen before (PostgreSQL) |
Unknown claims are rejected. TE stores each (iss, jti) in PostgreSQL and refuses a second use across replicas. If that store is down, the request fails with 503 identity_unavailable.
To rotate NAK’s key: add the new public key to TE, deploy, switch NAK to the new key ID, then remove the old key from TE.
TE also accepts KIDA access tokens (kida-access-token-v1), validated locally against KIDA’s JWKS. It picks the verifier from the token header typ; each verifier then checks its own signature.
Tool catalog and versions
A tool is described by a manifest: ID, version, input and output JSON Schemas, required permissions, risk (low, medium, high, critical) and execution settings (provider ID, timeout, input and output size limits, side_effecting, requires_durable_idempotency).
- Versions are immutable. Changing schemas, permissions, provider binding or execution settings needs a new version.
- Lifecycle: draft, validate, submit for review, approve or reject, publish, deprecate, disable. Each step needs a reason and is audited.
- Exact versions only. Discovery and invocation name an exact published version. A cached list is not a grant: TE rechecks publication, policy and schema on every call.
- The catalog’s
executionblock reportsside_effectinganddurable_idempotency.durable_idempotencyistrueonly when the provider passed conformance with durable deduplication evidence. NAK refuses catalogs without this block.
Example manifest: examples/echo-manifest.json. Reference: manifest .
Invocation and idempotency
POST /v1/tools/{tool_id}/versions/{version}/invoke takes:
{
"contract_version": "1",
"idempotency_key": "run-uuid:call-id",
"arguments": { "order_id": "42" },
"request_id": "req-123"
}- The key is scoped to the verified tenant, app, subject and exact tool version.
- Same key, same arguments: the stored result is replayed (
"replayed": true). - Same key, different arguments:
409 idempotency_conflict. - A key still in progress:
409 invocation_in_progresswith a retry hint. - A provider timeout is stored as a failed outcome. Retrying the same key replays the failure and does not call the provider again.
- TE does not retry providers itself.
- Side-effecting tools are refused unless the provider has evidence of durable same-key deduplication.
Errors use one envelope with a stable code. Provider messages, internal URLs and secrets are never returned. See errors and idempotency .
Audit outbox
Each terminal invocation result is written with its audit event and an outbox row in one PostgreSQL transaction. Authenticated rejections before dispatch are audited too. If audit storage fails, the request returns 503.
A worker sends events to TE_AUDIT_SINK_ENDPOINT, one JSON event per POST, at least once. It retries with capped exponential backoff and marks a row delivered only after a 2xx response. The receiver must deduplicate by the event ID in the Idempotency-Key header. Retention removes only delivered rows; undelivered rows are kept.
Providers
A provider is a remote HTTPS service that does the tool’s work. TE calls it with the HTTP provider protocol : a JSON envelope with the tool ID and version, arguments, remaining deadline_ms, the idempotency key and the minimal verified principal. The provider answers with status and content, which TE validates against the output schema.
Manifests name only a provider ID. The operator binds IDs to endpoints in TE_PROVIDER_CONFIG_JSON:
{
"orders.lookup": {
"endpoint": "https://orders.example.test/v1/invoke",
"health_check_endpoint": "https://orders.example.test/health/ready",
"allowed_hosts": ["orders.example.test"],
"secret_reference": "orders.api",
"maximum_response_bytes": 1048576
}
}- Allowed hosts: HTTPS only, exact host names, no IP literals, wildcards, URL credentials, query or fragment. Redirects and system proxies are disabled. DNS answers that are private, loopback, link-local or metadata are refused. You still need egress firewall rules.
- Credentials: each
secret_referencemaps to a HashiCorp Vault KV v2 path inTE_PROVIDER_VAULT_PATHS_JSON(field#tokenby default). TE sends it as the provider’s bearer token. Credentials are not cached and are redacted if a provider echoes them. - Pinning: a binding is pinned to its provider ID in PostgreSQL. Changing the endpoint, allowlist, response cap, secret reference or Vault path fails startup. Use a new provider ID and a new tool version. Secret values can rotate at the same Vault path.
- Health: readiness sends an authenticated
HEADto each provider’s health URL. It must return 2xx and have no side effects.
Before onboarding a provider, run the conformance check against an isolated staging endpoint:
cargo run -p te-conformance --bin te-provider-conformance -- \
path/to/manifest.json path/to/provider-conformance.jsonA passing report is protocol evidence only. It does not prove durable deduplication across restarts and replicas.
MCP is a TE surface, not a provider type. TE serves MCP at POST /mcp for clients. A manifest’s execution mode is in_process (demo only) or remote_http. To use tools from an upstream MCP server, put a provider in front of it that speaks TE’s HTTP provider protocol.
Policy: platform floor and tenant policies
TE uses KATIBA in two layers. Both must allow tool.discover or tool.invoke for the exact tool_id@version, and every permission the manifest requires.
| Layer | Source | Who controls it |
|---|---|---|
| Platform floor | TE_KATIBA_POLICY_FILE, pinned by TE_KATIBA_POLICY_REVISION | Operator, at deploy time |
| Tenant policy | Active revision in TE’s PostgreSQL | Policy admins, through the admin API |
- The floor may use KATIBA model v2, where
*matches any tenant or app. Tenant policies may not use*and must match the caller’s exact tenant and app. - A tenant without an active policy is denied tool access.
- Tenant policy changes go through draft, review, publish, disable and rollback. The reviewer must differ from the author. A simulate route evaluates a draft without calling a provider.
- Policy admin actions (
policy.admin.*) are checked only against the floor, so a tenant policy cannot grant itself management rights. - TE does not hot-reload the floor. Change it by deploying the file and its revision together.
Validate a policy and print its revision:
cargo run -p te-server --bin te-policy-check -- policy.json \
--expect-revision "$TE_KATIBA_POLICY_REVISION"Example floor: examples/platform-floor-policy.v2.json.
HTTP and MCP surface
| Route | Purpose |
|---|---|
GET /health/live | Liveness |
GET /health/ready | Readiness: KIDA keys, PostgreSQL, audit sink, every provider |
GET /metrics | Request and audit outbox metrics; keep private |
POST /mcp | MCP Streamable HTTP: server/discover, tools/list, tools/call |
GET /v1/tools | Discover visible published tools (cursor paging, limit 1–500) |
GET /v1/tools/{id}/versions/{version} | Exact manifest |
POST /v1/tools/{id}/versions/{version}/invoke | Invoke an exact version |
POST /v1/admin/tools | Register a draft manifest |
GET /v1/admin/tools/{id}/versions/{version} | Admin detail |
POST /v1/admin/tools/{id}/versions/{version}/{action} | validate, submit-review, review, publish, deprecate, disable |
GET, POST /v1/admin/policies | List or create tenant policy drafts |
GET /v1/admin/policies/{id}/revisions/{rev} | Read an exact revision |
POST /v1/admin/policies/{id}/revisions/{rev}/{action} | submit-review, review, publish, disable, rollback, simulate |
MCP targets the stateless revision 2026-07-28. Each MCP tool name encodes the exact ID and version. tools/call requires a stable com.ngamia.tools/idempotencyKey in params._meta. Host and Origin headers are checked against TE_MCP_ALLOWED_HOSTS and TE_MCP_ALLOWED_ORIGINS. See MCP .
Configuration
The production binary te-server needs TE_ENV=production. It refuses SQLite and demo settings.
| Variable | Meaning |
|---|---|
TE_ENV | Must be production |
TE_BIND_ADDR | Listen address; default 127.0.0.1:8080 |
TE_KIDA_ISSUER | KIDA issuer, HTTPS origin |
TE_KIDA_JWKS_URL | Optional; default <issuer>/.well-known/jwks.json |
TE_KIDA_AUDIENCE | Optional; default ngamia-te |
TE_KIDA_APP_ID | KIDA app ID for TE |
TE_KIDA_TIMEOUT_MS | JWKS timeout, 100–10000 ms (default 2000) |
TE_NAK_ASSERTION_ISSUER | Enables NAK assertions, e.g. ngamia-nak |
TE_NAK_ASSERTION_AUDIENCE | Optional; default TE_KIDA_AUDIENCE |
TE_NAK_ASSERTION_APPLICATIONS | Apps NAK may assert; platform in this stack |
TE_NAK_ASSERTION_KEYS | JSON of 1–8 key IDs to base64url Ed25519 public keys |
TE_KATIBA_POLICY_FILE | Platform floor policy, at most 1 MiB |
TE_KATIBA_POLICY_REVISION | Expected sha256: revision of that file |
TE_DATABASE_URL | PostgreSQL with sslmode=verify-full (or verify-ca) |
TE_PG_MAX_CONNECTIONS, TE_PG_MIN_CONNECTIONS, TE_PG_ACQUIRE_TIMEOUT_MS | Pool; defaults 16, 1, 5000 |
TE_PROVIDER_CONFIG_JSON | Provider bindings, 1–128 providers, at most 64 KiB |
TE_PROVIDER_VAULT_PATHS_JSON | Secret references to Vault KV v2 paths |
TE_VAULT_ADDRESS | Vault HTTPS origin |
TE_VAULT_TOKEN_FILE | Vault Agent token sink file (absolute path) |
TE_AUDIT_SINK_ENDPOINT | HTTPS audit receiver |
TE_AUDIT_SINK_SECRET_REFERENCE | Vault reference for the receiver’s bearer token |
TE_AUDIT_RETENTION_DAYS | Delivered audit retention, 30–3650 (default 365) |
TE_MCP_ALLOWED_HOSTS | Required exact host names for /mcp |
TE_MCP_ALLOWED_ORIGINS | Optional exact origins; unset denies requests with Origin |
TE_MAX_CONCURRENT_REQUESTS | In-flight cap per process (default 128) |
TE_INVOCATION_RATE_LIMIT, TE_INVOCATION_RATE_WINDOW_MS | Per-principal limit shared through PostgreSQL; default 120 per 60000 ms |
TE_IDEMPOTENCY_LEASE_MS | Claim lease; default 330000, above the 300000 ms max tool timeout |
TE_SHUTDOWN_GRACE_MS | Drain period on SIGTERM (default 30000) |
TE_KIDA_ENDPOINT, TE_KIDA_CALLER_CREDENTIAL and the old TE_JWT_* settings are retired; startup fails if they are set. Full list: operator guide .
Operations
- Enable in the stack: set
NAK_TE_ENDPOINTto TE’s HTTPS URL (NAK allows plain HTTP only on loopback),NAK_TE_ALLOWED_TOOLSandTE_IMAGEindeploy/.env, put Vault and policy settings indeploy/secrets/te.env, then rundocker compose --profile tools up -d. See deployment . - Readiness stays
503until KIDA keys, PostgreSQL, the audit sink’s secret and DNS, and every provider’s secret, DNS, TLS and health check pass. Restrict/health/readyto health checks: each call probes every provider. - Migrations run at startup. Back up the database before deploying one.
- Rate limits: over the limit returns
429 rate_limited; if PostgreSQL cannot enforce the limit,503 rate_limit_unavailable. Rate-limit unauthenticated traffic at the edge. - TLS: TE does not terminate TLS. Put it on a private network behind a TLS proxy.
- Logs record method, status and duration only, never paths, tokens or bodies.
Status and open gates
TE has KIDA and NAK identity, KATIBA policy, Vault credentials, the PostgreSQL audit outbox and shared rate limits. Open items include, among others: staging provider onboarding evidence, shared NAK and kernel conformance, full HTTP and MCP parity, tracing and alerts, backup, restore and migration rollback in production, and the SRS acceptance checklist. NAK still has an open staging run against a deployed TE.