{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/naturali-ai/json-schema/naturali-ai-tool-schema.json",
  "title": "Tool",
  "x-generated": "2026-11-19",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/naturali-ai-openapi.json#/components/schemas/Tool",
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "description": "Public ID of the tool"
    },
    "project_id": {
      "x-naturali-ref": "projects",
      "type": "string",
      "description": "Public ID of the owning project"
    },
    "name": {
      "type": "string",
      "description": "Tool name"
    },
    "type": {
      "type": "string",
      "enum": [
        "http",
        "client",
        "mcp",
        "builtin",
        "pipeline",
        "naturali"
      ],
      "description": "Tool type"
    },
    "description": {
      "type": [
        "string",
        "null"
      ],
      "description": "What the tool does (sent to the model)"
    },
    "parameters": {
      "type": [
        "object",
        "null"
      ],
      "description": "JSON Schema for tool input. On `http` and `pipeline` tools every call's input, `preset_parameters` merged in, must satisfy it: otherwise the call is `400 VALIDATION_FAILED` before any guardrail or dispatch. `mcp` actions declare their own on the server."
    },
    "execute": {
      "type": [
        "object",
        "null"
      ],
      "description": "Execution config for http tools. Supported fields: `url` (required), `method` (default `POST`), `headers`, `body_mode` and `response_mode`. The `url` may contain `{paramName}` placeholders (e.g. `/users/{userId}`) that are replaced at call time with the corresponding tool argument value (URL-encoded). Arguments consumed as path parameters are excluded from the query string and request body. `body_mode` is `json` (default) or `multipart`. In `multipart` mode the merged tool arguments are sent as a `multipart/form-data` body: scalar fields become plain form fields and a field shaped like `{ content_type, filename, data_base64 }` is decoded from base64 and attached as a file part (the hardcoded `Content-Type: application/json` is dropped so `fetch` sets the multipart boundary itself). `response_mode` is `json` (default: the body parsed as JSON, else returned as text) or `base64`, which returns a 2xx body as `{ content_type, filename, data_base64 }` — the same file shape `multipart` accepts, so a pipeline step can relay a downloaded file. `filename` comes from `Content-Disposition` and is omitted when the target names none. In either mode a 2xx body over `TOOL_RESPONSE_MAX_BYTES` is `502 TOOL_RESPONSE_TOO_LARGE`; a non-2xx body over it is cut to it.\n\n`auth` adds a computed request credential, for targets whose `Authorization` value cannot be expressed as a static header. Supported `auth.type` values:\n\n- `aws_sigv4` — signs the request with AWS Signature Version 4. Requires `region`, `service`, `access_key_id` and `secret_access_key`; `session_token` is optional (temporary credentials). Incompatible with `body_mode: multipart`, whose body bytes are not known at signing time.\n- `gcp_service_account` — mints a Google OAuth 2.0 access token from a signed service account assertion and sends it as a bearer token. Requires `credentials` (the service account key file JSON, as a string) and `scopes` (a non-empty array). Tokens are cached per service account and scope set until shortly before they expire.\n- `oauth_connection` — sends the access token of the OAuth connection the turn's actor holds through `oauth_client_id`, refreshing it when it expires. The call is refused unless both the caller and the agent's `policy_ids` allow `oauth-connections:UseOauthConnection` on the connection. With no actor it fails with `TOOL_AUTH_FAILED`; for an actor holding no connected connection, `409 OAUTH_CONNECTION_REQUIRED` naming how to reconnect.\n\nCredential fields accept `{{secret:...}}` references and should use them — a tool is readable by anyone who can `GET /tools`, and the stored reference is what is echoed back, never the resolved value.\n\nA credential slot takes a reference, never a literal: a literal `secret_access_key`, `session_token` or `credentials` under `auth`, a literal credential-named `headers` value (`Authorization`, `Cookie`, or a name containing `api-key`/`token`/`secret`/`password`), or a `url` carrying a password or a literal credential-named query parameter (those names, plus `key` and `sig`/`signature`) is refused with `400 LITERAL_CREDENTIAL`, `meta.paths` naming each one. A stored literal reads back as `{\"no_echo\": true}` (a `url` holding one is masked whole), an object rather than a string so a read-edit-write round trip fails the schema check instead of writing the placeholder in as the credential. A value carrying a `{{secret:...}}` reference is the wiring, not the credential, and stays readable.\n\n`headers` values additionally accept `{{context:<key>}}` references, resolved per call from the caller's `tool_context`, so a per-user credential can be placed in the real header the target expects (`Authorization: Bearer {{context:ocaToken}}`) instead of only in a prefixed context header. Valid **only** inside `headers` — a context value is caller-supplied, so it may not steer the `url` — and a key missing from the `tool_context` at call time fails the tool call with `MISSING_TOOL_CONTEXT_KEY` rather than sending an empty credential. See the Tool Context reference.\n"
    },
    "mcp": {
      "type": [
        "object",
        "null"
      ],
      "description": "MCP server config (`url`, `headers`). `headers` values accept `{{secret:...}}` and `{{context:<key>}}` references, resolved right before the outbound MCP request; `url` accepts `{{secret:...}}` only. A literal credential in `headers` or `url` is refused, exactly as in `execute`. `pin_definitions: true` pins each action's definition; see `mcp_pins`."
    },
    "mcp_pins": {
      "type": [
        "object",
        "null"
      ],
      "readOnly": true,
      "additionalProperties": {
        "type": "string"
      },
      "description": "For an `mcp` tool with `mcp.pin_definitions`: the SHA-256 digest of each action's definition, written once by the first listing an agent turn makes (a deferred server's tools as each is first described). An action whose live definition differs, or that has no pin, is withheld from the model. `null` until pinned; `PATCH` with `mcp_pins: null` or a new `mcp.url` clears it, and the next listing pins again."
    },
    "actions": {
      "type": [
        "array",
        "null"
      ],
      "items": {
        "type": "string"
      },
      "description": "Allowlist of actions to expose. For `builtin` tools: action names (required). For `mcp` tools: an optional allowlist of MCP tool names — when set, only those tools are exposed to the model and callable via `/call`; when `null`, the entire MCP server surface is exposed. Ignored for other tool types."
    },
    "denied_actions": {
      "type": [
        "array",
        "null"
      ],
      "items": {
        "type": "string"
      },
      "description": "For `mcp` tools: an optional denylist of MCP tool names to hide. Applied after `actions` and taking precedence over it — a name in both lists is denied. This is the ergonomic way to scope a read+write MCP server read-only: deny just the write tools instead of enumerating every read tool in `actions`. Names not listed are exposed. `null` (default) denies nothing. Ignored for other tool types."
    },
    "context_keys": {
      "type": [
        "array",
        "null"
      ],
      "items": {
        "type": "string"
      },
      "description": "Optional allowlist of `tool_context` keys that may be forwarded to this tool as prefixed context headers (`X-Naturali-Context-<key>` by default). When `null`, every key in the caller's `tool_context` is forwarded. When set, only the listed keys are, so a per-user credential in `tool_context` can be confined to the tools that need it; `[]` forwards none. The server-pinned identity keys (`session_id`, `actor_id`, `actor_external_id`) are always forwarded. A key consumed by a `{{context:<key>}}` token in this tool's own headers is substituted regardless of this list — the tool declared that header itself."
    },
    "preset_parameters": {
      "type": [
        "object",
        "null"
      ],
      "description": "Fixed parameters pinned on every call this tool makes, whatever its type. Keys matching fields in the input schema are removed from the schema shown to the model, and a pinned value wins over one the model or a direct caller supplies for the same key. On an `mcp` tool a preset reaches each action whose input schema declares it; an action whose schema declares no properties receives every one.\n\nValues accept `{{context:<key>}}` references, resolved per call from the caller's `tool_context`, so a pin can be the run's own value — the one account this run may act on — rather than one fixed when the tool was created. A resolved value is retyped to the parameter's declared schema type; a key missing from the call's `tool_context` fails the call with `MISSING_TOOL_CONTEXT_KEY` rather than sending the literal placeholder. `{{secret:...}}` is not resolved here. See the Tool Context reference."
    },
    "pipeline": {
      "type": [
        "object",
        "null"
      ],
      "description": "Pipeline definition for `pipeline` tools: an ordered `steps` array, each step invoking a tool (optional `action`) and building its `input` from earlier results via JSON Logic evaluated over `{ input, steps }`. A step references its tool either by `tool_id` (an existing, persisted tool) or by an inline `tool` definition — the same shape as `CreateToolRequest` minus `project_id` — executed directly without a Tool row, but never both. An inline step `tool` cannot itself be of type `pipeline`. An optional `output` maps the final result; `steps` may be empty when `output` is set, which computes `output` over the input alone. A literal credential in an inline step `tool` is refused, exactly as in `execute`."
    },
    "output_mapping": {
      "type": [
        "object",
        "null"
      ],
      "description": "Universal JSON Logic mapping applied to the tool's raw result, for every tool type (`http`, `mcp`, `builtin`, `pipeline`, `client`). Evaluated over `{ output: <raw result>, input: <merged input>, action: <action> }`, so `{ \"var\": \"output.text\" }` extracts a bare scalar field instead of requiring a wrapping `pipeline` tool, `{ \"var\": \"input.title\" }` echoes back a field of the request that produced the response, and `{ \"var\": \"action\" }` reads the `mcp` or `builtin` action that ran (`null` on other types). For `pipeline` tools this runs *after* the pipeline's own `output` mapping, over that mapping's result."
    },
    "guardrail_ids": {
      "x-naturali-ref": "guardrails",
      "type": [
        "array",
        "null"
      ],
      "items": {
        "type": "string"
      },
      "description": "Guardrails attached at the tool scope, governing this tool wherever it is used, by any agent."
    },
    "trusted_output": {
      "type": "boolean",
      "description": "Whether this tool's results are content no attacker can write. A result from a tool with `false` (the default) counts toward `runtime.generations.untrusted_tool_results.total` when it enters a generation's context; a `search-knowledge` or `get-document` result from a `builtin` tool counts toward `runtime.generations.knowledge_results.total` either way."
    },
    "created_at": {
      "type": "string",
      "format": "date-time"
    },
    "updated_at": {
      "type": "string",
      "format": "date-time"
    }
  }
}