# Agent Gateway: Authorize Agent-to-Agent and MCP Calls

> How the IndyKite Agent Gateway (IAG) decides whether an agent call may proceed, what to set up in your identity provider and your IndyKite project, how to configure, run and test one gateway, and how to read its responses and audit records.

**Category:** Agent Gateway

## Summary

From zero to a first authorized call: identity provider clients, graph data, KBAC and ContX IQ configuration, the gateway config file, a test request, and the audit record it produces. Then the complete reference: every configuration key with the exact startup errors, the capability checks that decide which tools, resources, prompts and skills a caller may use, deployment, HTTP behaviour in a2a and mcp mode, and the audit record format.

## Content

# What is the Agent Gateway?

The **IndyKite Agent Gateway** (IAG) is a self-hosted proxy placed in front of one AI agent or one MCP server. On every request it authenticates the caller, establishes the chain of agents acting for the user, checks in the IndyKite Knowledge Graph that this chain is a modelled workflow the user may trigger, forwards the request with a delegation token, and writes an audit record. Nothing reaches the protected agent without passing the gateway. You run **one gateway per protected agent**.

```text
user token
   │
   ▼
[orchestrator-iag] ──► orchestrator agent ──► [retriever-iag] ──► retriever agent
   introspect · exchange · check chain [orchestrator] against wf1 · authorize · audit
                                            introspect · exchange · check chain [orchestrator, retriever] · authorize · audit
```

Two protocols are understood, selected by `protected_agent.protocol`: `a2a` (Agent-to-Agent JSON-RPC, the default) and `mcp` (Model Context Protocol over Streamable HTTP). The [Agent Gateway MCP tutorial](/tutorials/tutorial-agent-gateway-mcp) walks the mcp mode end to end with a Google Drive server; this guide uses the a2a mode for its example and documents both.

## Terms used in this guide

| Term | Meaning |
| --- | --- |
| **IKG** | The IndyKite Knowledge Graph: nodes and relationships loaded through the Capture API ([Data Schema guide](/guides/guide-data-schema)). |
| **KBAC** | Knowledge-Based Access Control: a policy is a graph pattern between a subject and a resource; the **AuthZEN** API answers "may this subject perform this action on this resource?" from it ([AuthZEN guide](/guides/guide-authzen)). |
| **ContX IQ** | The API that runs a stored **Knowledge Query** against the graph under a ContX IQ policy, and whose `whoami` endpoint resolves a token to its graph subject ([ContX IQ guide](/guides/guide-contx-iq)). The gateway uses only `whoami`. |
| **Admission policy** | The KBAC policy the gateway asks AuthZEN to evaluate for every request: subject the user, action `authzen.action`, resource the protected agent, condition comparing the delegation chain in `$ik_token.act_chain` with a workflow's path in the graph. |
| **A2A** | Agent-to-Agent protocol: JSON-RPC methods such as `message/send` exchanged between agents. **MCP** is the Model Context Protocol between an AI client and a tool server. |
| **Subject** | The user on whose behalf the call is made: the `sub` claim of the tokens. **Actor**: an agent acting for the subject. The actors form the **delegation chain**. |
| **Delegation token** | A token obtained by OAuth 2.0 token exchange (RFC 8693) whose `act` claim names the acting agent and nests the previous `act`, so `act.sub`, `act.act.sub`, ... is the chain, newest first. |
| **Token Service** | The optional self-hosted IndyKite issuer of delegation tokens ([Token Service guide](/guides/guide-token-service)). Without it, your identity provider performs the exchange. |
| **Application Agent credential token** | The credential the gateway sends as `X-IK-ClientKey` to the IndyKite APIs; the agent needs the `Authorization` and `ContXIQ` API permissions ([Credentials guide](/guides/guide-credentials)). |
| **GID** | The platform identifier of a configuration object, prefixed `gid:`. Where a GID is accepted, the object's `name` usually is too. |

# How a request is decided

![One request through the Agent Gateway, nine steps in order. 1, the bearer token is introspected at the identity provider; a missing or inactive token answers 401. 2, the gateway gets its own actor token from the identity provider with the client credentials grant. 3, both are exchanged for a delegation token at the identity provider, or at the Token Service when one is configured. 4, the subject is resolved with ContX IQ whoami; a token it rejects answers 401. 5, admission: one AuthZEN evaluation decides whether the subject may reach the agent through the delegation chain; a denial answers 403. 6, capabilities: an AuthZEN resource search gives the tools, resources, prompts and skills the caller may use; lists are filtered and a call outside the set answers 403. 7, intent, in a2a mode with ibac.enabled: the Intent Agent reads the prompt, and with a Token Service the intent is compared with the skills of the agent; without an intent the gateway answers in place of the agent, and an intent that fits no skill answers 403. 8, mappings, in mcp mode with ibac.enabled and an intent in the token: a call is checked against the mapping of the capability and the resolved evaluations are decided by AuthZEN; a mismatch or a denial answers 403. 9, forward to the agent or the MCP server with the delegation token; an unreachable target answers 502. One audit record is written per decision, before forwarding.](/assets/images/iag-request-pipeline.svg)

The picture is the overview: each step, the party it asks, and what a refusal there answers. The list below has the exact rules of each step, including the statuses the picture leaves out.

For every request, in this order:

