<!-- Generated by website/scripts/sync-docs.mjs from docs/tools.md. Edit that file, not this one. -->

# Tools

> Every page of this site: https://dyokto.github.io/mcp-opa-authz/llms.txt

The six tools the server registers, their parameters and what they return.

## `evaluate_policy`

| Param | Required | Description |
| --- | --- | --- |
| `rego` | yes | Rego source with a `package` declaration. |
| `query` | yes | Rego query, e.g. `data.example.allow`. |
| `input_json` | no | JSON-encoded `input` document. |
| `data_json` | no | JSON-encoded base document for the `data` namespace. |
| `rego_version` | no | `v1` (default) or `v0` for pre-OPA-1.0 syntax. |
| `trace` | no | Return a pretty-printed evaluation trace. Verbose; bounded at 4000 events, 200 lines, 1 KiB per line. |

Returns `defined`, `value`, the raw OPA `result_set` (omitted with `result_set_omitted` past 256 KiB encoded), any `print()` output (200 lines of 1 KiB), and the trace when asked for.

## `authzen_evaluate`

| Param | Required | Description |
| --- | --- | --- |
| `subject` | yes | JSON object. AuthZEN requires `type` and `id`. |
| `action` | yes | JSON object. AuthZEN requires `name`. |
| `resource` | yes | JSON object. AuthZEN requires `type` and `id`. |
| `context` | no | JSON object with runtime context (IP, time, MFA strength). |
| `pdp_url` | no | Override `AUTHZEN_PDP_URL` for this call. |

Returns `decision`, the PDP's `context` if any, the `pdp_url` that answered, and the `request_id` sent as `X-Request-ID` — so a decision in a transcript can be found in the PDP's logs.

## `authzen_evaluate_batch`

Same arguments, plus `evaluations` (a JSON array whose entries override the top-level defaults) and `evaluations_semantic` (`execute_all`, `deny_on_first_deny`, `permit_on_first_permit`). Capped at 100 entries per call. Without `pdp_url`, the endpoint is the `access_evaluations_endpoint` the PDP advertises in its metadata, or `/access/v1/evaluations` under the root of `AUTHZEN_PDP_URL` when it advertises none — the same resolution, cache and same-origin rule as `authzen_search`. `endpoint_source` in the result says which was used.

```json
{
  "subject": "{\"type\":\"user\",\"id\":\"alice\"}",
  "action": "{\"name\":\"read\"}",
  "evaluations": "[{\"resource\":{\"type\":\"doc\",\"id\":\"1\"}},{\"resource\":{\"type\":\"doc\",\"id\":\"2\"}}]"
}
```

## `authzen_search`

The AuthZEN Search APIs. `search` picks which entity is being listed; that entity carries only its `type`.

| `search` | Asks | `subject` | `action` | `resource` |
| --- | --- | --- | --- | --- |
| `subject` | Who may do this to that resource? | `type` only | required | `type` and `id` |
| `resource` | Which resources of a type may the subject act on? | `type` and `id` | required | `type` only |
| `action` | What may the subject do to the resource? | `type` and `id` | must be omitted | `type` and `id` |

`context`, `pdp_url`, `page_limit` and `page_token` are optional. Without `pdp_url`, the endpoint is the one the PDP advertises in its metadata (`search_subject_endpoint` etc.), as the specification requires, falling back to the default path (`/access/v1/search/{subject,resource,action}`) under the root of `AUTHZEN_PDP_URL` when it has no usable metadata. The metadata is cached per PDP for five minutes, and `endpoint_source` in the result says which one was used. An advertised endpoint has to be on the PDP's own origin, because the PDP token goes with the request; a cross-origin one is refused unless passed explicitly as `pdp_url`. Returns `results`, `has_more` and `next_page_token`; pass the token back as `page_token`, with every other argument unchanged, for the next page. A response whose `page` object has no `next_token` is an error even though the specification's own example has one: without it nothing says whether the list is complete.

```json
{
  "search": "resource",
  "subject": "{\"type\":\"user\",\"id\":\"alice\"}",
  "action": "{\"name\":\"read\"}",
  "resource": "{\"type\":\"document\"}"
}
```

## `authzen_discover`

Fetches `/.well-known/authzen-configuration` from a PDP root. `pdp_url` may be a root or an evaluation endpoint — the known AuthZEN path suffix is stripped. For a PDP mounted under a prefix, the well-known string goes between the host and the prefix, as RFC 8615 and the specification place it (`https://gw.example.com/.well-known/authzen-configuration/pdp`); the older appended form (`…/pdp/.well-known/authzen-configuration`) is tried if that 404s. A document whose `policy_decision_point` is not the root it was fetched from is rejected, as the specification requires.

## `coaz_map`

Builds the AuthZEN request a [COAZ-MCP](https://openid.github.io/authzen/authzen-coaz-mcp-binding-1_0.html) enforcement point would send for one MCP request (COAZ-MCP Draft 1, 2026-02-13, openid/authzen at `0139b69`). Pass the tool's `inputSchema` as `input_schema` (or its `x-authzen-mapping` alone as `mapping`), the call's `params`, and the access token's decoded claims as `token`. A tool with no `x-authzen-mapping` gets the binding's default `tools/call` mapping; other methods get their default mapping via `method`. `$`-prefixed values are evaluated as CEL against `params` and `token`.

The result says which mapping applied, which API the request is for (`access_evaluation` or `access_evaluations`), and the request itself. With `evaluate: true` it is sent to the PDP, and `decision` is true only if every decision is a permit. `ping` and notifications come back as `pass_through`; a method with no mapping comes back denied without a PDP call, as the binding requires. `decided_by` says which of the two decided. A short `evaluations` answer is accepted only from a `deny_on_first_deny` mapping, as a deny with `truncated`.

What it checks, as the binding requires of a PEP:

- `subject.id` is the subject-identity claim (`sub`, or `subject_claim` for an on-behalf-of claim). Omitted, it is supplied from the token. Taken from anywhere else, the result carries a warning.
- An `evaluations` entry may not carry its own `subject`.
- A mapping with anything but exactly one envelope, an expression that fails, or a required member that resolves to nothing is a `COAZ mapping error`.
- Server-scoped methods resolve `aud` to one server; pass `resource_id` when `aud` lists several.

The token is not verified here; its claims are used as given. CEL work per expression is bounded by a cost limit.

Deviation: the draft's default mapping for `completion/complete` writes `$params.ref.name` inside a CEL expression, which does not parse. This server uses `params.ref.name` and `params.ref.uri` there ([openid/authzen#816](https://github.com/openid/authzen/issues/816)).

```json
{
  "params": "{\"name\":\"get_customer\",\"arguments\":{\"id\":\"cust-12345\"}}",
  "token": "{\"sub\":\"alice@example.com\",\"client_id\":\"agent-app\"}",
  "input_schema": "{\"type\":\"object\",\"x-authzen-mapping\":{\"evaluation\":{\"subject\":{\"type\":\"identity\",\"id\":\"$token.sub\"},\"action\":{\"name\":\"get_customer\"},\"resource\":{\"type\":\"customer\",\"id\":\"$params.arguments.id\"}}}}"
}
```
