Skip to Content
The Ngamia platform API is in preview. Endpoints may change before general availability.
EnginesTE: tools

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

  1. An agent definition lists tools as exact tool_id@version names, for example orders.status@2 (at most 32).
  2. The operator lists the tools NAK may offer in NAK_TE_ALLOWED_TOOLS, also as exact tool_id@version names. An agent’s tools should be a subset of this list.
  3. During a run, NAK offers only tools that are on the agent definition, on the allowlist, and read-only in TE’s catalog.
  4. For each TE request, NAK signs a fresh service assertion (nak-te-assertion-v1) for the run’s user, workspace and app platform.
  5. 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.

PartValueTE check
header alg / typEdDSA / nak-te-assertion+jwtexact; crit is rejected
header kidkey IDlisted in TE_NAK_ASSERTION_KEYS
isse.g. ngamia-nakequals TE_NAK_ASSERTION_ISSUER
aude.g. ngamia-teequals TE_NAK_ASSERTION_AUDIENCE
sub, tenant_iduser and workspace NAK verified1–256 visible ASCII characters
app_idplatform in this stacklisted in TE_NAK_ASSERTION_APPLICATIONS
iat, expissue and expiryat most 60 s apart, 5 s leeway
jtinew UUID per assertionnever 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 execution block reports side_effecting and durable_idempotency. durable_idempotency is true only 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_progress with 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_reference maps to a HashiCorp Vault KV v2 path in TE_PROVIDER_VAULT_PATHS_JSON (field #token by 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 HEAD to 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.json

A 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.

LayerSourceWho controls it
Platform floorTE_KATIBA_POLICY_FILE, pinned by TE_KATIBA_POLICY_REVISIONOperator, at deploy time
Tenant policyActive revision in TE’s PostgreSQLPolicy 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

RoutePurpose
GET /health/liveLiveness
GET /health/readyReadiness: KIDA keys, PostgreSQL, audit sink, every provider
GET /metricsRequest and audit outbox metrics; keep private
POST /mcpMCP Streamable HTTP: server/discover, tools/list, tools/call
GET /v1/toolsDiscover visible published tools (cursor paging, limit 1–500)
GET /v1/tools/{id}/versions/{version}Exact manifest
POST /v1/tools/{id}/versions/{version}/invokeInvoke an exact version
POST /v1/admin/toolsRegister 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/policiesList 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.

VariableMeaning
TE_ENVMust be production
TE_BIND_ADDRListen address; default 127.0.0.1:8080
TE_KIDA_ISSUERKIDA issuer, HTTPS origin
TE_KIDA_JWKS_URLOptional; default <issuer>/.well-known/jwks.json
TE_KIDA_AUDIENCEOptional; default ngamia-te
TE_KIDA_APP_IDKIDA app ID for TE
TE_KIDA_TIMEOUT_MSJWKS timeout, 100–10000 ms (default 2000)
TE_NAK_ASSERTION_ISSUEREnables NAK assertions, e.g. ngamia-nak
TE_NAK_ASSERTION_AUDIENCEOptional; default TE_KIDA_AUDIENCE
TE_NAK_ASSERTION_APPLICATIONSApps NAK may assert; platform in this stack
TE_NAK_ASSERTION_KEYSJSON of 1–8 key IDs to base64url Ed25519 public keys
TE_KATIBA_POLICY_FILEPlatform floor policy, at most 1 MiB
TE_KATIBA_POLICY_REVISIONExpected sha256: revision of that file
TE_DATABASE_URLPostgreSQL with sslmode=verify-full (or verify-ca)
TE_PG_MAX_CONNECTIONS, TE_PG_MIN_CONNECTIONS, TE_PG_ACQUIRE_TIMEOUT_MSPool; defaults 16, 1, 5000
TE_PROVIDER_CONFIG_JSONProvider bindings, 1–128 providers, at most 64 KiB
TE_PROVIDER_VAULT_PATHS_JSONSecret references to Vault KV v2 paths
TE_VAULT_ADDRESSVault HTTPS origin
TE_VAULT_TOKEN_FILEVault Agent token sink file (absolute path)
TE_AUDIT_SINK_ENDPOINTHTTPS audit receiver
TE_AUDIT_SINK_SECRET_REFERENCEVault reference for the receiver’s bearer token
TE_AUDIT_RETENTION_DAYSDelivered audit retention, 30–3650 (default 365)
TE_MCP_ALLOWED_HOSTSRequired exact host names for /mcp
TE_MCP_ALLOWED_ORIGINSOptional exact origins; unset denies requests with Origin
TE_MAX_CONCURRENT_REQUESTSIn-flight cap per process (default 128)
TE_INVOCATION_RATE_LIMIT, TE_INVOCATION_RATE_WINDOW_MSPer-principal limit shared through PostgreSQL; default 120 per 60000 ms
TE_IDEMPOTENCY_LEASE_MSClaim lease; default 330000, above the 300000 ms max tool timeout
TE_SHUTDOWN_GRACE_MSDrain 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_ENDPOINT to TE’s HTTPS URL (NAK allows plain HTTP only on loopback), NAK_TE_ALLOWED_TOOLS and TE_IMAGE in deploy/.env, put Vault and policy settings in deploy/secrets/te.env, then run docker compose --profile tools up -d. See deployment .
  • Readiness stays 503 until KIDA keys, PostgreSQL, the audit sink’s secret and DNS, and every provider’s secret, DNS, TLS and health check pass. Restrict /health/ready to 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.

Last updated on