1. **Bearer token, or the delegation token of the previous hop.** A request without `X-IK-Token` starts a workflow: `Authorization: Bearer <token>` is required, without it the answer is `401`, and the token is introspected at the identity provider and must be active. With `token_service` configured, the token must also have been issued for one of `protected_agent.authentication.audiences`, read from the introspection answer or, when that names none, from the token itself; any other token, one without an audience included, is refused with `401` and `Access token not issued for this agent`, so a workflow starts only at the agent the token was issued for. A request with `X-IK-Token` is a later hop: the gateway introspects that token at the issuer named under `token_service`, requires an `act` object and a `sub` in it, and needs no `Authorization`. A bearer token that travels beside it is handled by `authorization_header.forward`: with the default `correct_audience` it is introspected and passed on only when it is active and issued for one of `protected_agent.authentication.audiences`, otherwise it is dropped and the request goes on; with `all` it is passed on as sent; with `none` nothing is passed on. A token the gateway passes on must also name the same user as the delegation token while `authorization_header.same_user_check` is on (the default). Without `token_service`, `X-IK-Token` is ignored and every hop arrives with the previous hop's delegation token as its bearer token.
2. **Actor token.** The gateway obtains a token for the protected agent with the client credentials grant, using `protected_agent.authentication`. The request names an `audience` only when `identity_provider.client_credential_audience` is set. The token is kept and reused until `identity_provider.client_credential_renew_before` (default 10 seconds) before the `expires_in` of the grant answer; an answer without `expires_in`, or with a lifetime no longer than that margin, gives a token used once. When the exchange is refused with `400` or `401`, the gateway drops the kept token and tries once more with a new one, so a revoked token costs one retry, not a failed request.
3. **Delegation token.** The subject token, or on a later hop the incoming delegation token, and the actor token are exchanged for one delegation token. Without a Token Service the identity provider does the exchange at `identity_provider.exchange_endpoint`; with `token_service` configured, the issuer named there does: the IndyKite Token Service, or an identity provider that meets the requirements listed under [token_service](#configuration). On a later hop the issuer nests the incoming chain in the token it mints, so the chain grows by one agent per hop. The result must carry `sub` and an `act` object; the gateway reads the chain from it.
4. **Subject.** The gateway sends the bearer token of the request to ContX IQ `GET /contx-iq/v1/whoami`, with the AppAgent credential as `X-IK-ClientKey`, and takes the subject from the answer: `type` is the `ikg_node_type` of the project's Token Introspect configuration that validates the token, `id` is the token's subject claim ([whoami](/guides/guide-contx-iq#whoami)). A token `whoami` rejects ends the request with `401`. On a later hop that carries no bearer token, or whose bearer token the gateway neither passes on nor checks, the gateway sends the delegation token it just minted instead, as the bearer token; the platform resolves it through the Token Introspect configuration that matches the issuer under `token_service`, so every subject of such a hop gets the `ikg_node_type` of that one configuration.
5. **Admission.** The gateway asks AuthZEN once, with `POST /access/v1/evaluation`, whether the subject may reach the protected agent. The subject is the `type` and `id` from `whoami`; the action is `authzen.action`; the resource `id` is the newest hop of the chain, the gateway's own agent, and the resource `type` is that hop's `act.type`, or `protected_agent.node_type` when the token has none, or `Agent` when neither is set. `authzen.input_params` and `authzen.policy_tags`, when set, go as `context`. Beside the AppAgent credential in `X-IK-ClientKey`, the call carries the user's bearer token in `Authorization`, when the request had one, and the delegation token of this hop in `X-IK-Token`, with and without a Token Service; the policy therefore reads the chain as `$ik_token.act_chain` and compares it with the graph itself. The gateway does not compare the chain with anything: `decision: false` means `403`. A chain that cannot be read is refused without a call, and a token whose `act.type` differs from a set `protected_agent.node_type` is refused as an error. The decision is kept per subject, resource type, chain and token claims for `authzen.cache_ttl`, and the audit record says whether it came from the cache. In `mcp` mode, a request that names or lists capabilities skips this step and gets the capability decision of the next step instead.
6. **Capabilities (mcp mode, and the extended card in a2a mode).** With `authzen.capabilities.enabled` on, the default, the gateway also decides what the caller may use on the server. For each kind of capability a request needs, it reads the **permitted set** with one `POST /access/v1/search/resource`: the subject from `whoami`, the action `authzen.capabilities.action` (`CAN_USE` by default), the resource type from `authzen.capabilities.labels` (`Tool`, `McpResource`, `Prompt` and `Skill` by default), with the same headers and `context` as the admission call. The answer is the identifiers the caller may use: tool names, resource URIs, prompt names, skill ids. A `tools/list`, `resources/list` or `prompts/list` is a **discovery**: the server's list is filtered to the set of its kind, in the server's order and with its cursor untouched, and a caller who may use nothing of the kind gets an empty list without the server being called. A `tools/call`, `resources/read`, `resources/subscribe`, `prompts/get` or a `subscriptions/listen` naming resources is an **invocation**: every capability it names must be in the set of its kind, or the answer is `403` with the JSON-RPC error `-31403`, `Forbidden: the caller may not use the named tool` (or `resource`, `prompt`), and the server is not called. Such a request gets no admission decision: one decision per request, never both. Every other request, `initialize` included, keeps the admission decision. In `a2a` mode every request keeps the admission decision, and only the extended agent card is filtered, to the skills of the permitted set; with `ibac.enabled` and an intent in the delegation token, the card keeps of those skills only the ones that fit that intent, and with capability checks off the intent is compared with every skill of the agent, as the Mappings step describes. A set is kept per subject, action, label, chain and token claims for `authzen.cache_ttl`, an empty one too; a set that cannot be read fails the request with the platform's status, or `500`. The graph model and the policy are under [Capability checks](#capability-checks-what-the-caller-may-use).
7. **Intent (a2a mode, with `ibac.enabled`).** For a `message/send` or `message/stream` whose message has text, the gateway sends the text parts, joined one per line, to the [Intent Agent](/guides/guide-intent-agent#gateway) with the `whoami` subject in the metadata, authenticated by its own client credentials token for `intent_agent.audience`. Without `token_service`, an intent lets the message through; with it, the intent must also fit the skills of the agent, as described below. A failed task answers the caller in place of the agent, with status `200`: an agent message in the same `contextId` whose text is the task's error followed by its obligation, and whose `metadata.intent_error` holds `prompt`, `error`, `reason` and `obligation`; a streaming request gets it as its one event. An Intent Agent that cannot be reached, or answers in a shape the gateway cannot read, refuses the message with `502`; one that does not answer within `intent_agent.timeout`, with `504`. Messages without text and the other methods are not sent to the Intent Agent. The gateway reads an intent of at most 64 evaluations; without `token_service`, a larger one is a `502`. With `token_service`, the intent is first **compared with the skills** of the agent the caller may use: the permitted skills, or every skill of the agent with capability checks off. A skill covers an evaluation when the subject type, the resource type and the action of the evaluation match one of its `x-coaz-mappings`; a skill without a mapping covers every evaluation with `ibac.capabilities.unmapped: allow` and none with `deny`. An evaluation that no skill covers is left out, and an intent of which nothing is covered refuses the message with `403` and `Authorization check failed`; the agent does not get it. A message without text has no intent of its own: when its chain carries one, the newest is compared the same way. With `token_service`, a message with an intent also gets a **second exchange** of the delegation token: the same subject token and actor as the first, plus the evaluations of the intent that fit the skills in the `intent` parameter, exactly as the Intent Agent wrote them, with no field it left out or left empty, which the issuer writes into `act.intent` of this hop. The gateway authorizes on the token of the first exchange, and the agent receives the token of the second in `X-IK-Token`, so the next hop and the platform see what this hop is about to do. This needs an issuer that knows the `intent` parameter, such as the [IndyKite Token Service](/guides/guide-token-service#intent): a token that comes back without all the evaluations is refused with `502` and `cannot delegate the token with the intent`. An intent with more evaluations than the Token Service accepts (its `max_intent_evaluations`, 10 by default) or more than 64 is neither forwarded nor cut down: the gateway answers in place of the agent, as for a failed task, with the error `The request asks for too much at once: its intent has <n> evaluations, too many for one request.`, the reason `intent_too_large` and the obligation `Send the request in smaller parts.` A delegation token the Token Service finds too large, from either exchange, is refused with `403` and `Authorization check failed`. A `429` of the second exchange goes to the caller, as on the first.
8. **Mappings (with `ibac.enabled` and an intent: invocations in mcp mode, the extended card in a2a mode).** When the delegation token of the request carries an intent, written by an earlier hop, the gateway also checks each invocation (`tools/call`, `resources/read`, `resources/subscribe`, `prompts/get`, `subscriptions/listen`) against the [x-coaz-mappings](/guides/guide-ibac#mappings) of the capability it names. The gateway keeps a catalog of the server's tools, resources and prompts with their mappings, filled from every list that passes through it, before filtering, and kept for `ibac.capabilities.cache_ttl`. For a capability it has not seen listed, it first lists the server itself, every page of that kind, with the tokens of the request; that list fills the catalog and never reaches the caller, and a server that cannot be listed fails the call with `502` and `cannot list the capabilities of the MCP server`. Then: a capability whose mapping cannot be read is refused with `403` and the JSON-RPC error `-31403`, `Forbidden: the named tool has an invalid mapping` (or `resource`, `prompt`); a capability without a mapping, or one the server does not list, goes on when `ibac.capabilities.unmapped` is `allow` (the default), so the permitted set alone decides, and is refused with `Forbidden: the named tool has no mapping` when it is `deny`; a capability with a valid mapping is checked twice. **Against the intent:** the call goes on only when at least one evaluation of the current intent, the newest intent in the `act` chain of the token, matches a mapping of the capability by subject type, resource type and action; a mapping that lists no action accepts any action. The ids of a mapping are read from the call, `$request` being the `params` of the request and `$token` the claims of the delegation token, never from the intent; a mapping whose expression has no value, or a value that is not a non-empty string, does not match, so a call without the argument a mapping reads is refused. A call the intent does not match is refused with `403` and `Forbidden: the named tool does not match the intent` (or `resource`, `prompt`). **At the platform:** for every matched mapping whose subject and resource both name an id, one evaluation is resolved, the resource with its id and the action of the matched evaluation of the intent, and the gateway sends the evaluations of the request in one `POST /access/v1/evaluations`, with the subject from `whoami` and the same headers and `context` as the admission call. The call goes on only when the platform allows every one of them; otherwise it is refused with `403` and `Forbidden: the caller may not access the data the named tool uses` (or `resource`, `prompt`), and when the platform cannot be asked the call fails with the platform's status and the server does not get it. The answers are kept like an admission decision, for `authzen.cache_ttl`. A request that names several capabilities goes on only when every one of them passes. **The lists are filtered by the intent too:** of a `tools/list`, `resources/list` or `prompts/list` answer, after the permitted set with capability checks on and of every entry with them off, an entry stays when one of its mappings matches at least one evaluation of the current intent. An entry without a mapping stays with `ibac.capabilities.unmapped: allow` and is removed with `deny`; an entry whose mapping cannot be read is removed. Nothing is refused: a list can come back empty. Without an intent in the delegation token this step does not run: the gateway lists nothing itself and refuses nothing. In `a2a` mode, a message is compared with the mappings of the agent's skills in the Intent step above, with a Token Service; here the mappings decide what the **extended agent card** lists. With an intent in the delegation token of the request, the card lists only the skills that fit the **current intent**, of the permitted skills with capability checks on and of every skill of the agent with them off. The current intent is the newest intent in the `act` chain of the token: a skill fits when the subject type, the resource type and the action of at least one evaluation of the intent match one of its `x-coaz-mappings`. The gateway reads the mappings from the skills of the card as the agent sent it, before any filter, and keeps them for `ibac.capabilities.cache_ttl`. A skill without a mapping follows `ibac.capabilities.unmapped`: with `allow` it stays on the card, with `deny` it is dropped. A skill whose mapping cannot be read, or whose id the card lists twice, is dropped in both settings. When the skills of the card cannot be read with their mappings, the caller gets an error and no card. Without an intent in the token, the card is filtered to the permitted set only, or with capability checks off goes to the caller with every skill.
9. **Forward.** Without a Token Service the delegation token replaces the caller's token in `Authorization`; an A2A agent then gets no other header of the caller, and an MCP server gets all of them except `Authorization`, `X-IK-Token` and `Accept-Encoding`. With one, the delegation token travels in `X-IK-Token`, where IndyKite policies read it as `$ik_token`; `Authorization` carries what `authorization_header.forward` passes on, by default the user's token when it is issued for this agent; and the other headers of the caller travel too, except the headers of one connection (`Connection` and the headers it names, `Keep-Alive`, `Proxy-Authorization` and the like). A call to an A2A agent with a Token Service also carries the `A2A-Extensions` header naming the delegated token extension, whose identifier is the string `https://indykite.com/extensions/delegated-token/v1` (a name to compare against, not a page), so the agent knows the token in `X-IK-Token` is the token of that extension.
10. **Audit.** One record per decision, written before forwarding, on every outcome including refusals: `action` names the question (`ADMISSION`, `DISCOVERY`, `INVOCATION`, `INTENT`, or `noop` for a request refused before any question was asked) and `decision` the answer, see [Audit records](#audit-records). What IBAC adds beyond this step, the mappings a skill or tool declares and how an intent is matched against them, is in the [IBAC engine guide](/guides/guide-ibac).

Facts that follow from this sequence and matter when something is refused:

- The subject is always the user. On later hops the token's `sub` is still the user's; an agent is the subject only when it starts a workflow with its own token.
- The graph must hold a node of the subject type whose `external_id` equals the token's `sub`. For a `2.0-kbac` policy that node must be an identity node (`is_identity: true`). Otherwise every call ends in `403`. The subject type is the `ikg_node_type` of the matching Token Introspect configuration.
- Every token that reaches a gateway in `Authorization` needs a Token Introspect configuration in the project whose `jwt_matcher` matches its `iss` and `aud`; without one, `whoami` refuses it and the gateway answers `401`. On a later hop without a Token Service, `Authorization` carries the delegation token of the previous hop, so the issuer and audience of those tokens need a configuration too. With a Token Service, `Authorization` carries the user's own token at the start of a workflow; a later hop may carry it too, or no `Authorization` at all, and then the delegation token itself is resolved, so the issuer and audience of the delegation tokens (the issuer under `token_service` and its `audience`) need a Token Introspect configuration as well.
- The agent names in the chain are the `sub` claims of the agents' client-credentials tokens, as the exchange writes them into `act.sub`. The `Agent` nodes' `external_id` must equal those values. Which value an identity provider puts in `sub` for a client-credentials token is the provider's choice; the IndyKite demos run on a provider that uses the client id.
- The admission policy sees both tokens. The gateway sends the user's bearer token in `Authorization` and the delegation token in `X-IK-Token` on its admission call, in both modes, so the policy reads `$token` and `$ik_token`, and compares `$ik_token.act_chain` with the `INVOKES` path of a workflow in the graph. For the platform to read the delegation token, the project needs a Token Introspect configuration for the issuer and audience of the delegation tokens, also without a Token Service. What the protected agent receives does not change: without a Token Service it still gets the delegation token in `Authorization` only.
- The resource of the admission call is the protected agent, and its type selects the policy: one admission policy covers every agent and MCP server of that type. The type comes from the delegation token's `act.type`, which the IndyKite Token Service writes from its `idp.actor_type`, `Agent` by default. With an identity provider that writes no `act.type`, set `protected_agent.node_type`, or the type is `Agent`. When the token's type and the setting differ, every request is refused with an `ERROR` record that names both.
- A subject or resource type without a matching policy gives `decision: false`, so `403`, not an error.
- Without a Token Service, the chain grows across hops only if the identity provider nests the previous `act` claim when the subject token is itself a delegation token. RFC 8693 allows this but does not require it; a provider that does not nest gives the second gateway a chain of one agent, which matches no two-agent workflow.
- With a Token Service, an incoming `X-IK-Token` is validated at the issuer and becomes the subject of the next exchange. It must carry an `act` object, otherwise `401` with `Invalid delegated token, missing act claim`: an issuer may mint users' access tokens as well, and such a token cannot take the place of a delegation token. When a bearer token travels beside it and `authorization_header.same_user_check` is on, its `sub` must equal the `sub` of the `Authorization` token, otherwise `401` with `Invalid delegated token, subject mismatch`; with the check off, the bearer token of a later hop is not read at all. Without a Token Service an incoming `X-IK-Token` is ignored and removed from the forwarded request.
- With a Token Service, a user's token starts a workflow only at the gateway whose `protected_agent.authentication.audiences` lists one of its audiences. Sending the token for the orchestrator straight to the retriever's gateway is refused with `401` and `Access token not issued for this agent`, before any chain or policy check. A direct call to a later agent is allowed by issuing the user a token for that agent's audience and modelling the one-agent workflow, not by reusing the orchestrator's token.

## What is cached

- The admission decision is cached for `authzen.cache_ttl` (default 5 minutes), per subject, resource type, chain and the claims of both tokens other than `exp`, `iat`, `nbf` and `jti`, so a policy may read any other claim and a new token with the same content hits the cache. A grant or revocation in the graph takes effect when the entry expires, not on the next call.
- A failed admission call is cached as well: callers keep getting the error until `authzen.cache_update_after_error` (default 10 seconds) has passed and a retry succeeds.
- The `whoami` answer is kept per issuer, audience and subject of the token for `contx_iq.cache_ttl`; `0` keeps none. A failed `whoami` is not kept. A change of the Token Introspect configuration, such as its `ikg_node_type`, reaches the gateway after up to `contx_iq.cache_ttl`.
- Introspection and the token exchange are not cached; they run on every request. The protected agent's client credentials token, and the gateway's own token for the Intent Agent, are kept and reused until `identity_provider.client_credential_renew_before` (default 10 seconds) before they expire; a token the issuer or the Intent Agent refuses is replaced once.
- In a2a mode the agent card, and the client built from it, are kept for `a2a.cache_ttl` (default 5 minutes) and fetched again after `a2a.cache_update_after` (defaults to `cache_ttl`); a new delegation token causes no new card fetch, the tokens travel with each call. A failed card fetch is returned to every call for `a2a.cache_update_after_error` (default 10 seconds) before the next attempt.

# a2a or mcp: the two kinds of link in a chain

The decision sequence above is the same in both modes. What differs is what sits behind the gateway and, because of it, where the chain can go next. An A2A agent can itself call another gateway, so it is a link in the middle of a chain; an MCP server only answers tool calls, so it is always the last link.

|  | a2a mode | mcp mode |
| --- | --- | --- |
| Behind the gateway | One A2A agent, reached through the JSON-RPC URL of its agent card. | One MCP server over Streamable HTTP: a third-party server, or the IndyKite MCP server itself. The gateway serves one MCP endpoint, at the path of `service.base_url`, and forwards it to the server's endpoint URL in `protected_agent.base_url`. |
| Who calls the gateway | The user's client on the first hop; an upstream agent on later hops. | An MCP client: the user's tool directly, or an agent that uses the server as a tool. |
| What the caller sends | A JSON-RPC message such as `message/send`, with the user's token in `Authorization` at the start of a workflow and, with a Token Service, the chain so far in `X-IK-Token` on a later hop, with or without the user's token beside it. | The MCP messages as they are, `initialize`, `tools/list`, `tools/call`, with `Mcp-Protocol-Version`, and the same two headers. In front of the IndyKite MCP server with a Token Service, a later hop must keep the user's token in `Authorization` beside `X-IK-Token`: the gateway passes `Authorization` on as `authorization_header.forward` decides (by default only a token issued for this agent, nothing when the hop had none), and that server requires a bearer token and answers `401` without one even when `X-IK-Token` is present. |
| Position in the chain | Any: the agent receives the forwarded token and can call the next gateway, which exchanges again and appends the next agent to the chain. | Last: the chain ends at the server's agent name. A workflow that includes an MCP server lists it last. |
| Workflow shapes it needs, with the reference admission policy | `[orchestrator]` for the first gateway, `[orchestrator, retriever]` for the second, one workflow per shape. | `[retriever, mcp-agent]` when the retriever calls the server; a separate `[mcp-agent]` workflow if a user's own MCP client may call it directly. |
| What is forwarded | The JSON-RPC request to the card's interface URL on the configured host; the agent's response, or a JSON-RPC error frame in a stream. | The MCP request unchanged, to the server's endpoint URL with the request's query appended; `Mcp-Session-Id` and the server's status and body pass through, streamed for SSE, except that with capability checks on the server's `tools/list`, `resources/list` and `prompts/list` answers are filtered to what the caller may use. |
| What the protected target can do with the chain | With a Token Service: read `X-IK-Token` and call IndyKite APIs with it, so its own policies see `$ik_token`, or exchange it again at the Token Service for its next hop. Without one, it receives the delegation token in `Authorization` only. | The IndyKite MCP server validates `X-IK-Token` itself and its policies see `$ik_token`; a third-party server just receives the headers. |
| Refusals specific to the mode | The gateway serves the agent card at `/.well-known/agent-card.json`, public without a token, extended with one, and public again for a caller the gateway refuses (see [HTTP behaviour](#http-behaviour)). The card's interface URLs are rewritten to the scheme and host of `base_url`, and a card that cannot be used, or a redirect off that host, fails with `502`. With capability checks on, the extended card lists only the skills the caller may use, and with `ibac.enabled` and an intent in the delegation token, of them only the skills that fit that intent; with capability checks off, of every skill of the agent only the ones that fit it. With `ibac.enabled` and a Token Service, a message whose intent fits no skill of the agent the caller may use is refused with `403`. | A request to any path other than the endpoint path is answered `404` before the token is read, except the two OAuth metadata paths, which are public. A `401` carries a `WWW-Authenticate` challenge that links the gateway's protected resource metadata (see [OAuth discovery](#oauth-discovery)). Then the protocol-revision and request-classification checks of the [mcp mode table](#http-behaviour), answered as JSON-RPC errors before authorization. With capability checks on, an invocation outside the caller's permitted set is answered `403` with the JSON-RPC error `-31403`, and a list of a kind the caller may use nothing of is answered empty, without the server. With `ibac.enabled` and an intent in the delegation token, the lists are also filtered to the entries that fit the intent, and a call the intent does not match, or whose data the platform denies, is answered `403`. |

Everything about the chain itself is identical: the delegation token is exchanged on every hop, the admission policy compares the chain with the agent path of a workflow the subject may trigger, and the audit record carries `actorsChain`. Three refusals follow from the reference policy and look the same in both modes, `403` with `{"message": "Authorization check failed"}` and, in the audit record, the one reason `subject <type>/<id> may not reach <agent type>/<agent> through the delegation chain`; which of the three it was is read from `actorsChain` and the graph:

- **Skipping a hop.** A user sends their own token straight to the retriever's or the MCP server's gateway. The gateway exchanges it, the chain is `[retriever]` or `[mcp-agent]`, and unless a one-agent workflow with that shape exists, the policy finds no matching path. Modelling the direct shape as its own workflow is how you allow it deliberately. With a Token Service this case is already refused with `401`, since the user's token is not issued for that agent.
- **Reusing a token across workflows.** A delegation token minted for `[orchestrator, notifier]` is presented to the retriever's gateway. The exchange appends the retriever, and the chain `[orchestrator, notifier, retriever]` is the path of no workflow. A token therefore cannot be replayed from one workflow into another, even by an agent that is legitimately part of both.
- **Right chain, wrong user.** The chain is the path of a workflow, but no `CAN_TRIGGER` relationship links this subject to it. On a shared agent, two users with the same chain get their own answer, since the subject is always the user of the token.

The example that follows runs in a2a mode for both gateways; the [MCP tutorial](/tutorials/tutorial-agent-gateway-mcp) ends its chains at an MCP server and models the direct and the orchestrated shape as separate workflows.

# From zero to a first authorized call

The example protects one agent, the **retriever**, called by a user through the **orchestrator** agent: the workflow `wf1` is `user -> orchestrator -> retriever`. It is the shape the `a2a/` demos of the [developer-hub repository](https://github.com/indykite/developer-hub) run. Five steps, in the order they must happen.

## Step 1: Identity provider

The gateway works with any OAuth 2.0 provider that offers the three things below over HTTP Basic client authentication. Create one confidential client per agent, plus the client your users log in with.

| The provider must | Used for |
| --- | --- |
| Introspect tokens (RFC 7662) and report `active` and `sub` | Every incoming user or delegation token. |
| Issue a token to a client with the client credentials grant | The protected agent's own token. Its `sub` is what appears in the delegation chain, so note it: it must be the agent's `external_id` in the graph. |
| Exchange a subject token and an actor token for a delegation token (RFC 8693) whose `act.sub` is the actor, and nest the subject token's own `act` when it has one | Building the chain hop by hop. If your provider cannot nest, run the [Token Service](/guides/guide-token-service), which does the exchange instead; the provider then only needs the first two. |

For this example: client `indykiteagent` (orchestrator) and client `indykiteagent-2` (retriever), each with a secret, and a login client for the user `millicent`. The gateway also needs a [Token Introspect](/guides/guide-token-introspect) configuration in your IndyKite project for the tokens it receives in `Authorization`, since it resolves the user through `whoami`; its `ikg_node_type` is the subject type of the admission policy in step 3. One configuration covers one issuer and audience pair. The delegation tokens need a matching configuration too, in both modes: the gateway sends the delegation token to the platform in `X-IK-Token` on its admission call, and the platform reads it only through a matching configuration. When the provider issues them with the same issuer and audience as the user tokens, the configuration above covers both; create a second one only when the pair differs, since a duplicate pair is refused with `409`. Without a Token Service these are the exchanged tokens of the provider; with one, the Token Service's issuer and `token_service.audience`, which always need their own configuration. Created with Service Account credentials:

```json
POST /configs/v1/token-introspects
Authorization: Bearer <service-account-token>
{
  "project_id": "gid:AAAABbbbCCCC...",
  "name": "iag-user-tokens",
  "display_name": "IAG user tokens",
  "jwt_matcher": {
    "issuer": "<iss of the user tokens>",
    "audience": "<aud of the user tokens>"
  },
  "offline_validation": {},
  "ikg_node_type": "User"
}
```

The issuer must be an `https` URL on a public host. Check it with the user's token: `GET /contx-iq/v1/whoami` with `X-IK-ClientKey` and `Authorization: Bearer <millicent's token>` must answer `{"type": "User", "id": "millicent"}`.

## Step 2: Graph data

Four kinds of nodes and two kinds of relationships, loaded with the Capture API and AppAgent credentials (`X-IK-ClientKey`). The user is an identity node whose `external_id` is the `sub` of their token; each agent's `external_id` is the `sub` of its client-credentials token.

```json
POST /capture/v1/nodes
{
  "nodes": [
    {
      "external_id": "millicent",
      "type": "User",
      "is_identity": true,
      "properties": [
        {
          "type": "email",
          "value": "millicent@canbank.com"
        }
      ]
    },
    {
      "external_id": "wf1",
      "type": "Workflow"
    },
    {
      "external_id": "indykiteagent",
      "type": "Agent"
    },
    {
      "external_id": "indykiteagent-2",
      "type": "Agent"
    }
  ]
}
```

The workflow is a path of `INVOKES` relationships from the `Workflow` node through the agents in call order. Every relationship carries `workflow_name` equal to the workflow's `external_id`; that property is what keeps two workflows apart when they share agents. The user is linked to the workflow with the relationship the KBAC policy will match, here `CAN_TRIGGER`.

```json
POST /capture/v1/relationships
{
  "relationships": [
    {
      "source": {
        "type": "Workflow",
        "external_id": "wf1"
      },
      "target": {
        "type": "Agent",
        "external_id": "indykiteagent"
      },
      "type": "INVOKES",
      "properties": [
        {
          "type": "workflow_name",
          "value": "wf1"
        }
      ]
    },
    {
      "source": {
        "type": "Agent",
        "external_id": "indykiteagent"
      },
      "target": {
        "type": "Agent",
        "external_id": "indykiteagent-2"
      },
      "type": "INVOKES",
      "properties": [
        {
          "type": "workflow_name",
          "value": "wf1"
        }
      ]
    },
    {
      "source": {
        "type": "User",
        "external_id": "millicent"
      },
      "target": {
        "type": "Workflow",
        "external_id": "wf1"
      },
      "type": "CAN_TRIGGER"
    }
  ]
}
```

**One workflow per call shape.** A workflow holds exactly one agent list. If the same agent is reached by two paths, model two workflows (for example `wf3` for `user -> analyst` and `wf3-console` for `user -> orchestrator -> analyst`).

## Step 3: KBAC admission policy

One policy per subject type and agent type, with the action from `authzen.action` and the resource type of the protected agents, `Agent` here. The subject type is the `ikg_node_type` of the Token Introspect configuration from step 1. The condition does the whole check: the subject may trigger a workflow whose `INVOKES` path, agent by agent, equals the delegation chain the gateway sends as `$ik_token.act_chain`, and that path ends at the resource, the protected agent. One such policy serves every gateway whose agent has that type. Created with Service Account credentials:

```json
POST /configs/v1/authorization-policies
Authorization: Bearer <service-account-token>
{
  "project_id": "gid:AAAABbbbCCCC...",
  "name": "user-can-reach-agent",
  "display_name": "User can reach agent through a workflow",
  "policy": "{\"meta\":{\"policy_version\":\"2.0-kbac\"},\"subject\":{\"type\":\"User\"},\"actions\":[\"CAN_TRIGGER\"],\"resource\":{\"type\":\"Agent\"},\"condition\":{\"cypher\":\"MATCH (subject:User)-[:CAN_TRIGGER]->(wf:Workflow) MATCH (wf)-[rels:INVOKES*]->(resource:Agent) WHERE ALL(r IN rels WHERE r.workflow_name = wf.external_id AND endNode(r):Agent) AND [r IN rels | endNode(r).external_id] = $ik_token.act_chain\"}}",
  "status": "ACTIVE"
}
```

A request is admitted when the token's chain equals the agent path of a workflow the subject may trigger: `[indykiteagent, indykiteagent-2]` passes for `wf1` at the retriever's gateway; `[indykiteagent-2]` alone or `[indykiteagent, indykiteagent-3, indykiteagent-2]` does not. The policy matches the upstream hops by `external_id` among `Agent` nodes; to also require that each hop's type equals the node's, add `AND [r IN rels | endNode(r).type] = $ik_token.act_chain_types` as the [AuthZEN guide](/guides/guide-authzen#token-claims-in-cypher) shows, which needs every hop to carry `act.type`: the Token Service writes it, and a hop without one yields a `null` entry that equals no type. To restrict one gateway to some workflows, give it `authzen.input_params` such as `workflow_ids: ["wf1"]` and a tag in `authzen.policy_tags`, and add `AND wf.external_id IN $workflow_ids` to a copy of the policy that carries that tag.

Check it the way the gateway will, with the AppAgent credential and a delegation token whose chain is `[indykiteagent, indykiteagent-2]` in `X-IK-Token` (the platform needs the Token Introspect configuration for it from step 1):

```json
POST /access/v1/evaluation
X-IK-ClientKey: <app-agent-credential-token>
Authorization: Bearer <millicent's token>
X-IK-Token: <delegation token of the retriever hop>
{
  "subject": {
    "type": "User",
    "id": "millicent"
  },
  "action": {
    "name": "CAN_TRIGGER"
  },
  "resource": {
    "type": "Agent",
    "id": "indykiteagent-2"
  }
}
```

```json
{
  "decision": true
}
```

### Capability checks: what the caller may use

Admission decides whether the chain may reach the agent. With `authzen.capabilities.enabled` on, the default, a gateway in front of an MCP server also decides which tools, resources and prompts the caller may use on it, and a gateway in front of an A2A agent shows the caller only the skills they may use on the extended card. For each kind a request needs, the gateway reads the **permitted set** with one resource search, with the same headers and `context` as the admission call:

```json
POST /access/v1/search/resource
X-IK-ClientKey: <app-agent-credential-token>
X-IK-Token: <delegation token>
{
  "subject": { "type": "User", "id": "millicent" },
  "action": { "name": "CAN_USE" },
  "resource": { "type": "Tool" }
}
```

The identifiers in the answer are what the caller may use: tool names, resource URIs, prompt names, skill ids. Each capability is a node of the label configured for its kind (`Tool`, `McpResource`, `Prompt` and `Skill` by default) whose `external_id` is the identifier exactly as the protocol carries it, attached to its agent with a `HAS` relationship whose `workflow_name` confines it to one workflow:

```plain
(:Workflow)-[:INVOKES {workflow_name}]->(:Agent)-[:HAS {workflow_name}]->(:Tool {external_id})
(:Agent)-[:HAS {workflow_name}]->(:McpResource {external_id})
(:Agent)-[:HAS {workflow_name}]->(:Prompt {external_id})
(:Agent)-[:HAS {workflow_name}]->(:Skill {external_id})
```

For the retriever of this example, a skill `read-document` it may offer within `wf1` (a tool of an MCP server is modelled the same way, as a `Tool` node named after the tool):

```json
POST /capture/v1/nodes
X-IK-ClientKey: <app-agent-credential-token>
{
  "nodes": [
    {
      "external_id": "read-document",
      "type": "Skill"
    }
  ]
}
```

```json
POST /capture/v1/relationships
X-IK-ClientKey: <app-agent-credential-token>
{
  "relationships": [
    {
      "source": {
        "type": "Agent",
        "external_id": "indykiteagent-2"
      },
      "target": {
        "type": "Skill",
        "external_id": "read-document"
      },
      "type": "HAS",
      "properties": [
        {
          "type": "workflow_name",
          "value": "wf1"
        }
      ]
    }
  ]
}
```

One policy per label, with the action of `authzen.capabilities.action`. Its first half is the admission condition, so a non-empty set proves admission, and the last comparison keeps a capability attached for one workflow out of every other workflow that reaches the agent:

```json
POST /configs/v1/authorization-policies
Authorization: Bearer <service-account-token>
{
  "project_id": "gid:AAAABbbbCCCC...",
  "name": "user-can-use-skill",
  "display_name": "User can use a skill of an agent reached through a workflow",
  "policy": "{\"meta\":{\"policy_version\":\"2.0-kbac\"},\"subject\":{\"type\":\"User\"},\"actions\":[\"CAN_USE\"],\"resource\":{\"type\":\"Skill\"},\"condition\":{\"cypher\":\"MATCH (subject:User)-[:CAN_TRIGGER]->(wf:Workflow) MATCH (wf)-[rels:INVOKES*]->(agent:Agent)-[h:HAS]->(resource:Skill) WHERE ALL(r IN rels WHERE r.workflow_name = wf.external_id AND endNode(r):Agent) AND [r IN rels | endNode(r).external_id] = $ik_token.act_chain AND h.workflow_name = wf.external_id\"}}",
  "status": "ACTIVE"
}
```

- The same policy with `Tool`, `McpResource` or `Prompt` as the resource type serves the other kinds. Kinds that share one label share one search; the sets of different labels are never merged, so a tool and a prompt with the same name are two capabilities.
- A caller the platform admits nowhere matches no path, so the search finds nothing: an empty list on a discovery, `403` on an invocation. Not admitted, admitted with nothing permitted and nothing modelled look the same, by design; the audit record carries the permitted set.
- A deployment that models no capabilities switches the checks off with `authzen.capabilities.enabled: false` (`JARVIS_AUTHZEN_CAPABILITIES_ENABLED=false`); every request then gets the admission decision alone, as before the checks existed. With the checks on and nothing modelled, every list is empty, every invocation is refused, and the extended card lists no skill.

## Step 4: Configure and run the gateway

The smallest useful configuration for the retriever's gateway, with audit records written to a file. Secrets are shown as placeholders; the file is not environment-expanded, so either write the values in or set them through `JARVIS_` variables, which override the file (see [Configuration](#configuration)).

```yaml
service:
  name: retriever-iag
  port: 8888
  # public URL of this gateway, written into the agent card it serves
  base_url: https://retriever-iag.example.com
identity_provider:
  base_url: https://idp.example.com/oauth/v2/
  introspect_endpoint: oauth-introspect
  client_credential_endpoint: oauth-token
  exchange_endpoint: oauth-token
  # security scheme named in the served agent card
  openid_configuration_url: https://idp.example.com/.well-known/openid-configuration
protected_agent:
  base_url: http://retriever:6002
  protocol: a2a
  authentication:
    client_id: indykiteagent-2
    client_secret: <retriever client secret>
authzen:
  base_url: https://eu.api.indykite.com/access/v1
  action: CAN_TRIGGER
  # optional: restrict this gateway through a tagged copy of the admission policy
  # input_params:
  #   workflow_ids: ["wf1"]
  # policy_tags: ["pinned"]
contx_iq:
  base_url: https://eu.api.indykite.com/contx-iq/v1
  app_agent_credentials_token: <app agent credential token>
audit:
  delivery: file
  file:
    storage_path: /app/audit
    format: json
    rotation_strategy: size-and-time
```

```bash
docker run -d \
  --name retriever-iag \
  -p 8888:8888 \
  -v $(pwd)/config.yaml:/app/config.yaml:ro \
  -v $(pwd)/audit:/app/audit \
  indykite/agent-gateway:<version> \
  --config=/app/config.yaml
```

The audit directory must be writable by user 65532, the user the container runs as. The orchestrator gets its own gateway with `client_id: indykiteagent` and its own `base_url`; the orchestrator agent is configured to call the retriever through `retriever-iag`, not directly.

## Step 5: Test

A probe without a token proves the gateway is up and enforcing, and writes an audit record:

```bash
curl -i -X POST http://localhost:8888/ -H "Content-Type: application/json" -d '{}'
# HTTP/1.1 401 Unauthorized
# {"message":"Missing bearer token"}
```

A real call needs a delegation token whose chain is `[indykiteagent]`, the token the orchestrator receives from its own gateway. In the demos the orchestrator makes this call. To make it by hand, obtain a token for the user, exchange it at the provider with the orchestrator's client credentials as actor, and send the result:

```bash
curl -s -X POST http://localhost:8888/ \
  -H "Authorization: Bearer $DELEGATED_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "message/send",
  "params": {
    "message": {
      "role": "user",
      "messageId": "m-1",
      "parts": [
        {
          "kind": "text",
          "text": "Which policy documents pertain to refunds?"
        }
      ]
    }
  }
}'
```

On `200` the body is the retriever's JSON-RPC response. A user without the `CAN_TRIGGER` relationship, or a chain that is not `[indykiteagent]`, gets:

```json
{
  "message": "Authorization check failed"
}
```

The status alone does not say why. Read the audit record, whose `reason` does; it names the subject as `<type>/<id>`, while `subject` stays the token's `sub`:

```json
{
  "decision": "NOT_AUTHORIZED",
  "reason": "subject User/carol may not reach Agent/indykiteagent-2 through the delegation chain",
  "subject": "carol",
  "actor": "indykiteagent-2",
  "action": "noop",
  "service": "retriever-iag",
  "timestamp": "2026-09-30T09:12:00.123456789Z",
  "traceID": "4bf92f3577b34da6a3ce929d0e0e4736",
  "actorsChain": [
    "indykiteagent",
    "indykiteagent-2"
  ]
}
```

## Troubleshooting

| Symptom | Cause | Fix |
| --- | --- | --- |
| `401` `{"message":"Unauthorized","errors":["identity provider: the token is not active"]}` | The user or delegation token is expired or unknown to the provider. | Obtain a fresh token; check the provider's introspection endpoint in `identity_provider`. |
| `401` `Invalid token, missing act claim` | The exchange returned a token without `act`: the provider did not perform a delegation, or the token sent was not exchanged. | Confirm the provider's RFC 8693 support, or run the Token Service. |
| `403`, audit reason `subject <type>/<id> may not reach <agent type>/<agent> through the delegation chain` | The admission policy answered `false`. Either the chain (`actorsChain` in the record) is the `INVOKES` path of no workflow: the agents' `external_id` differ from the token subs, a hop is missing because the provider does not nest `act`, or the workflow shape is not ingested; or no `CAN_TRIGGER` relationship links the subject to that workflow, the subject node is missing or is not an identity node; or no ACTIVE policy exists for the subject type (the `ikg_node_type` of the Token Introspect configuration) and the agent type named in the reason; or the policy reads an `input_params` value this gateway does not send. | Replay the evaluation of step 3 by hand with the same subject, agent and `X-IK-Token`, then compare `actorsChain` with the workflow's path in the graph. |
| Every `tools/list` comes back empty, `tools/call` answers `403` with JSON-RPC `-31403` `Forbidden: the caller may not use the named tool`, or the extended card lists no skill | Capability checks are on (the default) and the caller's permitted set is empty: no `Tool`, `McpResource`, `Prompt` or `Skill` node is attached to the agent with a `HAS` relationship carrying the workflow name, no `CAN_USE` policy exists for the label, or the caller is admitted to no workflow that reaches the agent. The `DISCOVERY` or `INVOCATION` record shows the `permittedSet`. | Model the capabilities and create one policy per label ([Capability checks](#capability-checks-what-the-caller-may-use)), or set `authzen.capabilities.enabled: false` on that gateway. |
| An A2A message is refused with `403` `Authorization check failed` although admission is `AUTHORIZED`; the `INTENT` record says `none fits the skills of the agent` | `ibac.enabled` with a Token Service: no skill of the agent the caller may use covers any evaluation of the intent. Either the caller has no permitted skill on that agent (no `Skill` node attached with a `HAS` relationship for the workflow, or no `CAN_USE` policy for `Skill`), or the `x-coaz-mappings` of the permitted skills name other subject types, resource types or actions than the intent, or `ibac.capabilities.unmapped` is `deny` and the skills have no mapping. The `IBAC_DISCOVERY` record lists each evaluation with the skills it matched. | Model the skills of the agent and give them mappings that match the policies the intent uses; or switch capability checks off for that gateway (`authzen.capabilities.enabled: false`), so every skill on the agent's cards counts. |
| An MCP call answers `403` with `Forbidden: the named tool does not match the intent` (or `resource`, `prompt`) | `ibac.enabled` is on and the delegation token carries an intent: no evaluation of that intent matches a mapping of the capability by subject type, resource type and action, or the call lacks an argument a mapping reads. The `IBAC_USAGE` record has `reasonCode` `intent_mismatch`, and `currentIntent` shows the intent it was checked against. | Compare `currentIntent` with the `x-coaz-mappings` of the capability; send the argument the mapping reads; or correct the mapping on the server. |
| An MCP call answers `403` with `Forbidden: the caller may not access the data the named tool uses` | The intent matches, and the platform denied one of the evaluations resolved from the matched mappings: no KBAC policy lets this subject do that action on that resource, or `authzen.policy_tags` is set and the policy carries none of the tags. The `RESOLVED_EVALUATIONS` record lists each evaluation with `allowed`. | Read `resolvedEvaluations` in the record, then replay the denied one with `POST /access/v1/evaluations` and create or correct the policy. |
| Decision `ERROR` on a `DISCOVERY` or `INVOCATION` record; the caller gets the platform's status or `500` | The resource search for the permitted set failed. The error is kept for `authzen.cache_update_after_error`. | Check the AppAgent credential and the Token Introspect configuration for the delegation tokens, as for an admission `ERROR`. |
| The agent behind a later hop gets no `Authorization` header | `authorization_header.forward` is `correct_audience` (the default) and the bearer token of the hop is not issued for this agent, or it is `none`. | Issue the user's token for every agent that needs it in `Authorization`, or set `forward: all` on that gateway. |
| A browser client reports a CORS error, while the same request from `curl` works | The page's origin is not in `cors.allowed_origins` (empty by default), so the gateway sends no CORS headers on the MCP endpoint, the JSON-RPC paths or the extended card, and the browser refuses the answer. | Add the page's exact origin, `scheme://host[:port]`, to `cors.allowed_origins`. If the MCP server behind the gateway checks `Origin` itself, allow the same origin there. |
| Decision `ERROR`, reason `the delegated token names the protected agent <type>, protected_agent.node_type is <type>` | The token's `act.type` and the configured `protected_agent.node_type` differ, so the resource type of the admission call is ambiguous; every request is refused. | Remove `protected_agent.node_type`, or make it equal to the issuer's actor type (`idp.actor_type` of the Token Service). |
| `403`, audit reason `the delegation chain cannot be read` | A hop of the delegation token's `act` chain has no usable `sub`, or a `type` that is not a non-empty string. | Inspect the delegation token the exchange returns; check the issuer's `act` nesting. |
| `401` `{"message":"Unauthorized","errors":["ContX IQ whoami failed"]}`, audit reason `cannot resolve the subject of the access token` | No Token Introspect configuration in the project matches the issuer and audience of the token in `Authorization`, or the token fails its validation. | Call `GET /contx-iq/v1/whoami` by hand with the same token and add or fix the configuration (step 1). |
| Decision `ERROR`, reason `cannot authenticate protected agent` | The provider refused the client credentials grant. | Check `protected_agent.authentication` and the client at the provider. |
| Decision `ERROR`, reason `unable to evaluate the admission of subject <type>/<id>`, caller gets `401` or `403` with `["evaluating admission through AuthZEN failed"]` or `500` | AuthZEN could not be reached, refused the AppAgent credential, or could not read the delegation token in `X-IK-Token` because no Token Introspect configuration matches its issuer and audience. The error is cached for `authzen.cache_update_after_error`. | Check `app_agent_credentials_token`, its API permissions, the region base URL, and the Token Introspect configuration for the delegation tokens (step 1). |
| No audit records although `JARVIS_AUDIT_*` variables are set | The `audit` section must exist in a configuration file; environment variables only override its values. | Mount a file with at least `audit.delivery` and pass `--config`. |
| Gateway starts, webhook auth fails, or the async queue is 512 whatever you set | The webhook auth and queue keys are read under the compact names given in parentheses in the audit table below. | Write `apikey`, `apikeyheader`, `mtlscertificatepath`, `mtlsprivatekeypath`, `buffersize`. |

# Configuration

The gateway reads one YAML file passed with `--config=<file>`, or a directory of `.yaml`, `.yml`, `.json` or `.toml` files merged in alphabetical order with `--config-dir=<dir>`; the two flags are mutually exclusive. Rules that apply to every key:

- **Environment overrides.** Upper-case the key path, replace dots with underscores, prefix `JARVIS_`: `protected_agent.authentication.client_secret` is `JARVIS_PROTECTED_AGENT_AUTHENTICATION_CLIENT_SECRET`. A variable replaces the file value. `service.port` also honours `PORT`.
- **Lists** set from the environment are split on whitespace: `JARVIS_PROTECTED_AGENT_AUTHENTICATION_AUDIENCES="aud-1 aud-2"`.
- **No expansion.** `${VAR}` in the file is a literal string. Put secrets in the file or in `JARVIS_` variables.
- **The audit section is the one exception to "everything from the environment".** Audit is enabled by the presence of `audit` in a file; variables cannot create it, only override its values. Every other section works from variables alone.
- The gateway listens on plain HTTP. Terminate TLS in front of it. It calls the identity provider and the Token Service with HTTP Basic client authentication and a 10 second timeout, and the IndyKite APIs with a 10 second timeout.

## service

| Key | Default | Meaning |
| --- | --- | --- |
| `service.name` | `service` | Name of this instance, written to every audit record and audit file name. Set it; the default is the binary name. |
| `service.port` | `8888` | Listening port. |
| `service.base_url` |  | Public URL of the gateway, required in both modes. In `a2a` mode every interface URL in the agent cards the gateway serves is replaced with it, so callers never reach the agent directly. In `mcp` mode it is the full public URL of the MCP endpoint at the gateway, with its path and without a query, credentials or fragment, for example `https://agents.example.com/mcp/v1/gid:AAAA…`: the gateway serves MCP on that path only, and its OAuth protected resource metadata names it (see [OAuth discovery](#oauth-discovery)). Write the path unencoded, `gid:` and not `gid%3A`. It is a setting rather than the host of the request because, behind an ingress, the scheme and host of a request are not the public ones and the `Host` header is chosen by the caller. |
| `service.healthcheck_port` | `9080` | Port of `/healthz`, `/readyz` and `/startupz`, probed by the image's `HEALTHCHECK`. |
| `service.environment` |  | Free label such as `prod` or `demo`. |
| `service.log_level` | `info` | `debug`, `info`, `warn` or `error`; JSON logs on standard output. At `debug` the log shows the chain and the platform answers per request. |

## identity_provider (required)

| Key | Meaning |
| --- | --- |
| `identity_provider.base_url` | Provider base URL; the endpoints below are joined to it. |
| `identity_provider.issuer` | Required in `mcp` mode: the issuer identifier of the identity provider, exactly as it appears in its metadata and in the `iss` of its tokens, an absolute URL without a query or fragment, for example `https://idp.example.com/realms/main`. The gateway's protected resource metadata lists it in `authorization_servers`, and an MCP client builds the provider's metadata URL from it. |
| `identity_provider.introspect_endpoint` | Token introspection endpoint. |
| `identity_provider.client_credential_endpoint` | Token endpoint for the client credentials grant. |
| `identity_provider.client_credential_audience` | Optional: the `audience` parameter of the client credentials grant for the token of the protected agent, one value. Left out, the grant names no audience. Set it for an identity provider that refuses a grant without an audience; Auth0 does: use the identifier of an API registered there, and authorize the application of the agent for that API. The token is read by the service that does the token exchange, so with the IndyKite Token Service and a `jwt` matcher for actor tokens, the matcher must name the same audience. The token for the Intent Agent keeps `intent_agent.audience`. |
| `identity_provider.exchange_endpoint` | Token endpoint for the exchange grant, used when no Token Service is configured. Usually the same endpoint. |
| `identity_provider.client_credential_renew_before` | Optional, default `10s`: how long before its expiry a kept client credentials token is renewed, leaving time for the token to reach its recipient and for a clock difference. `0` takes the default; a negative value is refused at startup. |
| `identity_provider.openid_configuration_url` | OpenID Connect discovery URL of the identity provider, required in `a2a` mode: the security scheme the served agent cards name, where callers obtain their token. |

## token_service (optional)

When present, the issuer it names mints the delegation token, the IndyKite Token Service or an identity provider that meets the requirements below, and the gateway forwards it in `X-IK-Token` beside the caller's `Authorization`. A workflow then starts only at the agent the user's token was issued for, and a later hop needs only its `X-IK-Token`. All keys below except `audience` are then required; `identity_provider` stays required for introspection and the actor token, and `protected_agent.authentication.audiences` becomes required.

| Key | Meaning |
| --- | --- |
| `token_service.base_url` | Where the gateway reaches the issuer, e.g. `http://token-service:8102`. |
| `token_service.exchange_endpoint`, `introspect_endpoint` | `oauth2/token` and `oauth2/introspect` for the IndyKite Token Service. |
| `token_service.audience` | Optional: the audience asked for in every exchange, so the audience of every delegation token; `protected_agent.authentication.audiences` when left out. The delegation token travels on to the next gateway, so every gateway of a deployment should ask for the same one, and the Token Service must list it in its `idp.audiences`; a value it does not list is refused with `invalid_target`. The Token Introspect configuration that lets the platform resolve delegation tokens names this audience. |
| `token_service.client_auth.type` | Only `client_secret_basic`. |
| `token_service.client_auth.client_id`, `client_secret` | The credentials the issuer expects from gateways (for the IndyKite Token Service, its own `idp.client_auth`), not the identity provider credentials. |

An identity provider named here instead of the IndyKite Token Service has to support the RFC 8693 exchange with the user's access token as `subject_token` and the protected agent's client credentials token as `actor_token`; take its own delegated token as `subject_token` on a later hop and nest the previous `act` in the new one; keep the `sub` of the subject token and write the actor as `act.sub`; and answer RFC 7662 introspection of the tokens it issued with their `act` claim, since a later hop refuses an `X-IK-Token` without one. Two features depend on what it writes into `act`, both of which the IndyKite Token Service writes: `act.type` on every level, without which the platform looks each actor up by `external_id` alone, which then has to be unique, and `$ik_token.act_chain_types` holds `null` for each hop without a type, so a comparison of that list with a fully typed graph path denies; and `act.intent`, the intent of the hop. Without `token_service`, the identity provider's own exchange at `identity_provider.exchange_endpoint` is used. The gateway still sends the delegation token it minted in `X-IK-Token` on its admission call, so the admission policy reads the chain as `$ik_token.act_chain` in both modes. What changes is the forwarded request: the delegation token replaces the subject token in `Authorization`, so when the protected agent calls the platform with it, the agent's own policies read it as `$token`. The entry-agent rule, the later hop without `Authorization` and the `same_user_check` apply only with `token_service`.

## protected_agent (required)

| Key | Meaning |
| --- | --- |
| `protected_agent.base_url` | In `a2a` mode, where the agent card is read; requests go to the JSON-RPC URL the card declares. In `mcp` mode, the full URL of the MCP endpoint of the server, with its path, unencoded, without a fragment, and with its query when the server needs one, for example `http://mcp-server:8080/mcp/v1/gid:AAAA…`. Every request the gateway accepts goes to this URL, with the request's query appended after the configured one; the request path is not used to build it. Its path may differ from the path of `service.base_url`. |
| `protected_agent.protocol` | `a2a` (default) or `mcp`. |
| `protected_agent.node_type` | Optional, no default: the IKG node type of the protected agent, the resource type of the admission evaluation, used only when the delegation token of this hop carries no `act.type`. Without either, the type is `Agent`. When the token has `act.type` (the IndyKite Token Service writes its `idp.actor_type`, `Agent` by default), that type is used; when it differs from this setting, every request is refused with an `ERROR` record naming both. |
| `protected_agent.authentication.client_id`, `client_secret` | The protected agent's client at the identity provider, used for the client credentials grant. |
| `protected_agent.authentication.audiences` | Without `token_service`: optional list sent as `audience` on the exchange at the identity provider. With `token_service`: required, the audiences of user tokens this gateway accepts in `Authorization` as the start of a workflow (a token issued for none of them is refused with `401`), and the audiences asked for in the exchange unless `token_service.audience` is set. Each exchange audience must be in the Token Service's `idp.audiences`, otherwise the exchange is refused with `invalid_target`. From the environment, a space-separated list. |

## a2a (optional)

| Key | Default | Meaning |
| --- | --- | --- |
| `a2a.cache_ttl` | `5m` | How long the protected agent's card, and the client built from it, are kept. |
| `a2a.cache_update_after` | `cache_ttl` | Age after which the card is fetched again. Must not exceed `cache_ttl`. |
| `a2a.cache_update_after_error` | `10s` | How long a failed card fetch is returned to every call before the next attempt. Must not exceed `cache_update_after`. |

## authorization_header (optional, with token_service)

| Key | Default | Meaning |
| --- | --- | --- |
| `authorization_header.forward` | `correct_audience` | What the protected agent gets in `Authorization`; the delegation token goes in `X-IK-Token` with every value. `none`: nothing, so the agent cannot use the user's token to start a new workflow as the user. `correct_audience`: a bearer token only when the identity provider reports it active and its `aud` names one of `protected_agent.authentication.audiences`; a credential that is not a bearer token passes unchanged; any other bearer token is dropped and the request goes on; when the identity provider fails or answers `429` the request fails, since the gateway cannot tell whom the token is for. At the entry the user's token is always issued for this agent, so it is passed on. `all`: `Authorization` exactly as the caller sent it. |
| `authorization_header.same_user_check` | `true` | On a later hop, refuse a bearer token in `Authorization` whose `sub` differs from that of the delegation token. It checks only a token the gateway passes on, so never with `forward: none`. Switch it off for a flow whose `Authorization` does not carry the user's token, such as the service token of the calling agent: the gateway then reads that token only to decide whether `correct_audience` passes it on, and is responsible for the delegation token alone. |

A later hop whose bearer token is not passed on, or not checked, has no user's token: `whoami` and the admission call get the delegation token. With a Token Service the other headers of the caller are passed on to the agent, in both modes, except the headers of one connection (`Connection` and the headers it names, `Keep-Alive`, `Proxy-Authorization` and the like). Without one, an A2A agent gets no header of the caller, and an MCP server gets all of them except `Authorization`, `X-IK-Token` and `Accept-Encoding`.

## cors (optional)

| Key | Default | Meaning |
| --- | --- | --- |
| `cors.allowed_origins` | empty | The origins a browser may call the gateway's token-protected paths from: the MCP endpoint in `mcp` mode, the JSON-RPC paths and the extended agent card in `a2a` mode. Each entry is an origin, `scheme://host[:port]`, without a path, query, fragment or credentials, for example `https://mcp-client.example.com`; the single entry `*` allows every origin. Empty, no origin is allowed. Origins are compared exactly, with the scheme and host lower-cased and the default port dropped. From the environment, `JARVIS_CORS_ALLOWED_ORIGINS` as a space-separated list. The public paths (OAuth metadata, public agent card) allow every origin whatever this setting says; see [CORS](#cors). |

## ibac and intent_agent (optional)

With `ibac.enabled` on, a gateway in front of an A2A agent asks the [Intent Agent](/guides/guide-intent-agent#gateway) about every A2A message before forwarding it, and a gateway in front of an MCP server checks the mappings of invocations whose delegation token carries an intent, as described in [How a request is decided](#how-a-request-is-decided). Off, neither happens, and the `intent_agent` and `ibac.capabilities` settings are not read. The [IBAC engine guide](/guides/guide-ibac) covers the model behind the switch.

| Key | Default | Meaning |
| --- | --- | --- |
| `ibac.enabled` | `false` | Switches IBAC on: the Intent Agent call in front of an A2A agent and, with `token_service`, the comparison of the intent of a message with the skills of the agent; the mapping check of invocations and the intent filter of the lists in front of an MCP server; and, in front of an A2A agent, the filtering of the extended agent card to the skills that fit the current intent of the delegation token: of the permitted skills with capability checks on, of every skill of the agent with them off. On, in front of an A2A agent, `intent_agent.base_url` is required. |
| `ibac.capabilities.cache_ttl` | `5m` | In front of an MCP server: how long the gateway keeps a tool, resource or prompt, with its mappings, after the server last listed it. A list adds and refreshes entries and removes none, since a list can be one page of several. In front of an A2A agent: how long the gateway keeps the skills of the card the agent publishes and of the extended card, with their mappings, the same way; for a skill on both cards, the entry of the published card counts. Must be positive. |
| `ibac.capabilities.unmapped` | `allow` | In front of an MCP server: what happens to the call of a capability without a mapping, when the delegation token carries an intent. `allow`: the call goes on and only the permitted set decides. `deny`: the call is refused with `403`. A mapping that cannot be read refuses the call in both settings. The setting applies to the lists of the server too: with `allow` an entry without a mapping stays in a list, with `deny` it is removed. In front of an A2A agent it applies to the skills, on the extended card and in the comparison of a message with the skills: with `allow` a skill without a mapping fits every intent, so it stays on the card and covers every evaluation of a message, with `deny` it fits none. A message does not name the skill it uses, so under `allow` one permitted skill without a mapping lets the whole intent through, whatever the mappings of the other skills: give every skill a mapping, or set `deny`. |
| `intent_agent.base_url` |  | Where the Intent Agent serves its agent card; an absolute `http` or `https` URL. |
| `intent_agent.audience` | `intent_agent` | Audience of the client credentials token the gateway gets for the Intent Agent; must match the Intent Agent's `EXPECTED_TOKEN_AUDIENCE`. |
| `intent_agent.timeout` | `45s` | How long one prompt may take, the token grant included; longer answers `504`. Must be positive. |
| `audit.include_prompt` | `false` | Adds the prompt, the reason of a failed task, and the text the model answered with in place of an intent, to the `INTENT` audit records. Off, those records carry none of them, since all three can quote the user. |

## authzen (required)

| Key | Default | Meaning |
| --- | --- | --- |
| `authzen.base_url` |  | AuthZEN API of your region, e.g. `https://eu.api.indykite.com/access/v1`. |
| `authzen.action` |  | The action of the admission evaluation, the one the admission policy lists, e.g. `CAN_TRIGGER`. |
| `authzen.input_params` |  | Optional map sent as `context.input_params` in every admission call; a policy reads a value as `$name`, and the platform refuses a request that lacks a value the policy reads. A key has 2 to 20 lowercase letters, digits or `_` and starts with a letter; a text value has 1 to 256 bytes; the keys the platform fills are refused: `token`, `ik_token`, `subject_external_id`, `subject_id`, `subject_type`, `resource_external_id`, `resource_type`. From the environment, the whole map as JSON in `JARVIS_AUTHZEN_INPUT_PARAMS`. |
| `authzen.policy_tags` |  | Optional list sent as `context.policy_tags` in every admission call, so that only policies carrying at least one of the tags apply. A tag has 1 to 20 letters or digits, listed once. From the environment, space-separated. When a project uses tags, every gateway of the project should send them: a call without tags also reaches the tagged policies and their required parameters. |
| `authzen.subject_types` |  | Not read: the subject type comes from `whoami`. A value left over from an older configuration is ignored. |
| `authzen.cache_ttl` | `5m` | How long an admission decision is kept, per subject, resource type, chain and token claims, and how long a permitted set is kept, per subject, action, label, chain and token claims; an empty set too. Also how long the platform's answers to the resolved evaluations of an MCP call are kept, per subject, chain, evaluations and token claims; a denial and a failed call too. |
| `authzen.cache_update_after` | `cache_ttl` | Age after which a decision or a set is refreshed in the background by the next request that uses it; the last good value keeps being served for up to 12 hours while the platform is unreachable. With the default it coincides with expiry, so a value is read again only once it expired. Must not exceed `cache_ttl`. |
| `authzen.cache_update_after_error` | smaller of `10s` and `cache_update_after` | How long a failed evaluation or a failed search is served before a retry. Must not exceed `cache_update_after`. |
| `authzen.capabilities.enabled` | `true` | The [capability checks](#capability-checks-what-the-caller-may-use): the permitted set of the caller in front of an MCP server, and the filtering of the extended card in front of an A2A agent. Off, the gateway asks no capability question and every request gets the admission decision. `JARVIS_AUTHZEN_CAPABILITIES_ENABLED`. |
| `authzen.capabilities.action` | `CAN_USE` | The action of every capability search, the one the capability policies list. An empty value stops the gateway at startup. `JARVIS_AUTHZEN_CAPABILITIES_ACTION`. |
| `authzen.capabilities.labels.tools`, `resources`, `prompts`, `skills` | `Tool`, `McpResource`, `Prompt`, `Skill` | The IKG node types of the capabilities of each kind, the resource type of the search for that kind. Two kinds may share a label and then share one search; a label set to an empty value stops the gateway at startup. `JARVIS_AUTHZEN_CAPABILITIES_LABELS_TOOLS` and so on. |

## contx_iq (required)

| Key | Meaning |
| --- | --- |
| `contx_iq.base_url` | ContX IQ API of your region, e.g. `https://eu.api.indykite.com/contx-iq/v1`. |
| `contx_iq.app_agent_credentials_token` | The Application Agent credential token, sent as `X-IK-ClientKey` to ContX IQ `whoami` and to AuthZEN. |
| `contx_iq.cache_ttl` | Default `5m`: how long a `whoami` answer is kept, `0` keeps none. |
| `contx_iq.cache_update_after`, `cache_update_after_error` | Still checked at startup with the same ordering rules as under `authzen`, but without effect: a `whoami` answer is kept for `cache_ttl`. |
| `contx_iq.query_id`, `contx_iq.allowed_workflow_id` | No longer used: the gateway runs no Knowledge Query. `query_id` is ignored; a non-empty `allowed_workflow_id` stops the gateway at startup. Restrict a gateway through the admission policy with `authzen.input_params` and `authzen.policy_tags` instead. |

## audit (optional, file only)

Without an `audit` section nothing is recorded. With one, records are always delivered through a background queue so requests never wait for the sink; a full queue drops records with the log line `dropping payload, async queue is full`, and the queue is drained on shutdown. The five webhook authentication and queue keys are documented with their snake_case names; the compact name in parentheses is the one the current releases read.

| Key | Meaning |
| --- | --- |
| `audit.delivery` | `file` or `webhook`; the matching sub-section is required. |
| `audit.file.storage_path` | Directory for the files, named `audit-<service.name>-...`. Must be writable by user 65532. |
| `audit.file.format` | `json`, `csv` or `txt`. |
| `audit.file.rotation_strategy` | `time`, `size` or `size-and-time`. Required. |
| `audit.file.rotation_interval`, `rotation_max_bytes` | Defaults `24h` and `104857600` (100 MiB). |
| `audit.http.url`, `audit.http.method` | Webhook destination; method `POST` or `PUT`. Records are sent as JSON. |
| `audit.http.auth.type` | `no-auth`, `api-key` or `mTLS`. |
| `audit.http.auth.api_key` (`apikey`), `api_key_header` (`apikeyheader`) | For `api-key`; the header defaults to `X-API-Key`. |
| `audit.http.auth.mtls_certificate_file_path` (`mtlscertificatepath`), `mtls_private_key_path` (`mtlsprivatekeypath`) | For `mTLS`; both required. |
| `audit.async.buffer_size` (`buffersize`) | Queue length, default `512`. |
| `audit.include_prompt` | Default `false`: whether the `INTENT` records carry the prompt, the reason of a failed task and the text the model answered with in place of an intent, see [ibac and intent_agent](#ibac-and-intent_agent-optional). |

## Startup errors

A configuration problem stops the process with one of these messages in the log.

| Message | Cause |
| --- | --- |
| `invalid identity_provider configuration: missing <key>`, `invalid identity_provider configuration: client_credential_renew_before must not be negative` | One of the four identity provider keys is absent, or the renewal margin is negative. |
| `missing authentication.audiences in protected_agent configuration`, `invalid authorization_header.same_user_check: …`, `invalid authorization_header.forward "…", must be one of none, correct_audience, all` | With `token_service`, the entry audiences are absent, `same_user_check` is not a boolean, or `forward` is none of the three values. |
| `intent_agent.base_url is required when ibac.enabled is on in front of an A2A agent`, `intent_agent.base_url must be an absolute http or https URL`, `intent_agent.timeout must be positive` | Incomplete `intent_agent` section with `ibac.enabled` on. |
| `ibac.capabilities.cache_ttl must be positive, got …`, `ibac.capabilities.unmapped must be allow or deny, got "…"` | An invalid value in the `ibac.capabilities` section. |
| `invalid token_service configuration: missing <key>`, `client_auth of type "client_secret_basic" requires client_id and client_secret`, `client_auth has invalid type "…" (want "client_secret_basic")` | Incomplete Token Service section. |
| `cannot get protected_agent base_url`, `invalid protected_agent protocol`, `missing client_id in protected_agent configuration`, `missing client_secret in protected_agent configuration` | Incomplete protected agent section. |
| `cannot get service base_url, the public URL of the gateway`, `service base_url must be an absolute URL`, `cannot get identity_provider openid_configuration_url` | In `a2a` mode, the settings the served agent card needs are absent. |
| `protected_agent base_url must be the full URL of the MCP endpoint of the server, with its path, unencoded, and without a fragment`, `cannot get service base_url, the public URL of the MCP endpoint at the gateway`, `service base_url must be the full public URL of the MCP endpoint at the gateway, http or https, with its path, unencoded, and without credentials, a query or fragment`, `cannot get identity_provider issuer`, `identity_provider issuer must be an absolute URL without a query or fragment` | In `mcp` mode, one of the three endpoint settings is absent or malformed, for example a `protected_agent.base_url` without a path or a percent-encoded `gid%3A`. |
| `missing required authzen.base_url`, `missing required authzen.action` | Incomplete AuthZEN section. An empty `authzen.capabilities.action` or an empty `authzen.capabilities.labels.*` value stops the gateway as well. |
| `missing required contx_iq.base_url`, `missing required contx_iq.app_agent_credentials_token in configuration` | Incomplete ContX IQ section. |
| `contx_iq.allowed_workflow_id is no longer supported: restrict the workflows in the admission policy and pass the values with authzen.input_params and authzen.policy_tags` | A configuration from before the admission policy still restricts the gateway to one workflow. |
| `authzen.input_params must be a map: …`, `authzen.input_params: the key "…" is reserved, the platform fills it`, `authzen.input_params: the key "…" must have 2 to 20 lowercase letters, digits or underscores and start with a lowercase letter`, `authzen.input_params: the value of "…" must have 1 to 256 bytes`, `authzen.policy_tags: the tag "…" must have 1 to 20 letters or digits`, `authzen.policy_tags: the tag "…" is listed twice` | An `input_params` or `policy_tags` value the platform would refuse, including invalid JSON in `JARVIS_AUTHZEN_INPUT_PARAMS`. |
| `<section>.cache_ttl must not be negative, got …`, `<section>.cache_update_after (…) must not exceed <section>.cache_ttl (…)`, `<section>.cache_update_after_error (…) must not exceed <section>.cache_update_after (…)` | Cache durations out of order, for `authzen`, `contx_iq` or `a2a`. |
| `cors.allowed_origins: invalid origin "…", it must be scheme://host[:port] without a path, query, fragment or credentials`, `cors.allowed_origins: "*" must be the only entry` | An entry of `cors.allowed_origins` is not an origin (including `null`), or `*` is listed beside other origins. |
| `invalid port value … - not in range` | `service.port` or `service.healthcheck_port` is not a valid TCP port. |
| `audit: unknown delivery type "…", must be one of: file, webhook`, `audit: http url is required`, `audit: http method must be POST or PUT, got "…"`, `audit: unsupported auth type "…"`, `audit: api-key auth requires api_key`, `audit: mTLS requires mtls_certificate_file_path and mtls_private_key_path`, `audit: file storage path is required`, `audit: file rotation is required and must be one of "time", "size", "size-and-time"` | Incomplete audit section. The two auth messages name the keys in their snake_case form, but the values are read from `apikey`, `mtlscertificatepath` and `mtlsprivatekeypath`. |

# Deployment

The gateway ships as the Docker image `indykite/agent-gateway`: built from scratch with no shell, entrypoint `/app/service` so container arguments are the gateway flags, running as user `65532`, published for `linux/amd64` (add `platform: linux/amd64` on Apple Silicon), with a `HEALTHCHECK` on `http://localhost:9080/healthz` every 10 seconds after a 30 second start period.

- **Pin a version tag** from the [tag list](https://hub.docker.com/r/indykite/agent-gateway/tags). A `latest` tag exists but lags weeks behind the newest release, so it silently gives an old image. The IndyKite demos pin the release they were built against. Run the Token Service on the same tag ([Token Service guide](/guides/guide-token-service#release-pairing)). This guide describes the newest release; an older image may lack a behaviour described here, so when something documented does not happen, move to a newer tag before looking elsewhere.
- **Moving from the workflow query to the admission policy.** A deployment set up when the gateway still ran a ContX IQ Knowledge Query and an AuthZEN resource search needs, in this order: first, create the [admission policy](#step-3-kbac-admission-policy) (without it the new gateway refuses every request) and a Token Introspect configuration for the issuer and audience of the delegation tokens of every gateway, also without a Token Service; both are harmless to the old gateway. With the upgrade, remove any `contx_iq.allowed_workflow_id`, which stops the new gateway, and express the restriction with `authzen.input_params` and `authzen.policy_tags`. After the upgrade, remove `contx_iq.query_id`, which the new gateway ignores but the old one required, and delete the old `Workflow` trigger policy, the ContX IQ policy and the Knowledge Query it named.
- **Capability checks are on by default.** A gateway in front of an MCP server, or in front of an A2A agent with an extended card, needs one of two things: the capabilities of the server and the skills of the agent modelled in the graph with one `CAN_USE` policy per label ([Capability checks](#capability-checks-what-the-caller-may-use)), or `authzen.capabilities.enabled: false` on that gateway. With the checks on and nothing modelled, every list comes back empty, every invocation is refused and the extended card lists no skill. With the checks on, a caller the platform admits nowhere gets an empty list on `tools/list` and `403` with a JSON-RPC error on `tools/call`. With the checks on or off, a `prompts/get` without a prompt name is refused with `400`.
- **JSON-RPC codes of a refused caller.** A gateway in front of an A2A agent answers `-31401` (unauthenticated) and `-31403` (unauthorized) in a stream when the agent refuses the caller, codes outside the ranges the A2A specification and the MCP SDK assign, and a gateway in front of an MCP server refuses an invocation outside the permitted set with `-31403` too. A client built against an older image may still read `-32003` for these cases and needs to read both.
- **Docker Compose.** One pattern for several agents is a base service with the shared `JARVIS_` variables (identity provider, IndyKite URLs, credential token, action), extended once per gateway with `JARVIS_SERVICE_NAME`, `JARVIS_PROTECTED_AGENT_BASE_URL`, the agent's client id and secret, and, to restrict a gateway to some workflows, `JARVIS_AUTHZEN_INPUT_PARAMS` and `JARVIS_AUTHZEN_POLICY_TAGS`. Mount a small file with the `audit` section and pass `--config`, since audit cannot be enabled from variables. Complete stacks, with a Token Service and MCP-protecting gateways, are in the `a2a/` folder of the [developer-hub repository](https://github.com/indykite/developer-hub).
- **Kubernetes.** A plain `Deployment`; no Helm chart is published. Mount the configuration file from a `Secret` at `/app/config.yaml`, or keep it in a `ConfigMap` with the secrets in `JARVIS_` variables from a `Secret`. Run as a standalone Pod with its own `Service`, or as a sidecar in the agent's Pod with `protected_agent.base_url` set to `http://127.0.0.1:<port>` and only the gateway port exposed. Probes: `/startupz`, `/readyz`, `/healthz` on port `9080`; `runAsUser: 65532`; a writable volume for file audit; egress to the identity provider, the IndyKite region, the protected agent and the audit webhook.

# HTTP behaviour

## a2a mode

- JSON-RPC is accepted on any path and any method. Supported methods: `message/send`, `message/stream`, `tasks/get`, `tasks/list`, `tasks/cancel`, `tasks/resubscribe`, the four `tasks/pushNotificationConfig/*` methods and `agent/getAuthenticatedExtendedCard`.
- The gateway serves the agent card at `GET /.well-known/agent-card.json`: it is the card of the protected agent reduced to its JSON-RPC interfaces, each pointing at `service.base_url`, with the security scheme of the gateway's identity provider (`identity_provider.openid_configuration_url`) in place of the agent's on the card and on each skill, and without the agent's signatures. Without an `Authorization` header the answer is the public card, with no skills and `capabilities.extendedAgentCard` set; with a bearer token it is the extended card, after the same authentication and authorization as any other request. With an `Authorization` header the gateway would refuse with `401` or `403`, the answer is the public card as well: a header without a bearer token, a token that is not valid or not issued for this agent, a delegation token that cannot be used, or a caller that is not authorized. The refusal is audited as for any other request. A check that fails, such as an identity provider that does not answer, keeps its error. `agent/getAuthenticatedExtendedCard` answers with the same extended card; an agent that has no extended card answers with its own card. With capability checks on, the extended card lists only the skills the caller may use; when the permitted set cannot be read, the answer is an error and no card. With `ibac.enabled` and an intent in the delegation token, the card lists only the skills that fit the current intent, by their `x-coaz-mappings` and `ibac.capabilities.unmapped`: of the permitted skills with capability checks on, of every skill of the agent with them off; when the skills cannot be read with their mappings, the answer is an error and no card. Without an intent in the token the card is filtered to the permitted set only, or with capability checks off lists every skill. With a Token Service, both cards declare the delegated token extension in `capabilities.extensions`, with the identifier `https://indykite.com/extensions/delegated-token/v1` (a name, not a page) and `required: false`, in place of any declaration of that identifier the agent wrote, so a caller knows it may send its `X-IK-Token` to the agent. Both `service.base_url` and `identity_provider.openid_configuration_url` are required in `a2a` mode for this reason.
- The gateway reads the agent card from `protected_agent.base_url` and calls the card's interface URLs with the scheme and host of that base URL, keeping only their path and query, so a card cannot send requests to another host. A card that lists a null supported interface, or an interface without a URL, cannot be used: the request fails with `502`. A redirect from the agent is followed only while it stays on the host, port and scheme of `base_url`, or upgrades `http` to `https` on port 443, and for at most 5 hops; any other redirect fails the request with `502`.
- `message/stream` and `tasks/resubscribe` answer `200` with `text/event-stream` before the agent is contacted; an unreachable agent or a later failure arrives as a JSON-RPC error frame inside the stream; an agent that refuses the caller is reported there as `-31401` (unauthenticated) or `-31403` (unauthorized), and the A2A specification maps the other errors.

## mcp mode

![An MCP request in the Agent Gateway. Every request passes three gates. Path: only the path of service.base_url is served, any other path answers 404 before the token is read. Token: a missing or inactive bearer token answers 401 with a WWW-Authenticate challenge that links the protected resource metadata. Protocol: the request must be one JSON-RPC message on a supported protocol revision and name what it uses, otherwise a JSON-RPC error with 400, 413 or 415. Then it depends on the kind of request. A list, tools/list, resources/list or prompts/list, is filtered to the permitted set of the caller and, with ibac.enabled and an intent in the token, to the entries that fit the intent; nothing is refused and a list can come back empty. A call, tools/call, resources/read or prompts/get, must name a capability in the permitted set, otherwise 403 with the JSON-RPC error -31403; with ibac.enabled and an intent, it must also fit the intent by its mapping, and the platform must allow the resolved evaluations, otherwise 403. Any other request, such as initialize or a notification, gets the admission decision, one AuthZEN evaluation, and a denial answers 403. What passes is forwarded to the MCP server at protected_agent.base_url with the delegation token; Mcp-Session-Id and streamed responses pass through unchanged.](/assets/images/iag-mcp-request.svg)

The picture is the overview of an MCP request: three gates, then what a list, a call or any other request gets. The paragraphs and the table below have the exact rules, codes and messages.

The gateway serves MCP on one path, the path of `service.base_url`, compared with the request path exactly, trailing slash included and after percent-decoding, so a client that writes `gid%3A` still matches. Any other path is answered `404` with `{"message":"Not Found"}` before the token is read, except the two metadata paths of [OAuth discovery](#oauth-discovery); the MCP server's own paths beyond its endpoint, its metadata included, are not reachable through the gateway. Any MCP method on that path is forwarded after the checks pass, to the endpoint URL in `protected_agent.base_url` with the request's query appended, with `Mcp-Session-Id` and the response body passed through unchanged, streamed for SSE. The downstream server's status is returned as is, for example `202` for a notification or `404` for an unknown session. Requests must be on protocol revision `2025-06-18`, `2025-11-25` or `2026-07-28`; the checks run after introspection and before authorization, in this order:

| Refusal | Status, JSON-RPC code, message |
| --- | --- |
| `Content-Encoding` other than `identity` | `415`, `-32600`, `Invalid Request: content coding <coding> is not supported` |
| Body cannot be read | `400`, `-32700`, `Parse error: cannot read the request body` |
| Body over 4 MiB | `413`, `-32600`, `Invalid Request: request body exceeds 4194304 bytes` |
| `Mcp-Protocol-Version` present with an unsupported value, including on `initialize` | `400`, `-32022`, `Unsupported protocol version`, with `error.data.supported` and `error.data.requested` |
| Header absent on any request other than `initialize`: GET for SSE, DELETE, notifications and client responses included | `400`, `-32020`, `Header mismatch: Mcp-Protocol-Version header is missing` |
| JSON-RPC batch | `400`, `-32600`, `Invalid Request: JSON-RPC batching is not supported` |
| Body that is not valid UTF-8 | `400`, `-32700`, `Parse error: the request body is not valid UTF-8` |
| Body that is not exactly one JSON value: invalid JSON, two messages in one body, or text after the message | `400`, `-32700`, `Parse error: the request body is not one JSON value` |
| JSON that is not a JSON-RPC 2.0 message: no `"jsonrpc": "2.0"`, or neither a `method` nor a `result` or `error` | `400`, `-32600`, `Invalid Request: the request body is not a JSON-RPC message` |
| A key that can be read in more than one way, in the message itself, in the `params` of an invocation, or in `params.notifications` of a `subscriptions/listen`: a repeated key, a key that is not printable ASCII, or a key that differs from a field the gateway reads (`jsonrpc`, `method`, `params`, `name`, `uri`, `notifications`, `resourceSubscriptions`) only in letter case or in `_` and `-` characters | `400`, `-32600`, `Invalid Request: <object> has a repeated key`, `Invalid Request: <object> has a key that is not printable ASCII` or `Invalid Request: <object> has a key that can be read as <field>`, where `<object>` is `the message`, `params` or `params.notifications` |
| A method, tool name, prompt name or resource URI that contains a control character, a lone surrogate or the replacement character `U+FFFD` | `400`, `-32600`, `Invalid Request: the method contains a control character` or `Invalid Request: the method contains a lone surrogate or a replacement character`; the same two messages with `the tool name`, `the prompt name` and `the resource URI` |
| An invocation that names nothing: `tools/call` whose `params.name` is missing, empty or not a string; `prompts/get` with such a `params.name`; `resources/read` or `resources/subscribe` with such a `params.uri`; `subscriptions/listen` whose `params.notifications.resourceSubscriptions` cannot be read | `400`, `-32602`, `Invalid params: tools/call names no tool`, `Invalid params: prompts/get names no prompt`, `Invalid params: <method> names no resource URI` or `Invalid params: the resource subscriptions of subscriptions/listen cannot be read` |
| On revision `2026-07-28`: an `Mcp-Method` header that differs from the `method` in the body, or an `Mcp-Name` header that differs from the tool name of a `tools/call`, the prompt name of a `prompts/get` or the resource URI of a `resources/read`. A value in the form `=?base64?…?=` is decoded before the comparison, and one that does not decode is refused the same way. A missing header is left to the server. | `400`, `-32020`, `Header mismatch: Mcp-Method header does not match the method in the body`, `Header mismatch: Mcp-Name header does not match the tool name in the body` (or `the prompt name`, `the resource URI`), `Header mismatch: Mcp-Name header is not valid Base64` |

An `initialize` without the header is forwarded; if its `protocolVersion` is unsupported it is rewritten to `2025-11-25`. After the revision checks (the first six rows), the gateway reads what each request names: `tools/call` names a tool and `prompts/get` a prompt in `params.name`; `resources/read` and `resources/subscribe` name a resource in `params.uri`; `subscriptions/listen` names every URI in `params.notifications.resourceSubscriptions`; `tools/list`, `resources/list` and `prompts/list` are discovery. Every other message, such as `initialize`, a notification, a client response or a `resources/unsubscribe`, which only gives a resource up, names nothing and is forwarded as it is, as is a request without a body. Tool `arguments` and `_meta` are not checked, and a refusal message never repeats a value the client sent. The error body is a JSON-RPC response; `id` is present only when the request had one and the message could be read, so the two parse errors carry none. Every refusal is audited as `NOT_AUTHORIZED` with reason `MCP request refused: <message>`. The [MCP guide](/guides/guide-mcp) covers the revisions themselves.

With capability checks on, a discovery and an invocation then get the capability decision in place of the admission decision: the lists of a `tools/list`, `resources/list` or `prompts/list` answer are filtered to the caller's permitted set, in the server's order and with the cursor untouched, and the filtered list carries `cacheScope: private` and a `ttlMs` no longer than `authzen.cache_ttl`; a caller who may use nothing of the kind gets an empty list from the gateway, without the server, with `"resultType": "complete"` as revision `2026-07-28` requires in every result; an invocation outside the set is answered `403` with the JSON-RPC error `-31403`, `Forbidden: the caller may not use the named tool` (or `resource`, `prompt`) under the id of the request, and a `prompts/get` is tested against the prompts, never against a tool of the same name. A replayed stream (a `GET` with `Last-Event-ID`) keeps the admission decision and always reaches the server, and the lists in it are filtered with the sets of all three kinds. See [Capability checks](#capability-checks-what-the-caller-may-use).

With a Token Service, the gateway declares the delegated token extension `com.indykite/delegated-token` in the capabilities of the server, so a client knows it may send its `X-IK-Token` to the server: in the answer to an `initialize` on a revision before `2026-07-28` under `capabilities.experimental`; in the answer to an `initialize` on `2026-07-28` and in the answer to a `server/discover` under `capabilities.extensions`; and in a replayed stream in every result that carries a `protocolVersion`, by the same rule. The gateway adds the declaration and changes nothing else in the answer; an answer it cannot read in one way only is forwarded without it.

The MCP server behind the gateway must support one of the three revisions. When it answers an `initialize` with another revision, the client does not get the handshake and a failure at its next request: the gateway answers the `initialize` itself, under its `id` written as it was, with the status of the server's answer and the JSON-RPC error `-32603`, `Internal error: the MCP server supports none of the protocol revisions the gateway forwards`, whose `error.data` holds the revision the server `offered`, left out when it is not safe to repeat, and the `supported` revisions. A message the gateway cannot read before that answer, or a result whose `protocolVersion` cannot be read, is answered with `-32603`, `Internal error: the gateway cannot read the protocol revision the MCP server offered`. A replayed stream (a `GET` with `Last-Event-ID`) can repeat the answer to an `initialize`; every result in it that carries a `protocolVersion` is checked the same way and the same error takes its place, and the stream ends without an answer at a message the gateway cannot read. The gateway logs each such refusal.

### OAuth discovery

An MCP client finds out where to get its token the way the MCP authorization specification describes: from the OAuth 2.0 Protected Resource Metadata (RFC 9728) of the resource it called, which is the gateway, not the server behind it. The gateway serves that metadata without a token and links it from every `401` of the endpoint.

| Request | Answer |
| --- | --- |
| `GET /.well-known/oauth-protected-resource<path of service.base_url>` | No token needed. `resource` is `service.base_url`, `authorization_servers` is `[identity_provider.issuer]`, `bearer_methods_supported` is `["header"]`, and with a Token Service `mcp_extensions` is `{"com.indykite/delegated-token": {}}`. For `service.base_url` `https://agents.example.com/mcp/v1/gid:AAAA…` the path is `/.well-known/oauth-protected-resource/mcp/v1/gid:AAAA…`. |
| `GET /.well-known/oauth-protected-resource` | The same metadata with the origin of `service.base_url` (scheme, host and port, no trailing slash) as `resource`. When the path of `service.base_url` is `/`, this is the only metadata address and `resource` is the origin. |
| `HEAD` or `OPTIONS` on either path | `HEAD`: `200` with the JSON content type and no body. `OPTIONS`: `204` with `Allow: GET, HEAD`, and a CORS preflight from any origin gets `Access-Control-Allow-Origin: *` (see [CORS](#cors)). Any other method: `405` with `Allow: GET, HEAD`. |
| Any `401` of the MCP endpoint | `WWW-Authenticate: Bearer resource_metadata="<origin>/.well-known/oauth-protected-resource<path of service.base_url>"`, on the gateway's own refusals (missing or inactive token) as well as on a `401` the MCP server returns. |
| A `401` or `403` of the MCP server with its own challenge | The server's challenge is kept, `error`, `scope` and `error_description` included; only `resource_metadata` is replaced by the gateway's address in every `Bearer` challenge, or added when the challenge has none, since the server's metadata names the server, which the client did not call. The challenge is written back with its parameters sorted by name and every value quoted. A challenge the gateway cannot read stays as it is and gets the gateway's `Bearer` challenge next to it. A `403` without a challenge is an authorization decision of the gateway and gets none. The body of the server's answer is forwarded as it is, and may hold the server's own metadata address. |

What this means for the deployment and the tokens:

- **Ingress.** It must not strip a path prefix, since the gateway serves the path of `service.base_url` as it is, and it must route `/.well-known/oauth-protected-resource<path of service.base_url>` to the gateway. The root `/.well-known/oauth-protected-resource` can serve only one gateway per host. Another server may serve the metadata instead, with the same values, but routing the address to the gateway is simpler.
- **The token's `resource`.** A client asks the identity provider for its token with `resource` set to the `resource` of the metadata it read: `service.base_url`, or the origin at the root. The token is thus issued for the MCP server under its public URL, which is the gateway. Without `token_service`, the server receives the token the gateway exchanges for it at the identity provider. With `token_service`, the server receives the client's token in `Authorization` as `authorization_header.forward` passes it on, by default when it is issued for this agent, so it must accept the audience the identity provider writes for that `resource`; the IndyKite MCP server does with a Token Introspect configuration for the issuer and that audience. List the same value in `protected_agent.authentication.audiences`. A later hop that reaches the gateway with `X-IK-Token` alone is forwarded without `Authorization`; the IndyKite MCP server then answers `401`, since it requires a bearer token beside the delegation token, so callers of that server keep the user's token on every hop.
- **Moving an existing mcp configuration.** A gateway in front of an MCP server needs three settings and does not start without them: `service.base_url`, the public URL of the MCP endpoint at the gateway (set it to the URL your clients already call to keep it); `protected_agent.base_url`, the full URL of the server's endpoint rather than the server's address alone, for example `http://mcp-server:8080/mcp/v1/gid:AAAA…` instead of `http://mcp-server:8080`; and `identity_provider.issuer`. Both paths are written unencoded. A client that used to call other paths of the server through the gateway now gets `404`.

## CORS

The gateway answers CORS itself, so a browser client on another origin, such as a web console or a browser-based MCP client, can call it. Which origins a path allows depends on whether the path needs a token:

| Mode | Path | Allowed origins | Methods |
| --- | --- | --- | --- |
| `mcp` | The two metadata paths of [OAuth discovery](#oauth-discovery) | Every origin (`*`) | `GET, HEAD` |
| `mcp` | The path of `service.base_url`, the MCP endpoint | `cors.allowed_origins` | `GET, POST, DELETE` |
| `mcp` | Any other path | None: the path answers `404` | - |
| `a2a` | `/.well-known/agent-card.json`, a `GET` without `Authorization` (the public card) | Every origin (`*`) | `GET` |
| `a2a` | `/.well-known/agent-card.json` with `Authorization` (the extended card), and any other path (JSON-RPC calls) | `cors.allowed_origins` | `GET, POST` |

- **`OPTIONS`** on one of these paths is answered by the gateway with `204` and `Allow: <methods>`, before any token is read; nothing is forwarded.
- **A preflight** (`OPTIONS` with `Origin` and `Access-Control-Request-Method`) from an allowed origin also gets `Access-Control-Allow-Origin` (`*` on a public path or when the list is `*`, otherwise the request's origin), `Access-Control-Allow-Methods`, `Access-Control-Max-Age: 7200` and `Access-Control-Allow-Headers: Authorization, X-IK-Token, Content-Type, Accept, MCP-Protocol-Version, Mcp-Session-Id, Last-Event-ID, Mcp-Method, Mcp-Name, A2A-Version, A2A-Extensions`. On the MCP endpoint the allowed headers also include the `Mcp-Param-{Name}` headers the preflight asks for, which a `2026-07-28` client sends for tool parameters marked `x-mcp-header`; those answers carry `Vary: Access-Control-Request-Headers`. On the agent card path, only a preflight for a `GET` that does not ask for `Authorization` counts as one for the public card.
- **Any other request** from an allowed origin gets `Access-Control-Allow-Origin` and `Access-Control-Expose-Headers: WWW-Authenticate, Mcp-Session-Id` on every answer: the gateway's own `400`, `401` and `403`, and the answers it forwards, streams included. A browser MCP client can therefore read the `WWW-Authenticate` challenge of a `401` and the `Mcp-Session-Id` of an answer.
- **An origin that is not allowed**, or a request without `Origin`, gets no CORS headers on a token-protected path; the request is processed normally and the browser refuses the answer. The gateway does not refuse it with `403`.
- **Caching.** Answers on token-protected paths carry `Vary: Origin`. Answers on public paths carry `Access-Control-Allow-Origin: *` even without `Origin`, so a cache may serve them to every origin.
- **No credentials mode.** The gateway never sends `Access-Control-Allow-Credentials`: the token travels in `Authorization`, never in a cookie.
- **The protected server's own CORS headers are dropped**, since the gateway owns CORS at its public URL. `Origin` is forwarded unchanged, so an MCP server that checks `Origin` must accept the listed origins too.

## Status codes

| Status | Body and meaning |
| --- | --- |
| 200 | Authorized and forwarded; the body is the protected agent's or MCP server's response. In mcp mode any downstream status is passed through, a list answer is filtered to the caller's permitted set, and a list of a kind the caller may use nothing of is answered empty by the gateway itself. With `ibac.enabled`, also the answer the gateway gives in place of the agent when the Intent Agent failed the task: a JSON-RPC `result` holding an agent message in the request's `contextId`, its text the task's error and obligation, its `metadata.intent_error` the `{prompt, error, reason, obligation}` object; for `message/stream`, one event with that message. |
| 400 | a2a: the JSON-RPC request could not be parsed (empty body). mcp: one of the refusals above. |
| 401 | In mcp mode every `401` also carries `WWW-Authenticate: Bearer resource_metadata="…"` (see [OAuth discovery](#oauth-discovery)). `{"message":"Missing bearer token"}` for a request with neither a bearer token nor, with a Token Service, an `X-IK-Token`; `{"message":"Access token not issued for this agent"}` when a workflow is started with a token whose audience is none of `protected_agent.authentication.audiences`; `{"message":"Unauthorized","errors":["identity provider: the token is not active"]}` or `["token service: the token is not active"]`, the latter also for an identity provider token presented as `X-IK-Token`, since the Token Service reports only its own tokens as active; `{"message":"Invalid token, missing subject"}`, `{"message":"Invalid token, missing act claim"}`, `{"message":"Invalid token, act claim must be an object"}` for a delegation token the exchange produced; `{"message":"Invalid delegated token"}`, `{"message":"Invalid delegated token, missing act claim"}`, `{"message":"Invalid delegated token, missing subject"}`, `{"message":"Invalid delegated token, subject mismatch"}` for an incoming `X-IK-Token`, the last only when a bearer token travels beside it and `same_user_check` is on. A `401` or `403` from the identity provider, the Token Service, ContX IQ or AuthZEN is passed through with the same status and an `errors` entry naming the service, for example `["identity provider: token exchange failed - <error>: <error_description>"]`, `["identity provider: client credentials grant failed - …"]`, `["ContX IQ whoami failed"]`, `["evaluating admission through AuthZEN failed"]`, the latter also when the platform cannot read the delegation token in `X-IK-Token` for lack of a matching Token Introspect configuration. So an invalid AppAgent credential reaches the caller as `401` or `403`; the audit decision `ERROR` tells it apart from a denial. |
| 403 | `{"message":"Authorization check failed"}`: the admission policy answered `false` for this subject, agent and chain, or the chain could not be read. The audit `reason` says which. In mcp mode also a JSON-RPC error under the id of the request, `-31403`, `Forbidden: the caller may not use the named tool` (or `resource`, `prompt`): the invocation names a capability outside the caller's permitted set. With `ibac.enabled` and an intent in the delegation token, also `Forbidden: the named tool has an invalid mapping` and, with `ibac.capabilities.unmapped: deny`, `Forbidden: the named tool has no mapping` (or `resource`, `prompt`); `Forbidden: the named tool does not match the intent`, when no evaluation of the current intent matches a mapping of the capability or the call lacks a value a mapping reads; and `Forbidden: the caller may not access the data the named tool uses`, when the platform denies one of the evaluations resolved from the matched mappings. Neither message names the data or the intent. In a2a mode with a Token Service, `{"message":"Authorization check failed"}` also answers a delegation token the Token Service finds too large, and, with `ibac.enabled`, a message whose intent fits no skill of the agent the caller may use. |
| 405 | a2a: unknown JSON-RPC method (empty body). mcp: `{"message":"Method Not Allowed"}` with `Allow: GET, HEAD` for any other method on a metadata path. |
| 404 | mcp: `{"message":"Not Found"}` for any path other than the MCP endpoint path and the two metadata paths, before the token is read. |
| 404, 409, 415, 424, 501 | a2a: errors returned by the protected agent, translated: task or method not found, task not cancelable, unsupported content type, extended card not configured, unsupported operation. |
| 500 | `{"message":"Internal Server Error"}`: the identity provider, the Token Service, ContX IQ, AuthZEN or an A2A agent could not be reached or timed out, or one of them answered `500`; also when the permitted set of the caller could not be read, unless the platform answered another status, which is then passed on. |
| 502 | `{"message":"Bad Gateway","errors":[…]}`: in mcp mode the server could not be reached (the transport error is in `errors`) or `base_url` is not a URL (`cannot resolve downstream URL`); in a2a mode the agent returned a JSON-RPC internal error or an unusable response, its agent card cannot be used, or it redirected off the configured host; the identity provider or Token Service answered with a malformed body. With `ibac.enabled`: `["the intent agent cannot be asked"]`, `["the intent agent answered with a message instead of a task"]`, `["the intent agent answered with an intent that cannot be read"]`, `["the intent agent answered with a task neither completed nor failed"]`, `["cannot delegate the token with the intent"]` when the second exchange fails or its token lacks evaluations of the intent; in mcp mode with an intent in the delegation token, `["cannot list the capabilities of the MCP server"]`; in a2a mode with a Token Service, `["cannot read the skills of the agent"]` when the agent card, or its skills with their mappings, cannot be read to compare them with the intent; a `401` from the Intent Agent is retried once with a renewed token, and the identity provider's refusal of the gateway's own token for it is passed through as that provider's status. |
| 504 | `{"message":"Gateway Timeout","errors":["the intent agent did not answer in time"]}`: the Intent Agent did not answer within `intent_agent.timeout`. |

**Long answers.** The gateway sets no time limit on an answer, in either mode, so a long stream or a slow agent reaches the caller. Only connecting to the agent or the server is still bounded, to 10 seconds. The caller decides how long it waits: when it closes the connection, the gateway stops its call to the agent or the MCP server.

Health for orchestrators is on port 9080. The unauthenticated `401` works as an external probe too, but every such probe writes an audit record and, with webhook delivery, one webhook call.

# Audit records

One record per decision, written before the request is forwarded, so a forward that fails afterwards still shows `AUTHORIZED`. `action` names the question the record answers, `decision` the answer. JSON to the webhook, or the configured file format:

```json
{
  "decision": "AUTHORIZED",
  "reason": "subject User/millicent may reach Agent/indykiteagent-2 through the delegation chain",
  "subject": "millicent",
  "actor": "indykiteagent-2",
  "action": "ADMISSION",
  "service": "retriever-iag",
  "timestamp": "2026-09-30T09:12:00.123456789Z",
  "traceID": "4bf92f3577b34da6a3ce929d0e0e4736",
  "cached": {
    "admission": false
  },
  "actorsChain": [
    "indykiteagent",
    "indykiteagent-2"
  ]
}
```

A capability decision of a gateway in front of an MCP server, here the filtering of a `tools/list`:

```json
{
  "decision": "AUTHORIZED",
  "reason": "the lists of the server were filtered to the permitted set",
  "subject": "millicent",
  "actor": "mcp-agent",
  "action": "DISCOVERY",
  "service": "mcp-iag",
  "timestamp": "2026-11-06T09:12:00.123456789Z",
  "traceID": "0af7651916cd43dd8448eb211c80319c",
  "permittedSet": {
    "tool": ["read_document", "search_documents"]
  },
  "cached": {
    "tool": true
  },
  "discovery": {
    "serverCalled": true,
    "listed": 5,
    "kept": 2
  },
  "actorsChain": [
    "mcp-agent"
  ]
}
```

| Field | Values |
| --- | --- |
| `decision` | Read with `action`. On `ADMISSION`, `DISCOVERY` and `INVOCATION` records: `AUTHORIZED`, `NOT_AUTHORIZED`, or `ERROR` when the platform could not be consulted; a cached `ERROR` is a failed platform call kept for `authzen.cache_update_after_error`, and is never a denial. On `noop` records, written for a request refused before any question was asked: `NOT_AUTHORIZED` for a missing token, a token not issued for this agent, an unusable `X-IK-Token`, a subject `whoami` rejects, an MCP request or a delegation chain the gateway cannot read; `ERROR` when the identity provider refuses the gateway's own credentials, when the delegation token lacks `sub` or `act`, when `whoami` fails for another reason, or when the chain names the protected agent with another type than `protected_agent.node_type`. On `INTENT` records: `INTENT_FOUND` when the Intent Agent found the intent, `INTENT_FAILED` when it failed the task, `ERROR` when it could not be asked, answered unreadably or timed out, or when the skills of the agent could not be read. With a Token Service the intent is also compared with the skills of the agent: `NOT_AUTHORIZED` when it fits none of them; and for a message without text, which is not sent to the Intent Agent, `AUTHORIZED` or `NOT_AUTHORIZED` for the intent of its chain. |
| `reason` | Token steps: `no bearer token`, `cannot introspect the subject token`, `cannot validate the delegated token`, `invalid delegated token: missing act claim`, `invalid delegated token: missing subject`, `invalid delegated token: subject mismatch`, `the access token is not issued for this agent`, `cannot authenticate protected agent`, `cannot delegate token`, `invalid token: missing subject`, `invalid token: missing act claim`, `invalid token: act claim is not an object`, `MCP request refused: <message>`. Subject: `cannot resolve the subject of the access token`, with decision `NOT_AUTHORIZED` when `whoami` answers `401` and `ERROR` otherwise. Admission: `the delegation chain cannot be read`, `the delegated token names the protected agent <type>, protected_agent.node_type is <type>`, `unable to evaluate the admission of subject <type>/<id>`, `subject <type>/<id> may not reach <agent type>/<agent> through the delegation chain`, `subject <type>/<id> may reach <agent type>/<agent> through the delegation chain`. `<type>/<id>` is the subject from `whoami`, for example `User/millicent`; `<agent type>/<agent>` is the resource of the evaluation, for example `Agent/indykiteagent-2`. Intent (action `INTENT`): `intent with <n> evaluation(s)`, with a Token Service followed by how many fit the skills of the agent, as in `intent with 2 evaluation(s), 1 fit the skills of the agent`, or `intent with 2 evaluation(s), none fits the skills of the agent` on a refusal; for a message without text, `no prompt: the current intent with <n> evaluation(s), <m> fit the skills of the agent`, `no prompt: the current intent with <n> evaluation(s) fits no skill of the agent`, or `no prompt, IBAC did not run: the chain carries no intent`; `cannot read the skills of the agent: …` on an `ERROR`; `no intent: <error of the task>` followed by `(reason: <reason>)` only with `audit.include_prompt`, cut to 4096 bytes with a trailing `…`; when the error is the text the model answered with in place of an intent, which can quote the prompt, the record says only `no intent: the model answered with text` unless `audit.include_prompt` is on; and `cannot get the intent of the prompt` when the Intent Agent could not be asked. Capability decisions: `the lists of the server were filtered to the permitted set`, with `ibac.enabled` `the lists of the server were filtered to the permitted set and the current intent`, `the lists of the server were filtered to the current intent` with capability checks off, or `the lists of the server were filtered to the permitted set; IBAC did not run: the delegated token carries no intent`, `the caller may use nothing of the kind listed, answered with an empty list` `the skills of the card were filtered to the permitted set`, `the skills of the card were filtered to the permitted set and the current intent`, with capability checks off `the skills of the card were filtered to the current intent`, and, with `ibac.enabled` and no intent in the delegation token, `the skills of the card were filtered to the permitted set; IBAC did not run: the delegated token carries no intent` or, with capability checks off, `IBAC did not run: the delegated token carries no intent` on `DISCOVERY`; on an `ERROR` of a card, `the skills of the card cannot be read with their mappings`; `the caller may use the named tool` and `the caller may not use every named tool` (or `resource`, `prompt`) on `INVOCATION`; on an `ERROR`, the failure of the search or of the server. Resolved evaluations (action `RESOLVED_EVALUATIONS`): `the platform allowed every resolved evaluation`, `the platform denied a resolved evaluation`, and on an `ERROR` `the resolved evaluations cannot be checked: …`. |
| `subject`, `actor`, `actorsChain` | The user (the token's `sub`; the `whoami` subject appears only in `reason`), the last agent, and the chain oldest first. In records written by the token steps the subject can be empty, `actor` is the upstream agent and `actorsChain` is the incoming chain, so it lacks the protected agent and is `null` on the first hop. On a chain that cannot be read, `actor` is `no-actor` and `actorsChain` is `null`. |
| `action` | The question the record answers: `ADMISSION`, may the subject reach the protected agent through the delegation chain; `DISCOVERY`, which capabilities of the listed kind may the caller see, written for a filtered `tools/list`, `resources/list` or `prompts/list`, for the lists of a replayed stream and for the extended card of an A2A agent; `INVOCATION`, may the caller use every capability the request names; `RESOLVED_EVALUATIONS`, does the platform allow the data an MCP call touches, written with `ibac.enabled` for a call the intent matches whose mappings name ids; `INTENT`, the record of each Intent Agent call, written after the request's own record and carrying the same `subject`, `actor` and `actorsChain`; `noop`, no question was asked because the request was refused first. One decision per request, so a request gets either an `ADMISSION` or a capability record, never both. With `ibac.enabled` in mcp mode, an invocation also gets an `IBAC_USAGE` record when its mapping is checked: `IBAC did not run: the delegated token carries no intent`, `IBAC was skipped: the named tool has no mapping` (with `reasonCode` `missing_coaz_mapping`), a refusal (`the named tool has an invalid mapping` or `has no mapping`, with `reasonCode` `invalid_coaz_mapping` or `missing_coaz_mapping`), or `the capabilities of the server cannot be listed: …` as an `ERROR`. A capability checked against the intent gets one more `IBAC_USAGE` record, the result of the IBAC engine, with `reasonCode` `intent_match_authzen_required` (matched, with evaluations for the platform), `intent_match_search` (matched, nothing to ask the platform) or `intent_mismatch` (refused). With `ibac.enabled` in a2a mode, the filtering of an extended card by the current intent also writes `IBAC_DISCOVERY` records, before the `DISCOVERY` record of the card: one for the skills without a mapping, `AUTHORIZED` with `IBAC was skipped: the skills have no mapping` under `allow` or `NOT_AUTHORIZED` with `the skills have no mapping` under `deny`, both with `reasonCode` `missing_coaz_mapping`; one for the skills whose mapping cannot be read, `NOT_AUTHORIZED` with `the skills have an invalid mapping` and `invalid_coaz_mapping`; each with the skill ids in `skillIDs`; and the record of the IBAC engine for the skills with a mapping, one per 64 skills. The intent filter of an MCP list writes `IBAC_DISCOVERY` records the same way, with the entries of the list in `skillIDs`; and with a Token Service, the comparison of a message with the skills of the agent writes one with every evaluation and the skills it matched, where an evaluation that matched no skill was left out of the token. |
| `durationMs`, `prompt` | Only on `INTENT` records: how long the Intent Agent call took in milliseconds, and, with `audit.include_prompt`, the prompt that was asked about. Absent from the JSON of every other record. |
| `cached` | On decision records: whether the answer came from the gateway's cache or from the platform during the request. An `ADMISSION` record has the one key `admission`; a capability record has one key per kind it decided on, `tool`, `resource`, `prompt` or `skill`; a `RESOLVED_EVALUATIONS` record has the one key `evaluations`. |
| `resolvedEvaluations` | On `RESOLVED_EVALUATIONS` records: every evaluation sent to the platform, in the order sent, each with `subjectType`, `subjectID`, `action`, `resourceType`, `resourceID` and the platform's answer `allowed`, which is left out when the platform did not answer. The resource ids come from the arguments of the call. |
| `currentIntent`, `originalIntent` | On the records of an MCP request whose delegation token carries an intent, on the `IBAC_DISCOVERY` and `DISCOVERY` records of a card or a list filtered by the intent, and on the `INTENT` and `IBAC_DISCOVERY` records of a message compared with the skills, where the current intent of a message with text is the intent of its prompt: the intent the decision was checked against, the newest in the `act` chain, and the intent of the oldest hop that carries one, each as the evaluations the token carries. |
| `capabilities` | On `INVOCATION` records: the identifiers the request named, by kind, for example `{"tool": ["read_document"]}`. |
| `permittedSet` | On `DISCOVERY` records: the set the list was filtered to, by kind, as the platform returned it; an empty list when the caller may use nothing of the kind. A denied invocation compared with the permitted set of the last discovery for the same `subject` and `actorsChain` tells probing from a change of permissions; no record carries a flag for it, and the record does not tell apart a caller admitted nowhere, one admitted with nothing permitted and a server with nothing modelled. |
| `discovery` | On `DISCOVERY` records: `serverCalled`, whether the server was asked at all (`false` for a list the gateway answered empty); `listed`, how many entries the server's list advertised; `kept`, how many the caller got. For the extended card the agent is always asked, `listed` counts its skills and `kept` the skills the caller got, after the permitted set and, with `ibac.enabled` and an intent, after the current intent. A card filtered with capability checks off has a `DISCOVERY` record without `permittedSet` and `cached`. |
| `service` | `service.name`. |
| `timestamp`, `traceID` | RFC 3339 UTC with up to nanosecond precision (trailing zeros are dropped), and the trace ID also found in the gateway's JSON logs. |
| `tokenID` | Only in Token Service records; the CSV header carries the column so both services can share files. |

`cached`, `capabilities`, `permittedSet` and `discovery` appear in the JSON of the webhook and of `json` files only; the `csv` and `txt` layouts below do not carry them. The `txt` format writes one line per record, values unquoted and the chain comma-joined, except `prompt`, `capabilityName` and `skillID`, which are quoted so that a record stays on one line:

```text
[2026-09-30T09:12:00.123456789Z] decision=AUTHORIZED reason=subject User/millicent may reach Agent/indykiteagent-2 through the delegation chain subject=millicent actor=indykiteagent-2 actorsChain=indykiteagent,indykiteagent-2 action=ADMISSION service=retriever-iag traceID=4bf92f3577b34da6a3ce929d0e0e4736 tokenID= prompt="" capabilityName="" skillID="" reasonCode= skillIDs= evaluations= durationMs=0
```

`csv` writes the same columns in that order with a header row per file: after `tokenID` come `prompt`, `capabilityName`, `skillID`, `reasonCode`, `skillIDs`, `evaluations` and `durationMs`, appended at the end so that files written before they existed still read. The gateway fills `durationMs`, and `prompt` with `audit.include_prompt`, on its `INTENT` records; the other five columns, `capabilityName`, `skillID`, `reasonCode`, `skillIDs` and `evaluations`, belong to the `IBAC_DISCOVERY` and `IBAC_USAGE` records of the [IBAC engine](/guides/guide-ibac#audit) and stay empty on every other record.

# Telemetry

Every step a request waits for is a span in the trace of the request, named `agent-gateway <step>`, and a duration in the histogram `indykite_agent_gateway_step_duration_seconds`. The span and the metric carry the same labels:

| Label | Values |
| --- | --- |
| `step` | The step, see the next table. |
| `outcome` | `ok`: the step succeeded. `refused`: the step answered no, such as a denied decision, a token the identity provider or the Token Service reports inactive, an intent that does not match, or a failed task of the Intent Agent. `canceled`: the step failed because its request ended first, such as when the caller went away. `error`: the step failed; an introspection answered with a status, such as `401` for the credentials of the gateway, is an `error`. Only the span of an `error` step has the error status, so an alert on `error` does not fire on what callers do. |
| `cache` | `hit`: answered from the cache of the gateway. `miss`: the request made the call. `shared`: the request waited for the same call of another request. `none`: a step without a cache, a value that cannot be kept, or a request that stopped waiting. |

| `step` | What it measures | More labels | `cache` |
| --- | --- | --- | --- |
| `introspection` | An introspection of a token. | `peer` | `none` |
| `token_exchange` | A token exchange, the first one or the one with the intent. | `peer`, `exchange` (`first`, `intent`) | `none` |
| `actor_token` | The client credentials token of the gateway. |  | `hit`, `miss`, `shared`, `none` |
| `whoami` | ContX IQ `whoami`. |  | `hit`, `miss`, `shared`, `none` |
| `kbac_admission` | The AuthZEN admission evaluation. |  | `hit`, `miss`, `shared` |
| `kbac_permitted_set` | One AuthZEN resource search of the permitted set. | `resource_type` | `hit`, `miss`, `shared` |
| `intent_agent` | The call of the Intent Agent. |  | `none` |
| `ibac_discovery` | Filtering a list or a card by the intent. |  | `none` |
| `ibac_usage` | Checking a call against the intent. |  | `none` |
| `platform_checks` | The AuthZEN `evaluations` request with the resolved evaluations. |  | `hit`, `miss`, `shared` |
| `catalog_fill` | Listing the MCP server, or reading the agent cards, to learn the capabilities and their mappings. | `kind` | `none` |
| `agent_card` | Reading the card an A2A agent publishes, for every call to the agent. | `agent` (`protected_agent`, `intent_agent`) | `hit`, `miss`, `shared`, `none` |

- `peer` is `identity_provider` or `token_service`.
- The count of the histogram by `cache` gives the hits and the misses of each cache. A `whoami` for a token without a subject is not kept, and is `none`.
- A caller that gives up because a service is slow is `canceled` too, so watch the duration of a step as well as its errors.
- The Intent Agent answers both a prompt without an intent and a failure of its own with a failed task. So an `intent_agent` step that is `refused` can also be an outage of the Intent Agent; only a call that fails, a bad answer or a timeout is an `error`.
- `catalog_fill` runs for a capability the gateway has not seen listed. In front of an A2A agent with `ibac.enabled`, a Token Service and capability checks off, it also runs for every message, so its count then follows the messages.
- A step can run within another step, so the durations of the steps of a request do not add up to the duration of the request: `agent_card` runs within `intent_agent` and, when the skills of the protected agent are read, within `catalog_fill`.
- A call to AuthZEN and ContX IQ carries the trace on, so the IndyKite platform continues the same trace. A call to the identity provider or the Token Service sends no trace header.

# Related

- The big picture first, on the reference diagram: [Agent Gateway architecture guide](/guides/guide-iag-architecture)
- Protect an MCP server step by step: [Agent Gateway MCP tutorial](/tutorials/tutorial-agent-gateway-mcp)
- Let policies see the whole agent chain: [Token Service guide](/guides/guide-token-service)
- Turn a prompt into AuthZEN evaluations: [Intent Agent guide](/guides/guide-intent-agent)
- Match an intent against what a skill or tool declares it does: [IBAC engine guide](/guides/guide-ibac)
- Author the admission policy and the `$ik_token` claims it reads: [AuthZEN guide](/guides/guide-authzen)
- Working stacks: the `a2a/iag-mcp-demo` and `a2a/iag-token-exchange` folders of the [developer-hub repository](https://github.com/indykite/developer-hub)
- Drive the setup from a coding agent: [Agent Skills guide](/guides/guide-skills)
- The audit record next to the platform events and the Intent Agent record, and how to correlate them: [Audit Event Formats guide](/guides/guide-audit-formats)

---

Source: https://developer.indykite.com/guides/guide-agent-gateway