{
  "id": "tutorial-agent-gateway-mcp",
  "title": "Protect an MCP server with Agent Gateway and external token exchange: Google Drive behind the MCP proxy",
  "description": "Put the IndyKite Agent Gateway (IAG) in MCP proxy mode in front of any MCP server - demonstrated end to end with a Google Drive MCP server in the iag-mcp-demo reference app.",
  "category": "Agent Gateway",
  "order": 21,
  "image": "/assets/images/categories/card-agent-gateway.svg",
  "summary": "This tutorial uses external token exchange: the delegation tokens are minted by your own identity provider's OAuth 2.0 token exchange (RFC 8693), not by the IndyKite Token Service. Follow the chapters in order to understand IAG's MCP proxy mode with that setup, run the Google Drive MCP server as a container, model the wf-drive workflow and its delegation chain in the IKG, configure the drive-mcp-iag gateway, run a Google Drive search through it, verify denials in the audit trail, remediate one live with the AuthZEN-guarded grant button, and see the same recipe extended to a graph-filtered ERP and a Salesforce CRM.",
  "body": "<p class=\"notion\">This tutorial is grounded in the <a href=\"https://github.com/indykite/developer-hub/tree/master/a2a/iag-mcp-demo\" class=\"fancy-link\" target=\"_blank\">iag-mcp-demo</a> reference application, running its <strong>canbank usecase</strong> provisioned with the instant-stack app. It puts the IndyKite Agent Gateway (IAG) in <strong>MCP proxy mode</strong> (<code class=\"notion\">protected_agent.protocol: mcp</code>) in front of an MCP server - and proves the mode is downstream-agnostic by protecting a <strong>Google Drive MCP server</strong> that has nothing to do with IndyKite. Users log in at an <strong>external identity provider</strong> (IdP), which also introspects tokens and performs the OAuth 2.0 token exchange (RFC 8693) that gives every gateway its delegation token; the demo uses Curity, and any IdP with those endpoints fits. Every request is authorized against the Identity Knowledge Graph (IKG) before it is forwarded: who the caller is, which workflow they may trigger, and through which chain of agents. And because that authorization is graph data, it changes live: a denied request is remediated with one AuthZEN-guarded click, explained with a <strong>why?</strong> graph, and revoked again. The closing chapter shows the same recipe carried further - a Postgres-backed ERP whose rows are pre-filtered by AuthZEN search/resource, and a CRM agent that files Salesforce cases on behalf of the delegated user.</p>\n<p class=\"notion\">The whole demo, every agent, gateway and external service and the numbered request flow between them, is drawn and explained in the <a href=\"/guides/guide-iag-architecture\" class=\"fancy-link\">Agent Gateway architecture guide</a>. Read it first if you want the map before the route.</p>\n<p class=\"notion\"><strong>External token exchange or Token Service?</strong> In this tutorial the delegation tokens come from your identity provider's token exchange. If your provider has no token exchange, or you want the delegation tokens issued by a service you run, follow <a href=\"/tutorials/tutorial-agent-gateway-delegation-chain\" class=\"fancy-link\">Follow a delegation chain across agents: Agent Gateway with the IndyKite Token Service</a> instead; its first chapter compares the two.</p>\n\n<h3 class=\"\">What you will have at the end</h3>\n<ol type=\"1\" class=\"numbered-list\" start=\"1\">\n<li>A clear mental model of what IAG's MCP proxy mode does and does not do (session pass-through, SSE streaming, header handling, per-request authorization).</li>\n<li>A Google Drive MCP server running as a container: the reference stdio server wrapped into MCP Streamable HTTP.</li>\n<li>A <code class=\"notion\">Workflow</code> node (<code class=\"notion\">external_id=wf-drive</code>), an <code class=\"notion\">Agent</code> node (<code class=\"notion\">indykiteagent-drive</code>), and the <code class=\"notion\">CAN_TRIGGER</code> / <code class=\"notion\">INVOKES</code> relationships in the IKG.</li>\n<li>The admission KBAC policy that lets a user reach the Drive server only when a workflow they can trigger has exactly the request's delegation chain as its path of agents, and the Token Introspect configurations that tell IndyKite which tokens of your IdP to accept.</li>\n<li>A dedicated gateway instance, <code class=\"notion\">drive-mcp-iag</code>, proxying MCP traffic on port <code class=\"notion\">8887</code>.</li>\n<li>A full-text Google Drive search executed through the gateway as an authorized user - and the same call denied with <code class=\"notion\">403</code> for everyone else, with matching audit records.</li>\n<li>The <strong>deny → remediate → allow</strong> loop: a denied user's red audit card grants Drive access with one AuthZEN-guarded click (writing <code class=\"notion\">CAN_TRIGGER</code> relationships via the Capture API), a <strong>why?</strong> card renders the authorization path live from the graph, and a revoke resets the world.</li>\n<li>A view of where the recipe leads: the <strong>ERP</strong> profile (a Postgres-backed MCP server whose rows are pre-filtered per caller by AuthZEN search/resource) and the <strong>CRM</strong> profile (a gateway-protected agent filing Salesforce cases on behalf of the delegated user).</li>\n</ol>\n\n<h3 class=\"\">Prerequisites</h3>\n<ul class=\"bulleted-list\">\n<li style=\"list-style-type:disc\">An <strong>IndyKite project</strong> with AuthZEN/KBAC and ContX IQ enabled, provisioned with the <strong>canbank dataset</strong> via the <a href=\"https://github.com/indykite/developer-hub/tree/master/instant-stack\" class=\"fancy-link\" target=\"_blank\">instant-stack</a> app (<code class=\"notion\">DATASET=canbank</code>) or, request by request, with the demo's Bruno collection (<code class=\"notion\">bruno/iag-demo</code>) - chapter 5 explains the parts of that dataset this tutorial relies on.</li>\n<li style=\"list-style-type:disc\">An <strong>external OAuth 2.0 IdP</strong> with a token introspection endpoint, the client credentials grant, and token exchange (RFC 8693). It holds the demo's clients - <code class=\"notion\">console</code> for the chatbot login and one machine-to-machine client per gateway (<code class=\"notion\">indykiteagent</code>, <code class=\"notion\">indykiteagent-2</code> to <code class=\"notion\">-4</code>, <code class=\"notion\">indykiteagent-mcp</code>, and <code class=\"notion\">indykiteagent-drive</code> for this tutorial) - and <code class=\"notion\">millicent</code> as a login user (chapter 7 logs in as her).</li>\n<li style=\"list-style-type:disc\"><strong>Docker and Docker Compose v2</strong>, plus a Google account for chapter 3. The gateways run the <code class=\"notion\">indykite/agent-gateway</code> image with a platform release tag from <a href=\"https://hub.docker.com/u/indykite\" class=\"fancy-link\" target=\"_blank\">IndyKite on Docker Hub</a>.</li>\n<li style=\"list-style-type:disc\">The base iag-mcp-demo configured per the <a href=\"https://github.com/indykite/developer-hub/tree/master/a2a/iag-mcp-demo\" class=\"fancy-link\" target=\"_blank\">repo README</a> with the <strong>canbank usecase</strong> active - this tutorial adds the Drive pieces on top and bootstraps the usecase env file (<code class=\"notion\">.env.canbank</code>) in chapter 7.</li>\n</ul>\n\n<h3 class=\"\">Who this tutorial is for</h3>\n<ul class=\"bulleted-list\">\n<li style=\"list-style-type:disc\">Developers exposing <strong>MCP servers</strong> to AI agents who need token introspection, authorization, and audit in front of them - without changing the MCP server itself.</li>\n<li style=\"list-style-type:disc\">Platform and security engineers who want the same enforcement point for MCP tool calls as for A2A agent calls.</li>\n<li style=\"list-style-type:disc\">AI agents consuming this doc as a runbook - every chapter uses explicit service names, ports, file paths, and commands.</li>\n</ul>\n\n<h3 class=\"\">Demo topology at a glance</h3>\n<p class=\"notion\">The iag-mcp-demo is <strong>usecase-driven</strong>: the agents, gateways, and compose topology are domain-agnostic, and a usecase bundle (<code class=\"notion\">usecases/canbank/</code> - domain vocabulary, per-agent skills, demo script) plus a matching provisioned IndyKite project make it \"the CanBank demo\". Activate it with <code class=\"notion\">./switch-usecase.sh canbank</code>. This tutorial focuses on the services below; the Google Drive pair only starts when the <code class=\"notion\">drive</code> compose profile is enabled.</p>\n<table class=\"simple-table\">\n<tbody>\n<tr>\n<td class=\"simple-table-header-color\"><strong>Service</strong></td>\n<td class=\"simple-table-header-color\"><strong>Role</strong></td>\n<td class=\"simple-table-header-color\"><strong>Port</strong></td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">chatbot</code></td>\n<td class=\"\">Web UI; users log in here, and the demo scripts reuse its session token.</td>\n<td class=\"\"><code class=\"notion\">3000</code></td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">mcp-iag</code></td>\n<td class=\"\">IAG in MCP proxy mode in front of the IndyKite MCP server.</td>\n<td class=\"\"><code class=\"notion\">8886</code></td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">drive-mcp-iag</code></td>\n<td class=\"\">IAG in MCP proxy mode in front of the Google Drive MCP server (profile <code class=\"notion\">drive</code>).</td>\n<td class=\"\"><code class=\"notion\">8887</code></td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">drive-mcp</code></td>\n<td class=\"\">Google Drive MCP server: stdio reference server wrapped into Streamable HTTP (profile <code class=\"notion\">drive</code>).</td>\n<td class=\"\"><code class=\"notion\">8000</code></td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">erp-mcp-iag</code></td>\n<td class=\"\">IAG in MCP proxy mode in front of the ERP MCP server (profile <code class=\"notion\">erp</code>; chapter 8's \"Beyond Drive\" section).</td>\n<td class=\"\"><code class=\"notion\">8889</code></td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">erp-mcp</code> + <code class=\"notion\">erp-db</code></td>\n<td class=\"\">Postgres-backed ERP MCP server and its database (profile <code class=\"notion\">erp</code>). Deliberately <strong>not</strong> published to the host - only the gateway reaches them.</td>\n<td class=\"\">internal only</td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">analyst-iag</code></td>\n<td class=\"\">IAG in front of the analyst agent (used by the optional analyst path in chapter 7).</td>\n<td class=\"\"><code class=\"notion\">8885</code></td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">analyst</code></td>\n<td class=\"\">A2A data analyst agent; can use both the IndyKite and the Drive MCP backends.</td>\n<td class=\"\"><code class=\"notion\">6005</code></td>\n</tr>\n</tbody>\n</table>",
  "chapterCount": 8,
  "chapters": [
    {
      "chapter": 1,
      "title": "What MCP proxy mode is",
      "description": "How one configuration switch turns the Agent Gateway into an authorization-enforcing proxy for any MCP Streamable HTTP server, with an external identity provider issuing the tokens.",
      "body": "<h2 class=\"\">Chapter 1: What MCP proxy mode is</h2>\n\n<p class=\"notion\">The <strong>IndyKite Agent Gateway (IAG)</strong> protects exactly one downstream per instance. By default (<code class=\"notion\">protected_agent.protocol: a2a</code>) that downstream is an A2A agent. Set <code class=\"notion\">protected_agent.protocol: mcp</code> and the same gateway instead proxies <strong>MCP Streamable HTTP</strong> traffic to a downstream MCP server. Everything in front of the forwarding step - token introspection, the token exchange, the admission decision against the IKG, and audit - is identical in both modes.</p>\n\n<h3 class=\"\">Three parties, three jobs</h3>\n<p class=\"notion\">Before the details, the division of work. The gateway owns no users and issues no tokens; it sits between three parties and asks each one the question that party can answer:</p>\n<table class=\"simple-table\">\n<tbody>\n<tr>\n<td class=\"simple-table-header-color\"><strong>Party</strong></td>\n<td class=\"simple-table-header-color\"><strong>What it does for the gateway</strong></td>\n</tr>\n<tr>\n<td class=\"\">Your <strong>external identity provider</strong> (IdP)</td>\n<td class=\"\">Logs users in, tells the gateway whether a token is active (token introspection), gives each gateway its own client credentials token, and performs the <strong>OAuth 2.0 token exchange</strong> (RFC 8693) that turns \"this user\" plus \"this gateway\" into one <strong>delegation token</strong>: <code class=\"notion\">sub</code> is the user, the nested <code class=\"notion\">act</code> claims are the chain of gateway clients the request has passed.</td>\n</tr>\n<tr>\n<td class=\"\"><strong>IndyKite</strong></td>\n<td class=\"\">Answers who the token's user is in the graph (ContX IQ <code class=\"notion\">whoami</code>) and whether that user may reach the protected server through this delegation chain (one AuthZEN evaluation against a KBAC policy).</td>\n</tr>\n<tr>\n<td class=\"\">The <strong>MCP server</strong></td>\n<td class=\"\">Receives the request once both have said yes. It needs no change and no knowledge of IndyKite.</td>\n</tr>\n</tbody>\n</table>\n<p class=\"notion\">The demo runs on Curity as its IdP. Nothing in the gateway is tied to that product: any OAuth 2.0 provider that offers token introspection, the client credentials grant and a token exchange that nests the <code class=\"notion\">act</code> claim hop by hop fits, and chapter 6 shows the handful of settings that point the gateways at yours.</p>\n\n<h3 class=\"\">What the MCP proxy does</h3>\n<ul class=\"bulleted-list\">\n<li style=\"list-style-type:disc\"><strong>Serves one MCP endpoint</strong> - the path of <code class=\"notion\">service.base_url</code>, for the Drive gateway <code class=\"notion\">/mcp</code>. Any MCP method on that path - <code class=\"notion\">initialize</code>, the <code class=\"notion\">notifications/initialized</code> notification, <code class=\"notion\">tools/list</code>, <code class=\"notion\">tools/call</code>, <code class=\"notion\">resources/list</code>, <code class=\"notion\">resources/read</code> - is forwarded after the checks pass, to exactly the server endpoint named in <code class=\"notion\">protected_agent.base_url</code>. Session-teardown <code class=\"notion\">DELETE</code> requests are forwarded too. Any other path answers <code class=\"notion\">404</code> before the token is even read.</li>\n<li style=\"list-style-type:disc\"><strong>Enforces the protocol revision</strong> - only revisions <code class=\"notion\">2025-06-18</code>, <code class=\"notion\">2025-11-25</code>, and <code class=\"notion\">2026-07-28</code> are forwarded. An <code class=\"notion\">initialize</code> naming another revision is forwarded with <code class=\"notion\">protocolVersion</code> rewritten to <code class=\"notion\">2025-11-25</code>; every other request must carry <code class=\"notion\">Mcp-Protocol-Version</code> with a supported value, or it is refused with <code class=\"notion\">400</code> (JSON-RPC <code class=\"notion\">-32020</code> when the header is missing, <code class=\"notion\">-32022</code> with the supported list when the revision is unknown). JSON-RPC batches (<code class=\"notion\">400</code>, <code class=\"notion\">-32600</code>), bodies with a <code class=\"notion\">Content-Encoding</code> other than <code class=\"notion\">identity</code> (<code class=\"notion\">415</code>), and bodies over 4 MiB (<code class=\"notion\">413</code>) are refused as well. Refusals are audited as <code class=\"notion\">NOT_AUTHORIZED</code> and never reach the downstream.</li>\n<li style=\"list-style-type:disc\"><strong>Reads what each request names</strong> - a <code class=\"notion\">tools/call</code> must name its tool and a <code class=\"notion\">prompts/get</code> its prompt in <code class=\"notion\">params.name</code>, a <code class=\"notion\">resources/read</code> its resource in <code class=\"notion\">params.uri</code>. A body that is not exactly one JSON-RPC message, a key that could be read in more than one way (for example both <code class=\"notion\">name</code> and <code class=\"notion\">Name</code> in <code class=\"notion\">params</code>), a missing tool name, or on revision <code class=\"notion\">2026-07-28</code> an <code class=\"notion\">Mcp-Method</code> or <code class=\"notion\">Mcp-Name</code> header that disagrees with the body, is refused with <code class=\"notion\">400</code> before authorization. The exact codes and messages are in the <a href=\"/guides/guide-agent-gateway#http\" class=\"fancy-link\">Agent Gateway guide</a>.</li>\n<li style=\"list-style-type:disc\"><strong>Decides who gets in (admission)</strong> - one AuthZEN evaluation per request: may this user reach this MCP server through this delegation chain? The answer comes from a KBAC policy over the graph you model in chapter 5.</li>\n<li style=\"list-style-type:disc\"><strong>Decides what the caller may use (capability checks)</strong> - a second decision, on by default: the gateway reads from the graph which tools, resources and prompts the caller may use, filters <code class=\"notion\">tools/list</code>, <code class=\"notion\">resources/list</code> and <code class=\"notion\">prompts/list</code> to that set, and refuses a call outside it with <code class=\"notion\">403</code> and the JSON-RPC error <code class=\"notion\">-31403</code>. The demo switches this off for the Drive gateway, for a reason chapter 6 explains, and shows how to turn it on.</li>\n<li style=\"list-style-type:disc\"><strong>Passes the session through untouched</strong> - the <code class=\"notion\">Mcp-Session-Id</code> header is forwarded in both directions without translation. The session the downstream server mints during <code class=\"notion\">initialize</code> is the session the caller uses on every follow-up.</li>\n<li style=\"list-style-type:disc\"><strong>Streams SSE responses</strong> - the downstream response body is streamed to the caller and flushed per SSE message, so long-running responses are not buffered or truncated.</li>\n<li style=\"list-style-type:disc\"><strong>Swaps the credentials</strong> - the caller's <code class=\"notion\">Authorization</code> header is removed and replaced with the delegation token the IdP minted for this hop. Chapter 2 covers what this means for the downstream server.</li>\n<li style=\"list-style-type:disc\"><strong>Tells MCP clients where to get a token</strong> - the gateway serves OAuth 2.0 Protected Resource Metadata (RFC 9728) at <code class=\"notion\">/.well-known/oauth-protected-resource/mcp</code> without a token, naming your IdP's issuer as the authorization server, and every <code class=\"notion\">401</code> links it in a <code class=\"notion\">WWW-Authenticate</code> header.</li>\n</ul>\n\n<h3 class=\"\">What the MCP proxy does not do</h3>\n<ul class=\"bulleted-list\">\n<li style=\"list-style-type:disc\">It does <strong>not inspect tool arguments</strong>. The gateway decides on who calls, through which chain, and - with capability checks on - on the name of the tool, resource or prompt. What a tool does with its arguments stays the server's business.</li>\n<li style=\"list-style-type:disc\">It is <strong>not a generic HTTP reverse proxy</strong>. The downstream must speak MCP Streamable HTTP, and only its one MCP endpoint is reachable through the gateway.</li>\n<li style=\"list-style-type:disc\">It does <strong>not check the intent of a prompt in this demo</strong>. Intent-based access control (<code class=\"notion\">ibac.enabled</code>) is off here, the gateway's default. Its checks need the intent of a prompt in the delegation token, which only the IndyKite Token Service writes; this demo exchanges tokens at the identity provider, so its delegation tokens carry no intent, and admission and the capability checks are what the gateways decide. The <a href=\"/tutorials/tutorial-intent-ibac-gateway\" class=\"fancy-link\">intent tutorial</a> shows the gateway with the Token Service and the Intent Agent.</li>\n</ul>\n\n<h3 class=\"\">Downstream-agnostic by design</h3>\n<p class=\"notion\">Nothing in MCP proxy mode is specific to IndyKite's own MCP server. The <a href=\"https://github.com/indykite/developer-hub/tree/master/a2a/iag-mcp-demo\" class=\"fancy-link\" target=\"_blank\">iag-mcp-demo</a> proves this with three protected MCP downstreams:</p>\n<ul class=\"bulleted-list\">\n<li style=\"list-style-type:disc\"><code class=\"notion\">mcp-iag</code> (port <code class=\"notion\">8886</code>) protects the <strong>IndyKite MCP server</strong> - the demo agents reach ContX IQ and AuthZEN tools through it.</li>\n<li style=\"list-style-type:disc\"><code class=\"notion\">drive-mcp-iag</code> (port <code class=\"notion\">8887</code>) protects a <strong>Google Drive MCP server</strong> - a third-party server that knows nothing about IndyKite. This is the pair this tutorial builds.</li>\n<li style=\"list-style-type:disc\"><code class=\"notion\">erp-mcp-iag</code> (port <code class=\"notion\">8889</code>, compose profile <code class=\"notion\">erp</code>) protects a <strong>Postgres-backed ERP MCP server</strong> whose rows are pre-filtered per caller by the AuthZEN search/resource API before any SQL runs - the same recipe as Drive, applied to a database-backed server.</li>\n</ul>\n\n<h3 class=\"\">Mental model</h3>\n<pre class=\"code\"><code class=\"language-Text\">millicent (user token from your IdP)\n   │  MCP Streamable HTTP: initialize / tools/list / tools/call\n   ▼\ndrive-mcp-iag:8887/mcp\n   │  ── is the token active?                     ──&gt;  external IdP (introspection)\n   │  ── user token + gateway token → delegation  ──&gt;  external IdP (token exchange)\n   │  ── who is this user in the graph?           ──&gt;  IndyKite ContX IQ (whoami)\n   │  ── may User/millicent reach Agent/indykiteagent-drive\n   │     through the chain [indykiteagent-drive]? ──&gt;  IndyKite AuthZEN (KBAC over the IKG)\n   │  ── AUTHORIZED / NOT_AUTHORIZED              ──&gt;  audit stream\n   │  Authorization header replaced with the delegation token,\n   │  Mcp-Session-Id and SSE streamed through untouched\n   ▼\ndrive-mcp:8000/mcp  ──&gt;  Google Drive API (server's own Google credentials)</code></pre>\n\n<h3 class=\"\">What comes next</h3>\n<p class=\"notion\">Chapter 2 follows one MCP request through the gateway and lists the exact HTTP responses callers can get back.</p>",
      "links": {
        "html": "/tutorials/tutorial-agent-gateway-mcp#chapter-1",
        "markdown": "/tutorials/tutorial-agent-gateway-mcp/1.md"
      }
    },
    {
      "chapter": 2,
      "title": "How the gateway handles an MCP request",
      "description": "The runtime path of one MCP call through IAG, the token exchange at the external identity provider, the credential swap, and every HTTP response a caller can receive.",
      "body": "<h2 class=\"\">Chapter 2: How the gateway handles an MCP request</h2>\n\n<p class=\"notion\">Take one call - <code class=\"notion\">tools/call</code> with the Drive server's <code class=\"notion\">search</code> tool - sent to <code class=\"notion\">http://localhost:8887/mcp</code> with a user's Bearer token. The gateway runs the same sequence for every request in the session. Steps 2 to 4 talk to your identity provider, steps 5 and 6 to IndyKite:</p>\n\n<ol type=\"1\" class=\"numbered-list\" start=\"1\">\n<li><strong>Extract the Bearer token.</strong> No <code class=\"notion\">Authorization: Bearer</code> header means an immediate <code class=\"notion\">401</code>.</li>\n<li><strong>Introspect the token at the IdP.</strong> The token must be active and carry a subject.</li>\n<li><strong>Get the gateway's own token.</strong> With the client credentials grant, using the client configured for this instance (<code class=\"notion\">indykiteagent-drive</code>). The gateway keeps and reuses this token until shortly before it expires.</li>\n<li><strong>Exchange both for a delegation token.</strong> The IdP's token exchange (RFC 8693) takes the caller's token as the subject and the gateway's token as the actor, and returns one token: <code class=\"notion\">sub</code> is still the user, and <code class=\"notion\">act</code> names this gateway's client. When the caller's token was itself a delegation token from an earlier gateway, the IdP nests that token's <code class=\"notion\">act</code> inside the new one, so the chain grows by one client per hop. A request straight from millicent gives the chain <code class=\"notion\">[indykiteagent-drive]</code>; the same request arriving through the analyst gives <code class=\"notion\">[indykiteagent-4, indykiteagent-drive]</code>.</li>\n<li><strong>Resolve the subject with ContX IQ <code class=\"notion\">whoami</code>.</strong> The gateway sends the Bearer token to <code class=\"notion\">GET /contx-iq/v1/whoami</code> with its AppAgent credentials token and gets back the user's IKG node, for millicent <code class=\"notion\">{\"type\": \"User\", \"id\": \"millicent\"}</code>. The <code class=\"notion\">type</code> is the <code class=\"notion\">ikg_node_type</code> of the project's Token Introspect configuration whose <code class=\"notion\">jwt_matcher</code> matches the token's issuer and audience; without such a configuration the request ends in <code class=\"notion\">401</code>. Chapter 5 creates these configurations for your IdP.</li>\n<li><strong>Ask AuthZEN for the admission decision.</strong> One <code class=\"notion\">POST /access/v1/evaluation</code>: subject <code class=\"notion\">User</code>/<code class=\"notion\">millicent</code>, action <code class=\"notion\">CAN_TRIGGER</code>, resource <code class=\"notion\">Agent</code>/<code class=\"notion\">indykiteagent-drive</code> - the gateway's own client, the newest hop of the chain. The delegation token travels on that call in <code class=\"notion\">X-IK-Token</code>, so the KBAC policy reads the chain as <code class=\"notion\">$ik_token.act_chain</code> and compares it with the workflows in the graph (chapter 5). The gateway itself compares nothing: <code class=\"notion\">decision: false</code> means <code class=\"notion\">403</code>. With capability checks on, a request that lists or names a tool, resource or prompt gets the capability decision in place of this one (chapter 6).</li>\n<li><strong>Audit the decision.</strong> One record per decision, written before forwarding, on the configured audit stream (chapter 8).</li>\n<li><strong>Swap the credential and forward.</strong> The gateway <strong>replaces</strong> the caller's <code class=\"notion\">Authorization</code> header with the delegation token from step 4 and forwards the request to the server's endpoint - same query, same body, <code class=\"notion\">Mcp-Session-Id</code> untouched. The downstream's status code, headers, and (streamed) body go back to the caller as-is.</li>\n</ol>\n\n<p class=\"notion\">The decision of step 6 is kept per subject and chain for a configurable time, so follow-up requests of a session do not each cost a platform call. Introspection and the token exchange run on every request.</p>\n\n<h3 class=\"\">The credential swap, and what it means for your MCP server</h3>\n<p class=\"notion\">Because the gateway always replaces the <code class=\"notion\">Authorization</code> header, the protected MCP server never sees the caller's token - it sees the delegation token: the user as <code class=\"notion\">sub</code>, the chain of gateway clients as <code class=\"notion\">act</code>. Two consequences:</p>\n<ul class=\"bulleted-list\">\n<li style=\"list-style-type:disc\">An MCP server that requires the <strong>caller's own upstream credential</strong> (for example a hosted MCP endpoint that expects the caller's Google OAuth access token) will not work behind the gateway.</li>\n<li style=\"list-style-type:disc\">The downstream must hold <strong>its own credentials</strong> for whatever backend it talks to. The Google Drive server in this tutorial holds its own Google OAuth material (chapter 3) and simply ignores the incoming Bearer token. A server that wants to know who the request is for can read the delegation token instead - the ERP server of chapter 8 does.</li>\n</ul>\n\n<h3 class=\"\">Responses a caller can receive</h3>\n<table class=\"simple-table\">\n<tbody>\n<tr>\n<td class=\"simple-table-header-color\"><strong>Status</strong></td>\n<td class=\"simple-table-header-color\"><strong>Body / meaning</strong></td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">200</code> / <code class=\"notion\">202</code></td>\n<td class=\"\">Authorized and forwarded; this is the downstream MCP server's own response (JSON or SSE). With capability checks on, a list answer is filtered to what the caller may use.</td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">400</code>, <code class=\"notion\">413</code>, <code class=\"notion\">415</code></td>\n<td class=\"\">A JSON-RPC error from the gateway: the request is not one readable MCP message on a supported protocol revision (chapter 1).</td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">401</code></td>\n<td class=\"\"><code class=\"notion\">{\"message\":\"Missing bearer token\"}</code> when no token is sent. <code class=\"notion\">{\"message\":\"Unauthorized\",\"errors\":[\"identity provider: the token is not active\"]}</code> when the IdP reports the token expired or unknown. <code class=\"notion\">{\"message\":\"Unauthorized\",\"errors\":[\"ContX IQ whoami failed\"]}</code> when no Token Introspect configuration in the project matches the token, or the token fails its validation (step 5). Every <code class=\"notion\">401</code> carries <code class=\"notion\">WWW-Authenticate: Bearer resource_metadata=\"…\"</code>, the address of the gateway's OAuth protected resource metadata.</td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">403</code></td>\n<td class=\"\"><code class=\"notion\">{\"message\":\"Authorization check failed\"}</code> - the caller is authenticated but the admission policy answered no: no workflow this subject can trigger has the request's delegation chain as its path of agents. With capability checks on (chapter 6), also a JSON-RPC error under the request's id, <code class=\"notion\">-31403</code> <code class=\"notion\">Forbidden: the caller may not use the named tool</code> (or <code class=\"notion\">resource</code>, <code class=\"notion\">prompt</code>): the call names a capability outside the caller's permitted set.</td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">404</code></td>\n<td class=\"\"><code class=\"notion\">{\"message\":\"Not Found\"}</code> - the request went to a path other than the gateway's one MCP endpoint.</td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">500</code></td>\n<td class=\"\"><code class=\"notion\">{\"message\":\"Internal Server Error\"}</code> - the IdP or IndyKite could not be reached or timed out.</td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">502</code></td>\n<td class=\"\"><code class=\"notion\">{\"message\":\"Bad Gateway\",\"errors\":[…]}</code> - the downstream MCP server could not be reached.</td>\n</tr>\n</tbody>\n</table>\n\n<p class=\"notion\">A <code class=\"notion\">401</code> or <code class=\"notion\">403</code> that the IdP or IndyKite itself answers is passed through with an <code class=\"notion\">errors</code> entry naming the service, for example <code class=\"notion\">[\"identity provider: token exchange failed - …\"]</code>, so a wrong client secret or an invalid AppAgent credential is told apart from a denial; the audit record then says <code class=\"notion\">ERROR</code>, not <code class=\"notion\">NOT_AUTHORIZED</code>.</p>\n\n<p class=\"notion\">The <code class=\"notion\">401</code>-with-no-token response doubles as a liveness probe: an unauthenticated <code class=\"notion\">POST</code> to the gateway's endpoint answering <code class=\"notion\">{\"message\":\"Missing bearer token\"}</code> proves the instance is up and enforcing. Chapter 7 uses exactly this check.</p>\n\n<h3 class=\"\">What comes next</h3>\n<p class=\"notion\">Chapter 3 sets up the Google side: a Google Cloud project, the Drive API, and the OAuth material the Drive MCP server needs.</p>",
      "links": {
        "html": "/tutorials/tutorial-agent-gateway-mcp#chapter-2",
        "markdown": "/tutorials/tutorial-agent-gateway-mcp/2.md"
      }
    },
    {
      "chapter": 3,
      "title": "Set up Google Drive access",
      "description": "Create the Google Cloud OAuth client and mint the credentials the Drive MCP server uses to search Google Drive.",
      "body": "<h2 class=\"\">Chapter 3: Set up Google Drive access</h2>\n\n<p class=\"notion\">The Drive MCP server talks to the Google Drive API with <strong>its own</strong> Google OAuth credentials (chapter 2 explains why the caller's token never reaches it). This chapter produces the two credential files the server needs. Work from the demo directory:</p>\n\n<pre class=\"code\"><code class=\"language-Bash\">cd a2a/iag-mcp-demo</code></pre>\n\n<h3 class=\"\">1. Create a Google Cloud project and enable the Drive API</h3>\n<ol type=\"1\" class=\"numbered-list\" start=\"1\">\n<li>Go to <a href=\"https://console.cloud.google.com\" class=\"fancy-link\" target=\"_blank\">console.cloud.google.com</a>. A personal Google account is easiest: it can create projects freely, and the demo then searches that account's Drive.</li>\n<li>Create a project (for example <code class=\"notion\">iag-drive-demo</code>) and switch to it.</li>\n<li>Search for <strong>Google Drive API</strong> and click <strong>Enable</strong>.</li>\n</ol>\n\n<h3 class=\"\">2. Configure the OAuth consent screen</h3>\n<p class=\"notion\">Under <strong>APIs &amp; Services → OAuth consent screen</strong>: choose type <em>External</em>, fill the required fields, and under <strong>Test users</strong> add the Google account you will authorize with. While the app is in <em>Testing</em> status only test users can authenticate - anyone else gets \"Access blocked: app has not completed verification\".</p>\n\n<h3 class=\"\">3. Create the OAuth client and download the keys</h3>\n<ol type=\"1\" class=\"numbered-list\" start=\"1\">\n<li><strong>APIs &amp; Services → Credentials → Create credentials → OAuth client ID</strong> → application type <strong>Desktop app</strong> → Create → <strong>Download JSON</strong>.</li>\n<li>Save the download as <code class=\"notion\">drive_mcp/.gdrive/gcp-oauth.keys.json</code> inside the demo directory. This path is git-ignored.</li>\n</ol>\n\n<h3 class=\"\">4. Authorize once (browser flow)</h3>\n<p class=\"notion\">Run the one-time auth bootstrap on the host. It opens a browser and writes the refresh-token credentials file next to the keys:</p>\n\n<pre class=\"code\"><code class=\"language-Bash\">cd drive_mcp\nGDRIVE_OAUTH_PATH=$PWD/.gdrive/gcp-oauth.keys.json \\\nGDRIVE_CREDENTIALS_PATH=$PWD/.gdrive/.gdrive-server-credentials.json \\\nnpx -y @modelcontextprotocol/server-gdrive auth\ncd ..</code></pre>\n\n<p class=\"notion\">In the browser: pick the account (the project owner or a test user) → on the \"Google hasn't verified this app\" warning click <strong>Advanced</strong> → <strong>Go to &lt;app&gt; (unsafe)</strong> (it is your own app) → <strong>Allow</strong> read access to Drive. The granted scope is read-only (<code class=\"notion\">https://www.googleapis.com/auth/drive.readonly</code>).</p>\n\n<h3 class=\"\">5. Verify the credential files</h3>\n<pre class=\"code\"><code class=\"language-Bash\">ls -A drive_mcp/.gdrive/\n# expect both files (next to the repo's committed .gitkeep):\n#   gcp-oauth.keys.json\n#   .gdrive-server-credentials.json</code></pre>\n\n<p class=\"notion\">Both files must come from the <strong>same</strong> OAuth client. If you ever replace <code class=\"notion\">gcp-oauth.keys.json</code>, re-run step 4 - mismatched files fail later with <code class=\"notion\">invalid_request</code> on the first Drive call.</p>\n\n<h3 class=\"\">6. Seed some content</h3>\n<p class=\"notion\">Put a few files in that Google account's Drive so searches return something. The Drive server's <code class=\"notion\">search</code> tool is <strong>full-text over file contents</strong>, so a reliable trick is to create a Google Doc containing a unique word (for example <code class=\"notion\">canbank-test-fixture</code>) - searching for that word then always returns exactly that document.</p>\n\n<h3 class=\"\">What comes next</h3>\n<p class=\"notion\">Chapter 4 packages the Drive MCP server as a container the gateway can protect.</p>",
      "links": {
        "html": "/tutorials/tutorial-agent-gateway-mcp#chapter-3",
        "markdown": "/tutorials/tutorial-agent-gateway-mcp/3.md"
      }
    },
    {
      "chapter": 4,
      "title": "The Google Drive MCP server container",
      "description": "Wrap the reference stdio Drive MCP server into MCP Streamable HTTP so the gateway can proxy it.",
      "body": "<h2 class=\"\">Chapter 4: The Google Drive MCP server container</h2>\n\n<p class=\"notion\">The gateway proxies <strong>MCP Streamable HTTP</strong>, but the reference Google Drive MCP server speaks <strong>stdio</strong>. The demo bridges the two and exposes it as a stateful Streamable HTTP endpoint. This is a general recipe: any stdio MCP server can be put behind IAG the same way.</p>\n\n<h3 class=\"\">The image</h3>\n<p class=\"notion\">The <code class=\"notion\">drive_mcp/Dockerfile</code> in the demo installs <a href=\"https://github.com/supercorp-ai/supergateway\" class=\"fancy-link\" target=\"_blank\">supergateway</a>, a wrapper that serves a stdio MCP server over Streamable HTTP, and the Drive server vendored under <code class=\"notion\">drive_mcp/vendor/</code> - the reference <code class=\"notion\">server-gdrive</code> extended with two demo-friendly touches: <code class=\"notion\">search</code> results include the file ID, and <strong>PDF files are text-extracted on read</strong> instead of returned as opaque base64 (the reference server only exports Google-native docs as text). The wrapper runs with:</p>\n<ul class=\"bulleted-list\">\n<li style=\"list-style-type:disc\">MCP endpoint: <code class=\"notion\">http://drive-mcp:8000/mcp</code>. This full URL is what the gateway forwards to (<code class=\"notion\">protected_agent.base_url</code>, chapter 6).</li>\n<li style=\"list-style-type:disc\"><code class=\"notion\">--stateful</code>: the wrapper keeps one Drive server process per MCP session and mints an <code class=\"notion\">Mcp-Session-Id</code> per <code class=\"notion\">initialize</code>; the gateway passes it through both ways.</li>\n<li style=\"list-style-type:disc\">Health check: <code class=\"notion\">GET /healthz</code>.</li>\n</ul>\n\n<h3 class=\"\">The compose service</h3>\n<pre class=\"code\"><code class=\"language-YAML\">drive-mcp:\n  image: drive-mcp:latest\n  profiles: [\"drive\"]\n  ports:\n    - \"${DRIVE_MCP_PORT:-8000}:8000\"\n  networks:\n    - drive-mcp-iag-network\n  environment:\n    # Paths to the mounted Google OAuth material (values are paths, not secrets).\n    GDRIVE_OAUTH_PATH: /gdrive/gcp-oauth.keys.json\n    GDRIVE_CREDENTIALS_PATH: /gdrive/.gdrive-server-credentials.json\n  volumes:\n    - ./drive_mcp/.gdrive:/gdrive:ro</code></pre>\n\n<p class=\"notion\">The credential files from chapter 3 are mounted read-only. The server refreshes its Google access token from them automatically; the Bearer token the gateway injects on forwarded requests is simply ignored - exactly the arrangement chapter 2 requires. To put another Streamable HTTP Drive MCP server behind the gateway, set the gateway's <code class=\"notion\">JARVIS_PROTECTED_AGENT_BASE_URL</code> to that server's full endpoint URL: scheme, host, port and path. Changing <code class=\"notion\">DRIVE_MCP_HOST</code> alone is enough only when the replacement also serves HTTP on port <code class=\"notion\">8000</code> at <code class=\"notion\">/mcp</code>.</p>\n\n<h3 class=\"\">What the server exposes</h3>\n<table class=\"simple-table\">\n<tbody>\n<tr>\n<td class=\"simple-table-header-color\"><strong>Capability</strong></td>\n<td class=\"simple-table-header-color\"><strong>Behavior</strong></td>\n</tr>\n<tr>\n<td class=\"\">Tool <code class=\"notion\">search</code></td>\n<td class=\"\">Full-text search over file <em>contents</em> in the authorized account's Drive; returns up to 10 matches, one <code class=\"notion\">&lt;fileId&gt; &lt;name&gt; (&lt;mimeType&gt;)</code> line each.</td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">resources/list</code></td>\n<td class=\"\">Lists Drive files as resources with <code class=\"notion\">gdrive:///&lt;fileId&gt;</code> URIs.</td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">resources/read</code></td>\n<td class=\"\">Reads one file by URI. Google-native files (Docs, Sheets, Slides) are exported as text, and PDFs are text-extracted by the vendored server (an encrypted or scanned-image PDF falls back to base64). Other binaries (<code class=\"notion\">.doc</code>, video, …) come back base64-encoded, so point read prompts at Google-native or PDF copies.</td>\n</tr>\n</tbody>\n</table>\n\n<h3 class=\"\">Build it</h3>\n<pre class=\"code\"><code class=\"language-Bash\">make new-drive-mcp     # builds the drive-mcp image from ./drive_mcp</code></pre>\n\n<h3 class=\"\">What comes next</h3>\n<p class=\"notion\">The server is ready but nothing authorizes access to it yet. Chapter 5 models who may reach it, and through which chain, in the IKG.</p>",
      "links": {
        "html": "/tutorials/tutorial-agent-gateway-mcp#chapter-4",
        "markdown": "/tutorials/tutorial-agent-gateway-mcp/4.md"
      }
    },
    {
      "chapter": 5,
      "title": "Model the wf-drive workflow in the IKG",
      "description": "The IdP client, the Token Introspect configurations, the Workflow and Agent nodes, the CAN_TRIGGER grant, the INVOKES chain and the one admission policy that authorize Google Drive access - plus one workflow per call shape.",
      "body": "<h2 class=\"\">Chapter 5: Model the wf-drive workflow in the IKG</h2>\n\n<p class=\"notion\">The gateway admits an MCP request only when a workflow the subject can trigger has <strong>exactly the request's delegation chain</strong> as its path of agents. The chain comes from your identity provider's token exchange (chapter 2); the workflows, the agents and the grant live in the Identity Knowledge Graph (IKG); one KBAC policy compares the two. This chapter adds all of it for the Drive downstream. If you provision with instant-stack, everything here is already in your project - read the chapter to understand it, then jump to the <a href=\"#shortcut\" class=\"fancy-link\">shortcut</a>.</p>\n\n<h3 class=\"\">1. Register the client at your IdP</h3>\n<p class=\"notion\">Create a confidential machine-to-machine client <code class=\"notion\">indykiteagent-drive</code> at your IdP, allowed to use the client credentials grant and the token exchange; it needs no redirect URI. The gateway authenticates as this client, so the client's name ends up in the delegation chain. <strong>The value your IdP writes into <code class=\"notion\">sub</code> for this client's token must exactly match the Agent node's <code class=\"notion\">external_id</code></strong> - the admission policy compares the two. The demo's IdP uses the client ID, which is why the node is called <code class=\"notion\">indykiteagent-drive</code> too.</p>\n\n<h3 class=\"\">2. Tell IndyKite which tokens of your IdP to accept</h3>\n<p class=\"notion\">IndyKite reads a token only through a <strong>Token Introspect configuration</strong> whose <code class=\"notion\">jwt_matcher</code> equals the token's <code class=\"notion\">iss</code> and <code class=\"notion\">aud</code>. Two kinds of token reach the platform from a gateway, and each issuer and audience pair needs its own configuration:</p>\n<ul class=\"bulleted-list\">\n<li style=\"list-style-type:disc\">The <strong>Bearer token of the request</strong>, sent to <code class=\"notion\">whoami</code>. For a direct call to the Drive gateway that is millicent's login token, with the audience your IdP writes for the chatbot's login client (<code class=\"notion\">chatbot-mcp</code> in the demo).</li>\n<li style=\"list-style-type:disc\">The <strong>delegation token</strong> the IdP mints for this gateway, sent in <code class=\"notion\">X-IK-Token</code> on the admission call. Its audience is the gateway's client, <code class=\"notion\">indykiteagent-drive</code>.</li>\n</ul>\n<p class=\"notion\">On the longer chains, the Bearer token at the Drive gateway is the delegation token of the previous gateway, so those audiences (<code class=\"notion\">indykiteagent</code>, <code class=\"notion\">indykiteagent-4</code>) need a configuration as well. The canbank dataset carries one per audience. The <code class=\"notion\">ikg_node_type</code> is the node type <code class=\"notion\">whoami</code> answers with, and therefore the subject type of the policy in step 5. Created with Service Account credentials:</p>\n\n<pre class=\"code\"><code class=\"language-JSON\">POST /configs/v1/token-introspects\nAuthorization: Bearer &lt;service-account-token&gt;\n{\n  \"project_id\": \"&lt;PROJECT_GID&gt;\",\n  \"name\": \"canbank-delegated-indykiteagent-drive\",\n  \"display_name\": \"CanBank delegated token (Drive MCP gateway)\",\n  \"jwt_matcher\": {\n    \"issuer\": \"&lt;issuer of your IdP, exactly as in the iss claim&gt;\",\n    \"audience\": \"indykiteagent-drive\"\n  },\n  \"offline_validation\": {},\n  \"ikg_node_type\": \"User\"\n}</code></pre>\n\n<p class=\"notion\">Check a token the way the gateway will: <code class=\"notion\">GET /contx-iq/v1/whoami</code> with the AppAgent credential in <code class=\"notion\">X-IK-ClientKey</code> and <code class=\"notion\">Authorization: Bearer $TOKEN</code>. The answer <code class=\"notion\">{\"type\": \"User\", \"id\": \"millicent\"}</code> means the gateway will resolve it too; a <code class=\"notion\">401</code> means no configuration matches that token.</p>\n\n<h3 class=\"\">3. Create the nodes</h3>\n<p class=\"notion\">Via the Capture API (<code class=\"notion\">POST /capture/v1/nodes</code>, AppAgent credential in <code class=\"notion\">X-IK-ClientKey</code>) - one <code class=\"notion\">Workflow</code> and one <code class=\"notion\">Agent</code>. The user, <code class=\"notion\">millicent</code>, is already in the canbank dataset as a <code class=\"notion\">User</code> identity node whose <code class=\"notion\">external_id</code> equals the <code class=\"notion\">sub</code> of her token:</p>\n\n<pre class=\"code\"><code class=\"language-JSON\">{\n  \"nodes\": [\n    {\n      \"external_id\": \"wf-drive\",\n      \"type\": \"Workflow\",\n      \"is_identity\": false,\n      \"properties\": []\n    },\n    {\n      \"external_id\": \"indykiteagent-drive\",\n      \"type\": \"Agent\",\n      \"is_identity\": false,\n      \"properties\": []\n    }\n  ]\n}</code></pre>\n\n<h3 class=\"\">4. Create the relationships</h3>\n<p class=\"notion\">Via <code class=\"notion\">POST /capture/v1/relationships</code>. Two relationships matter: the <strong>grant</strong> (who may trigger the workflow) and the <strong>chain</strong> (which agent the workflow invokes). Every <code class=\"notion\">INVOKES</code> relationship in a chain must carry a <code class=\"notion\">workflow_name</code> property equal to the workflow's <code class=\"notion\">external_id</code> - the admission policy filters on it at every hop, so a chain without it admits no request.</p>\n\n<pre class=\"code\"><code class=\"language-JSON\">{\n  \"relationships\": [\n    {\n      \"source\": {\n        \"type\": \"User\",\n        \"external_id\": \"millicent\"\n      },\n      \"target\": {\n        \"type\": \"Workflow\",\n        \"external_id\": \"wf-drive\"\n      },\n      \"properties\": [],\n      \"type\": \"CAN_TRIGGER\"\n    },\n    {\n      \"source\": {\n        \"type\": \"Workflow\",\n        \"external_id\": \"wf-drive\"\n      },\n      \"target\": {\n        \"type\": \"Agent\",\n        \"external_id\": \"indykiteagent-drive\"\n      },\n      \"properties\": [\n        {\n          \"type\": \"workflow_name\",\n          \"value\": \"wf-drive\"\n        }\n      ],\n      \"type\": \"INVOKES\"\n    }\n  ]\n}</code></pre>\n\n<p class=\"notion\">In the demo dataset only <code class=\"notion\">millicent</code> gets this grant. Every other user is denied at the gateway - that asymmetry is the demo.</p>\n\n<h3 class=\"\">5. Create the admission policy</h3>\n<p class=\"notion\">One KBAC policy answers the gateway's question \"may this subject reach this agent through this chain?\". It is generic over all workflows and all gateways - if you already provisioned it for other gateway instances, there is nothing to add; <code class=\"notion\">wf-drive</code> is covered the moment it exists in the graph. The demo names it <code class=\"notion\">user-can-reach-agent</code>:</p>\n\n<pre class=\"code\"><code class=\"language-JSON\">{\n  \"meta\": {\n    \"policy_version\": \"2.0-kbac\"\n  },\n  \"subject\": {\n    \"type\": \"User\"\n  },\n  \"actions\": [\n    \"CAN_TRIGGER\"\n  ],\n  \"resource\": {\n    \"type\": \"Agent\"\n  },\n  \"condition\": {\n    \"cypher\": \"MATCH (subject:User)-[:WORKS_IN|CAN_TRIGGER*..3]-&gt;(wf:Workflow) MATCH (wf)-[rels:INVOKES*]-&gt;(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\"\n  }\n}</code></pre>\n\n<p class=\"notion\">Read the condition line by line:</p>\n<ul class=\"bulleted-list\">\n<li style=\"list-style-type:disc\"><strong>First <code class=\"notion\">MATCH</code></strong> - the subject can trigger a workflow, directly (<code class=\"notion\">User -CAN_TRIGGER-&gt; Workflow</code>, millicent's relationship from step 4) or through their department (<code class=\"notion\">User -WORKS_IN-&gt; Department -CAN_TRIGGER-&gt; Workflow</code>).</li>\n<li style=\"list-style-type:disc\"><strong>Second <code class=\"notion\">MATCH</code></strong> - that workflow's <code class=\"notion\">INVOKES</code> path ends at the resource, the agent this gateway protects.</li>\n<li style=\"list-style-type:disc\"><strong><code class=\"notion\">WHERE</code></strong> - every hop of the path belongs to this workflow (<code class=\"notion\">workflow_name</code>), and the agents on the path, in order, equal <code class=\"notion\">$ik_token.act_chain</code>: the chain of the delegation token the gateway sent in <code class=\"notion\">X-IK-Token</code>.</li>\n</ul>\n<p class=\"notion\">So the policy sees both worlds at once: the chain your IdP wrote into the token, and the chain you modelled in the graph. Create it with <code class=\"notion\">POST /configs/v1/authorization-policies</code> (Service Account credentials; the policy above as a JSON string in <code class=\"notion\">policy</code>, <code class=\"notion\">status</code> <code class=\"notion\">ACTIVE</code>). The policy's subject type must be the <code class=\"notion\">ikg_node_type</code> of step 2: a user whose token matches a configuration with another type, such as <code class=\"notion\">Person</code>, needs a policy for that type.</p>\n\n<p class=\"notion\">Replay the gateway's question by hand to test the model, with a delegation token of the Drive hop in <code class=\"notion\">X-IK-Token</code>:</p>\n\n<pre class=\"code\"><code class=\"language-JSON\">POST /access/v1/evaluation\nX-IK-ClientKey: &lt;app-agent-credentials-token&gt;\nAuthorization: Bearer &lt;millicent's token&gt;\nX-IK-Token: &lt;delegation token of the Drive hop&gt;\n{\n  \"subject\": {\n    \"type\": \"User\",\n    \"id\": \"millicent\"\n  },\n  \"action\": {\n    \"name\": \"CAN_TRIGGER\"\n  },\n  \"resource\": {\n    \"type\": \"Agent\",\n    \"id\": \"indykiteagent-drive\"\n  }\n}</code></pre>\n<pre class=\"code\"><code class=\"language-JSON\">{\n  \"decision\": true\n}</code></pre>\n\n<p class=\"notion\">Admission is not the dataset&#x27;s only policy. It also provisions <code class=\"notion\">user-can-trigger-workflow</code> (subject <code class=\"notion\">User</code>, action <code class=\"notion\">CAN_TRIGGER</code>, resource <code class=\"notion\">Workflow</code>, condition <code class=\"notion\">MATCH (subject:User)-[:WORKS_IN|CAN_TRIGGER*..3]-&gt;(resource:Workflow)</code>), which the chatbot uses for the grant button of chapter 8, the capability policies <code class=\"notion\">user-can-use-*</code> of chapter 6, and <code class=\"notion\">user-can-retrieve-quote</code> (<code class=\"notion\">2.0-kbac</code>): subject <code class=\"notion\">User</code>, action <code class=\"notion\">CAN_RETRIEVE</code>, resource <code class=\"notion\">Quote</code> (id <code class=\"notion\">stock_quote</code>), condition <code class=\"notion\">MATCH (subject:User)-[:WORKS_IN]-&gt;(department:Department)-[:CAN_RETRIEVE]-&gt;(resource:Quote)</code>. Only the <code class=\"notion\">trading</code> department holds the <code class=\"notion\">CAN_RETRIEVE</code> relationship, and <code class=\"notion\">millicent</code> works in both <code class=\"notion\">support</code> and <code class=\"notion\">trading</code> - this is what powers the stock-quote and AuthZEN prompts in chapter 7.</p>\n\n<h3 class=\"\">One workflow per call shape</h3>\n<p class=\"notion\">A workflow holds <strong>exactly one agent chain</strong>, and the policy wants the request's chain to equal it. If the same protected agent should be reachable through several different chains - directly, via another agent, via a console orchestrator - model each shape as its own workflow. The demo wires four:</p>\n\n<table class=\"simple-table\">\n<tbody>\n<tr>\n<td class=\"simple-table-header-color\"><strong>Workflow</strong></td>\n<td class=\"simple-table-header-color\"><strong>Chain</strong></td>\n<td class=\"simple-table-header-color\"><strong>Used by</strong></td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">wf-drive</code></td>\n<td class=\"\"><code class=\"notion\">indykiteagent-drive</code></td>\n<td class=\"\">Direct MCP calls to the Drive gateway (chapter 7).</td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">wf-drive-analyst</code></td>\n<td class=\"\"><code class=\"notion\">indykiteagent-4 → indykiteagent-drive</code></td>\n<td class=\"\">A prompt to the analyst agent, which calls Drive as an MCP backend.</td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">wf-drive-console</code></td>\n<td class=\"\"><code class=\"notion\">indykiteagent → indykiteagent-4 → indykiteagent-drive</code></td>\n<td class=\"\">The chatbot console: orchestrator → analyst → Drive.</td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">wf3-console</code></td>\n<td class=\"\"><code class=\"notion\">indykiteagent → indykiteagent-4 → indykiteagent-mcp</code></td>\n<td class=\"\">The console-routed analyst reaching the IndyKite MCP server.</td>\n</tr>\n</tbody>\n</table>\n\n<p class=\"notion\">When two workflows share an agent-to-agent hop (for example <code class=\"notion\">indykiteagent-4 → indykiteagent-drive</code> in both the analyst and console shapes), create <strong>parallel <code class=\"notion\">INVOKES</code> relationships</strong> - one per workflow - and add a <code class=\"notion\">discriminating_property</code> property with value <code class=\"notion\">workflow_name</code> to each, so the relationships stay distinct per workflow:</p>\n\n<pre class=\"code\"><code class=\"language-JSON\">{\n  \"source\": {\n    \"type\": \"Agent\",\n    \"external_id\": \"indykiteagent-4\"\n  },\n  \"target\": {\n    \"type\": \"Agent\",\n    \"external_id\": \"indykiteagent-drive\"\n  },\n  \"properties\": [\n    {\n      \"type\": \"workflow_name\",\n      \"value\": \"wf-drive-analyst\"\n    },\n    {\n      \"type\": \"discriminating_property\",\n      \"value\": \"workflow_name\"\n    }\n  ],\n  \"type\": \"INVOKES\"\n}</code></pre>\n\n<p class=\"notion\">Grant <code class=\"notion\">CAN_TRIGGER</code> per shape as well - in the demo, <code class=\"notion\">millicent</code> holds it on all three <code class=\"notion\">wf-drive*</code> workflows. A token carries the chain, not a workflow name: admission asks only whether the resulting chain is the path of a workflow the subject can trigger. Workflows that share their first agents therefore share those hops - a request that passed the orchestrator and the analyst for <code class=\"notion\">wf3-console</code> has the chain <code class=\"notion\">[indykiteagent, indykiteagent-4]</code>, which is also the start of <code class=\"notion\">wf-drive-console</code>, and continuing to the Drive gateway is admitted for a subject who can trigger that workflow. A chain that is the path of no workflow the subject can trigger is refused with <code class=\"notion\">403</code>.</p>\n\n<h3 id=\"shortcut\" class=\"\">Provisioning shortcut</h3>\n<p class=\"notion\">The <a href=\"https://github.com/indykite/developer-hub/tree/master/instant-stack\" class=\"fancy-link\" target=\"_blank\">instant-stack</a> companion app provisions everything in this chapter - and the rest of the project - from the canbank dataset (<code class=\"notion\">DATASET=canbank</code>). Its manifest covers the application and AppAgent (with credentials), the Token Introspect configurations (one per token audience), the MCP server configuration, the graph capture (nodes and relationships, including all the <code class=\"notion\">wf-drive*</code> workflows and <code class=\"notion\">indykiteagent-drive</code> with their <code class=\"notion\">workflow_name</code> / <code class=\"notion\">discriminating_property</code> relationships, and the <code class=\"notion\">search</code> tool node of chapter 6), the KBAC policies (admission and capability policies included), the external data resolvers, and every ContX IQ policy and knowledge query. The values it creates are where chapter 7's env values come from. A provisioning run creates what is missing and upserts the graph; it does not rewrite a configuration that already exists in the project. To change an existing policy or Token Introspect configuration, such as its <code class=\"notion\">jwt_matcher.issuer</code>, update it through the Config API (<code class=\"notion\">PUT /configs/v1/token-introspects/{id}</code>, <code class=\"notion\">PUT /configs/v1/authorization-policies/{id}</code>). The Drive data is inert while the <code class=\"notion\">drive</code> compose profile is off, so the same provisioning serves the base demo too.</p>\n<p class=\"notion\">The Token Introspect configurations of the dataset name the issuer of the demo's IdP. Running against your own provider, set <code class=\"notion\">jwt_matcher.issuer</code> to your issuer and the audiences to the ones your provider writes, as in step 2.</p>\n<p class=\"notion\">The demo repo also carries the same data request-by-request as a Bruno collection (<code class=\"notion\">bruno/iag-demo</code>: Token Introspect under <code class=\"notion\">token-introspect</code>, workflow graph under <code class=\"notion\">ingest/agent-workflow</code>, policies under <code class=\"notion\">authzen</code>) - useful as a manual alternative or for debugging a single element.</p>\n\n<h3 class=\"\">What comes next</h3>\n<p class=\"notion\">Chapter 6 configures the gateway instance that enforces all of this: <code class=\"notion\">drive-mcp-iag</code>.</p>",
      "links": {
        "html": "/tutorials/tutorial-agent-gateway-mcp#chapter-5",
        "markdown": "/tutorials/tutorial-agent-gateway-mcp/5.md"
      }
    },
    {
      "chapter": 6,
      "title": "Configure the drive-mcp-iag gateway",
      "description": "The shared settings that point every gateway at your identity provider and at IndyKite, the per-instance settings that switch IAG into MCP proxy mode in front of the Drive server, and how capability checks apply to it.",
      "body": "<h2 class=\"\">Chapter 6: Configure the drive-mcp-iag gateway</h2>\n\n<p class=\"notion\">The gateway takes its configuration from a YAML file passed with <code class=\"notion\">--config</code>, from environment variables, or both. Every config path maps to an environment variable with the fixed <code class=\"notion\">JARVIS_</code> prefix: uppercase the path and replace dots with underscores, so <code class=\"notion\">protected_agent.protocol</code> becomes <code class=\"notion\">JARVIS_PROTECTED_AGENT_PROTOCOL</code>. The demo splits the settings in two: a shared base service (<code class=\"notion\">iag-base-docker.yaml</code>) holds what is the same for every gateway - the image, your identity provider, IndyKite - and each instance in <code class=\"notion\">docker-compose.yaml</code> adds only what is its own.</p>\n\n<h3 class=\"\">The image</h3>\n<p class=\"notion\">The gateway is published as <code class=\"notion\">indykite/agent-gateway</code> by <a href=\"https://hub.docker.com/u/indykite\" class=\"fancy-link\" target=\"_blank\">IndyKite on Docker Hub</a>. All gateways of the demo share one image, named once in the env file (chapter 7):</p>\n<pre class=\"code\"><code class=\"language-Bash\">AGENT_GATEWAY_IMAGE=indykite/agent-gateway:&lt;version&gt;</code></pre>\n<p class=\"notion\">To move to a newer release, change the tag and run <code class=\"notion\">docker compose pull</code>. On Apple Silicon, add <code class=\"notion\">platform: linux/amd64</code> to the <code class=\"notion\">iag-base</code> service if Docker reports a platform mismatch.</p>\n\n<h3 class=\"\">The shared base: your IdP and IndyKite</h3>\n<p class=\"notion\">These settings are inherited by every gateway. The first block is where an external identity provider plugs in: one base URL, three endpoint paths under it, and the issuer.</p>\n<pre class=\"code\"><code class=\"language-YAML\">iag-base:\n  image: ${AGENT_GATEWAY_IMAGE}\n  environment:\n    # Your identity provider: introspects the bearer token, issues each gateway\n    # its client credentials token, and mints the delegation token (RFC 8693).\n    JARVIS_IDENTITY_PROVIDER_BASE_URL: \"${IDP_BASE_URL}\"\n    JARVIS_IDENTITY_PROVIDER_INTROSPECT_ENDPOINT: \"&lt;introspection path&gt;\"\n    JARVIS_IDENTITY_PROVIDER_CLIENT_CREDENTIAL_ENDPOINT: \"&lt;token path&gt;\"\n    JARVIS_IDENTITY_PROVIDER_EXCHANGE_ENDPOINT: \"&lt;token path&gt;\"\n    # The issuer, exactly as in the iss claim of the IdP's tokens. MCP gateways\n    # name it as the authorization server in their protected resource metadata.\n    JARVIS_IDENTITY_PROVIDER_ISSUER: \"${IDP_ISSUER}\"\n    JARVIS_IDENTITY_PROVIDER_OPENID_CONFIGURATION_URL: \"${IDP_ISSUER}/.well-known/openid-configuration\"\n    # IndyKite: whoami resolves the subject, AuthZEN takes the admission decision.\n    JARVIS_CONTX_IQ_BASE_URL: ${INDYKITE_BASE_URL}/contx-iq/v1\n    JARVIS_CONTX_IQ_APP_AGENT_CREDENTIALS_TOKEN: ${APP_AGENT_CREDENTIALS_TOKEN}\n    JARVIS_AUTHZEN_BASE_URL: ${INDYKITE_BASE_URL}/access/v1\n    JARVIS_AUTHZEN_ACTION: CAN_TRIGGER\n    # Capability checks, on by default; the Drive gateway overrides this below.\n    JARVIS_AUTHZEN_CAPABILITIES_ENABLED: ${IAG_CAPABILITY_CHECKS:-true}\n    # How long a decision is kept per subject and chain.\n    JARVIS_AUTHZEN_CACHE_TTL: ${IAG_AUTHZEN_CACHE_TTL:-30s}\n    JARVIS_AUTHZEN_CACHE_UPDATE_AFTER: ${IAG_AUTHZEN_CACHE_TTL:-30s}</code></pre>\n<p class=\"notion\">The repo's file carries the endpoint paths and default URLs of the demo's own IdP. With another provider, set <code class=\"notion\">IDP_BASE_URL</code> and <code class=\"notion\">IDP_ISSUER</code> in the env file and replace the three endpoint paths with your provider's; the gateway authenticates to all three with HTTP Basic client authentication. Two more places name the provider. The chatbot's login: its <code class=\"notion\">ID_SERVER_AUTHORIZE_ENDPOINT</code> and <code class=\"notion\">ID_SERVER_TOKEN_ENDPOINT</code> in <code class=\"notion\">docker-compose.yaml</code>, and the logout address it builds in <code class=\"notion\">chatbot/app.py</code>, which is the demo provider's own. And the project's Token Introspect configurations, whose issuer and audiences must be your provider's (chapter 5). Note what is <strong>not</strong> here: no workflow setting and no subject type. The subject type comes from <code class=\"notion\">whoami</code>, and which workflows a gateway serves is decided by the admission policy alone.</p>\n\n<h3 class=\"\">The compose service</h3>\n<pre class=\"code\"><code class=\"language-YAML\">drive-mcp-iag:\n  extends:\n    service: iag-base\n    file: iag-base-docker.yaml\n  profiles: [\"drive\"]\n  ports:\n    - \"${IAG_DRIVE_MCP_PORT:-8887}:${IAG_DRIVE_MCP_PORT:-8887}\"\n  networks:\n    - drive-mcp-iag-network\n  environment:\n    JARVIS_SERVICE_NAME: drive-mcp-iag\n    JARVIS_SERVICE_PORT: ${IAG_DRIVE_MCP_PORT:-8887}\n    # Switch from the default \"a2a\" proxy into MCP proxy mode.\n    JARVIS_PROTECTED_AGENT_PROTOCOL: mcp\n    # The public MCP endpoint at the gateway, and the MCP endpoint of the\n    # Drive server it forwards to. Both are full URLs, path included.\n    JARVIS_SERVICE_BASE_URL: http://${IAG_DRIVE_MCP_HOST:-drive-mcp-iag}:${IAG_DRIVE_MCP_PORT:-8887}/mcp\n    JARVIS_PROTECTED_AGENT_BASE_URL: http://${DRIVE_MCP_HOST:-drive-mcp}:8000/mcp\n    # Admission only on this gateway; see \"Capability checks\" below.\n    JARVIS_AUTHZEN_CAPABILITIES_ENABLED: ${IAG_DRIVE_CAPABILITY_CHECKS:-false}\n    JARVIS_PROTECTED_AGENT_AUTHENTICATION_CLIENT_ID: ${DRIVE_MCP_IDP_CLIENT_ID:-indykiteagent-drive}\n    JARVIS_PROTECTED_AGENT_AUTHENTICATION_CLIENT_SECRET: ${DRIVE_MCP_IDP_CLIENT_SECRET:-}\n  # Audit delivery is configured per instance via a mounted config file.\n  volumes:\n    - ./audit-config.yaml:/app/.configs/audit-config.yaml\n  command: [\"--config=/app/.configs/audit-config.yaml\"]</code></pre>\n\n<h3 class=\"\">The per-instance fields</h3>\n<table class=\"simple-table\">\n<tbody>\n<tr>\n<td class=\"simple-table-header-color\"><strong>Setting</strong></td>\n<td class=\"simple-table-header-color\"><strong>Value for this instance</strong></td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">service.name</code></td>\n<td class=\"\"><code class=\"notion\">drive-mcp-iag</code> - also stamped on every audit record.</td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">service.port</code></td>\n<td class=\"\"><code class=\"notion\">8887</code>.</td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">protected_agent.protocol</code></td>\n<td class=\"\"><code class=\"notion\">mcp</code>.</td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">service.base_url</code></td>\n<td class=\"\"><code class=\"notion\">http://drive-mcp-iag:8887/mcp</code> - the public URL of the MCP endpoint at the gateway. Its path, <code class=\"notion\">/mcp</code>, is the one path the gateway serves; every other path answers <code class=\"notion\">404</code>. It is also the <code class=\"notion\">resource</code> of the gateway's OAuth protected resource metadata.</td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">protected_agent.base_url</code></td>\n<td class=\"\"><code class=\"notion\">http://drive-mcp:8000/mcp</code> - the full URL of the Drive server's MCP endpoint, not its address alone.</td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">protected_agent.authentication.client_id</code> / <code class=\"notion\">client_secret</code></td>\n<td class=\"\">The <code class=\"notion\">indykiteagent-drive</code> IdP client from chapter 5.</td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">authzen.capabilities.enabled</code></td>\n<td class=\"\"><code class=\"notion\">false</code> through <code class=\"notion\">IAG_DRIVE_CAPABILITY_CHECKS</code>: this gateway decides on admission alone.</td>\n</tr>\n</tbody>\n</table>\n\n<p class=\"notion\">A gateway in MCP mode does not start without <code class=\"notion\">service.base_url</code>, <code class=\"notion\">protected_agent.base_url</code> and <code class=\"notion\">identity_provider.issuer</code>; when one is missing or invalid, the gateway's log names it. <strong>Audit delivery</strong> comes from the mounted <code class=\"notion\">audit-config.yaml</code> shown above - the same file every gateway in the demo mounts; without an <code class=\"notion\">audit</code> section in a config file the instance writes no audit records, and chapter 8 has nothing to read.</p>\n\n<p class=\"notion\"><strong>Decision caching:</strong> each gateway keeps its admission decisions and permitted sets per subject and delegation chain for <code class=\"notion\">authzen.cache_ttl</code>, which the demo sets to 30 seconds through <code class=\"notion\">IAG_AUTHZEN_CACHE_TTL</code>. The practical consequence: a <code class=\"notion\">CAN_TRIGGER</code> relationship added or removed in the graph (chapter 8's grant/revoke flow) reaches a gateway's decisions within that window - or immediately after restarting the affected gateways (<code class=\"notion\">docker compose restart orchestrator-iag analyst-iag drive-mcp-iag</code>). The platform's own AuthZEN answers change at once; only the gateway cache lags.</p>\n\n<h3 class=\"\">.env entries</h3>\n\n<p class=\"notion\">These go into the usecase's env file, <code class=\"notion\">.env.canbank</code> - the demo keeps one complete env file per usecase and symlinks <code class=\"notion\">.env</code> to the active one (chapter 7).</p>\n\n<pre class=\"code\"><code class=\"language-Bash\"># The gateway image for all gateways.\nAGENT_GATEWAY_IMAGE=indykite/agent-gateway:&lt;version&gt;\n# Your identity provider: base URL of its OAuth endpoints, and its issuer\n# exactly as written into the iss claim of its tokens.\nIDP_BASE_URL=&lt;idp-base-url&gt;\nIDP_ISSUER=&lt;idp-issuer&gt;\n# Include the two drive services in a plain `docker compose up`\n# (equivalent to `docker compose --profile drive up`); leave empty for the base demo.\nCOMPOSE_PROFILES=drive\n# IdP client for drive-mcp-iag's client-credentials / token-exchange flow.\nDRIVE_MCP_IDP_CLIENT_ID=indykiteagent-drive\nDRIVE_MCP_IDP_CLIENT_SECRET=&lt;secret from your IdP&gt;\n# Capability checks of the Drive gateway; false = admission only (see below).\nIAG_DRIVE_CAPABILITY_CHECKS=false\n# Optional: how long a gateway keeps a decision before asking IndyKite again,\n# i.e. how fast a grant or revoke reaches the gateways (default 30s).\nIAG_AUTHZEN_CACHE_TTL=30s\n# Read by the chatbot only, for its \"why?\" cards; leave empty for Drive.\nDRIVE_WORKFLOW_ID=\n# Give the analyst agent both MCP backends (alias=url pairs). Write the\n# project gid unencoded (gid:..., not gid%3A...).\n# Tool names get prefixed per backend: indykite_ciq_execute, drive_search, ...\nANALYST_MCP_SERVER_URLS=indykite=http://mcp-iag:8886/mcp/v1/&lt;PROJECT_GID&gt;,drive=http://drive-mcp-iag:8887/mcp\n# Optional: enable the chatbot's grant/revoke buttons on DENY cards (chapter 8).\n# Per gateway, the workflows one click grants (colon-separated); empty = buttons off.\n# Only the chatbot reads this - the gateways take no workflow setting.\nGRANT_WORKFLOW_MAP=drive-mcp-iag=wf-drive:wf-drive-analyst:wf-drive-console\n# Optional: enable the \"why?\" buttons on audit cards (chapter 8) - the GIDs of the\n# two explain queries provisioned with the canbank dataset.\nEXPLAIN_STAFF_QUERY_ID=&lt;gid-of-explain-staff-workflow-access&gt;\nEXPLAIN_DIRECT_QUERY_ID=&lt;gid-of-explain-direct-workflow-access&gt;</code></pre>\n\n<p class=\"notion\">The env file holds secrets - client secrets, the AppAgent credentials token, an LLM key. It is gitignored in the demo; keep it out of commits, images and screenshots.</p>\n\n<h3 id=\"capability-checks\" class=\"\">Capability checks: off for Drive, and how to turn them on</h3>\n<p class=\"notion\">In front of an MCP server the gateway makes a second decision beside admission, on by default: <strong>capability checks</strong>. It reads which tools, resources and prompts the caller may use, with one AuthZEN resource search per kind (action <code class=\"notion\">CAN_USE</code>, resource types <code class=\"notion\">Tool</code>, <code class=\"notion\">McpResource</code> and <code class=\"notion\">Prompt</code>), filters <code class=\"notion\">tools/list</code>, <code class=\"notion\">resources/list</code> and <code class=\"notion\">prompts/list</code> to that permitted set, and refuses a <code class=\"notion\">tools/call</code>, <code class=\"notion\">resources/read</code> or <code class=\"notion\">prompts/get</code> outside it with <code class=\"notion\">403</code> and the JSON-RPC error <code class=\"notion\">-31403</code>, without calling the server. Such a request gets the capability decision in place of the admission decision. The <a href=\"/guides/guide-agent-gateway#capability-checks\" class=\"fancy-link\">Agent Gateway guide</a> has the full contract.</p>\n\n<h4 class=\"\">Why the demo runs Drive with the checks off</h4>\n<p class=\"notion\">The Drive server lists its files as resources with <code class=\"notion\">gdrive:///&lt;fileId&gt;</code> URIs, a set that changes with the account's Drive. With the checks on, each file a user may read would have to exist in the graph as an <code class=\"notion\">McpResource</code> node named by that URI, or <code class=\"notion\">resources/list</code> stays empty and <code class=\"notion\">resources/read</code> is refused. So <code class=\"notion\">IAG_DRIVE_CAPABILITY_CHECKS</code> defaults to <code class=\"notion\">false</code>: admission decides who reaches Drive, and an admitted user may use everything the server offers. The audit trail of chapter 8 is unchanged by this setting. The demo's other MCP gateways, <code class=\"notion\">mcp-iag</code> and <code class=\"notion\">erp-mcp-iag</code>, keep the checks on.</p>\n\n<h4 class=\"\">Turning them on: only <code class=\"notion\">search</code> passes</h4>\n<p class=\"notion\">Set <code class=\"notion\">IAG_DRIVE_CAPABILITY_CHECKS=true</code> and recreate the gateway (<code class=\"notion\">docker compose up -d --force-recreate drive-mcp-iag</code>) to see the checks at work. The canbank dataset already models the one tool the walkthrough calls: a <code class=\"notion\">Tool</code> node <code class=\"notion\">search</code>, whose <code class=\"notion\">external_id</code> is the tool name exactly as the protocol carries it, attached to <code class=\"notion\">indykiteagent-drive</code> with one <code class=\"notion\">HAS</code> relationship per workflow shape. Each carries the <code class=\"notion\">workflow_name</code> that confines it to that shape and, like the parallel <code class=\"notion\">INVOKES</code> relationships of chapter 5, a <code class=\"notion\">discriminating_property</code> naming it, so that Capture keeps the three relationships apart instead of overwriting one with the next:</p>\n<pre class=\"code\"><code class=\"language-JSON\">POST /capture/v1/nodes\n{\n  \"nodes\": [\n    {\n      \"external_id\": \"search\",\n      \"type\": \"Tool\",\n      \"is_identity\": false,\n      \"properties\": []\n    }\n  ]\n}</code></pre>\n<pre class=\"code\"><code class=\"language-JSON\">POST /capture/v1/relationships\n{\n  \"relationships\": [\n    {\n      \"source\": { \"type\": \"Agent\", \"external_id\": \"indykiteagent-drive\" },\n      \"target\": { \"type\": \"Tool\", \"external_id\": \"search\" },\n      \"properties\": [\n        { \"type\": \"workflow_name\", \"value\": \"wf-drive\" },\n        { \"type\": \"discriminating_property\", \"value\": \"workflow_name\" }\n      ],\n      \"type\": \"HAS\"\n    },\n    {\n      \"source\": { \"type\": \"Agent\", \"external_id\": \"indykiteagent-drive\" },\n      \"target\": { \"type\": \"Tool\", \"external_id\": \"search\" },\n      \"properties\": [\n        { \"type\": \"workflow_name\", \"value\": \"wf-drive-analyst\" },\n        { \"type\": \"discriminating_property\", \"value\": \"workflow_name\" }\n      ],\n      \"type\": \"HAS\"\n    },\n    {\n      \"source\": { \"type\": \"Agent\", \"external_id\": \"indykiteagent-drive\" },\n      \"target\": { \"type\": \"Tool\", \"external_id\": \"search\" },\n      \"properties\": [\n        { \"type\": \"workflow_name\", \"value\": \"wf-drive-console\" },\n        { \"type\": \"discriminating_property\", \"value\": \"workflow_name\" }\n      ],\n      \"type\": \"HAS\"\n    }\n  ]\n}</code></pre>\n<p class=\"notion\">The dataset's KBAC policy for the <code class=\"notion\">Tool</code> type, <code class=\"notion\">user-can-use-tool</code>, has the action <code class=\"notion\">CAN_USE</code>. Its condition repeats the admission condition and ends at the tool, so a non-empty set proves admission too:</p>\n<pre class=\"code\"><code class=\"language-JSON\">{\n  \"meta\": {\n    \"policy_version\": \"2.0-kbac\"\n  },\n  \"subject\": {\n    \"type\": \"User\"\n  },\n  \"actions\": [\n    \"CAN_USE\"\n  ],\n  \"resource\": {\n    \"type\": \"Tool\"\n  },\n  \"condition\": {\n    \"cypher\": \"MATCH (subject:User)-[:WORKS_IN|CAN_TRIGGER*..3]-&gt;(wf:Workflow) MATCH (wf)-[rels:INVOKES*]-&gt;(agent:Agent)-[h:HAS]-&gt;(resource:Tool) 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\"\n  }\n}</code></pre>\n<p class=\"notion\">With the checks on, <code class=\"notion\">tools/list</code> shows <code class=\"notion\">search</code> to millicent and an empty list to a user without the grant, a <code class=\"notion\">tools/call</code> of any other name is refused with <code class=\"notion\">403</code> and <code class=\"notion\">-31403</code> before it reaches the server, and chapter 8's trail gains a <code class=\"notion\">DISCOVERY</code> record per list and an <code class=\"notion\">INVOCATION</code> record per call, each with the permitted set or the tool it named. <code class=\"notion\">resources/list</code> comes back empty and <code class=\"notion\">resources/read</code> is refused, for millicent too: no Drive file is modelled. To allow file reads under the checks, model the files a user may read as <code class=\"notion\">McpResource</code> nodes with their <code class=\"notion\">gdrive:///&lt;fileId&gt;</code> URIs as <code class=\"notion\">external_id</code>, attached the same way; the dataset's <code class=\"notion\">user-can-use-mcp-resource</code> policy then covers them.</p>\n\n<h3 class=\"\">What comes next</h3>\n<p class=\"notion\">Chapter 7 starts the stack and runs a Google Drive search through the gateway.</p>",
      "links": {
        "html": "/tutorials/tutorial-agent-gateway-mcp#chapter-6",
        "markdown": "/tutorials/tutorial-agent-gateway-mcp/6.md"
      }
    },
    {
      "chapter": 7,
      "title": "Run a Google Drive search through the gateway",
      "description": "Start the stack, establish an MCP session against drive-mcp-iag, and execute the full-text search - by script, by hand, and by prompt.",
      "body": "<h2 class=\"\">Chapter 7: Run a Google Drive search through the gateway</h2>\n\n<h3 class=\"\">1. Configure the usecase env file</h3>\n<p class=\"notion\">The demo keeps one <strong>complete env file per usecase</strong> (<code class=\"notion\">.env.canbank</code>, gitignored) and <code class=\"notion\">.env</code> is a symlink to the active one - so a switch always swaps the platform bindings, the domain vocabulary, and the agent skills together. First run only: bootstrap <code class=\"notion\">.env.canbank</code> from the committed template and fill in the base values per the repo README, then add the entries from chapter 6 (including <code class=\"notion\">AGENT_GATEWAY_IMAGE</code> and <code class=\"notion\">COMPOSE_PROFILES=drive</code>). Take the project-specific values from the instant-stack provisioning output (chapter 5).</p>\n\n<table class=\"simple-table\">\n<tbody>\n<tr>\n<td class=\"simple-table-header-color\"><strong>Where it comes from</strong></td>\n<td class=\"simple-table-header-color\"><strong>Variables</strong></td>\n</tr>\n<tr>\n<td class=\"\">Your IndyKite project</td>\n<td class=\"\"><code class=\"notion\">INDYKITE_BASE_URL</code> (the API URL of your region), <code class=\"notion\">APP_AGENT_CREDENTIALS_TOKEN</code>, and <code class=\"notion\">MCP_SERVER_ORIGIN</code> / <code class=\"notion\">MCP_SERVER_PATH</code> / <code class=\"notion\">MCP_SERVER_URL</code> for the IndyKite MCP server, with the path <code class=\"notion\">/mcp/v1/&lt;PROJECT_GID&gt;</code> and the gid written unencoded (<code class=\"notion\">gid:...</code>, not <code class=\"notion\">gid%3A...</code>).</td>\n</tr>\n<tr>\n<td class=\"\">Your identity provider</td>\n<td class=\"\"><code class=\"notion\">IDP_BASE_URL</code>, <code class=\"notion\">IDP_ISSUER</code>, and one client ID and secret per client: <code class=\"notion\">CHATBOT_IDP_*</code> (<code class=\"notion\">console</code>), <code class=\"notion\">ORCHESTRATOR_IDP_*</code>, <code class=\"notion\">RETRIEVER_IDP_*</code>, <code class=\"notion\">WEATHER_IDP_*</code>, <code class=\"notion\">ANALYST_IDP_*</code>, <code class=\"notion\">MCP_IDP_*</code> and <code class=\"notion\">DRIVE_MCP_IDP_*</code>. The redirect URL of the <code class=\"notion\">console</code> client must be exactly <code class=\"notion\">http://localhost:3000/auth/callback</code>.</td>\n</tr>\n<tr>\n<td class=\"\">Your choice</td>\n<td class=\"\"><code class=\"notion\">USECASE=canbank</code>, <code class=\"notion\">AUTHZEN_SUBJECT_TYPES=User</code> (read by the chatbot, not by the gateways), an LLM for the agents (<code class=\"notion\">GEMINI_ENABLED=true</code> with <code class=\"notion\">GEMINI_API_KEY</code>, or a local Ollama through <code class=\"notion\">OLLAMA_HOST</code>), and a fresh <code class=\"notion\">FLASK_SECRET_KEY</code>.</td>\n</tr>\n</tbody>\n</table>\n\n<pre class=\"code\"><code class=\"language-Bash\">cd a2a/iag-mcp-demo\ncp .example.env .env.canbank\n# edit .env.canbank: base demo values per the repo README + the chapter 6 entries\nln -sf .env.canbank .env      # .env is a symlink to the active usecase's file</code></pre>\n\n<p class=\"notion\">Later, <code class=\"notion\">./switch-usecase.sh canbank</code> does the same relink and recreates whatever changed in one step. <code class=\"notion\">USECASE=canbank</code> selects the usecase bundle <code class=\"notion\">usecases/canbank/</code>: its <code class=\"notion\">usecase.env</code> feeds every agent the CanBank vocabulary (org name, knowledge-query names such as <code class=\"notion\">get-stock-quote</code> and <code class=\"notion\">get-hq-weather</code>, the weather HQ keywords), and its <code class=\"notion\">skills/&lt;agent&gt;</code> folders are mounted read-only into the orchestrator, retriever, and analyst - including the dataset-specific <code class=\"notion\">canbank-authz</code> skill with the exact KBAC vocabulary.</p>\n\n<p class=\"notion\">Two optional <code class=\"notion\">.env</code> entries tune the agents. <code class=\"notion\">MCP_SESSION_TTL</code> is how long, in seconds, an agent reuses each user&#x27;s MCP session against the gateway before rebuilding it - keep it below the access-token lifetime, or set <code class=\"notion\">0</code> for a fresh session per request. <code class=\"notion\">LIB_LOG_LEVEL</code> sets the log level of the agents&#x27; third-party libraries independently of <code class=\"notion\">LOG_LEVEL</code> - keep it at <code class=\"notion\">INFO</code> or <code class=\"notion\">WARNING</code> for readable agent logs, or set <code class=\"notion\">DEBUG</code> to see the SDK events as one-line breadcrumbs.</p>\n\n<h3 class=\"\">2. Build and start the stack</h3>\n<pre class=\"code\"><code class=\"language-Bash\">make                   # builds the chatbot and agent images\nmake new-drive-mcp     # builds the drive-mcp image (chapter 4)\ndocker compose pull    # fetches indykite/agent-gateway from Docker Hub\ndocker compose up -d   # COMPOSE_PROFILES=drive in .env.canbank adds the two drive services\ndocker compose ps</code></pre>\n\n<p class=\"notion\">The chatbot, agent and Drive server images are built locally and never pushed; only the gateway image comes from <a href=\"https://hub.docker.com/u/indykite\" class=\"fancy-link\" target=\"_blank\">IndyKite on Docker Hub</a>. A change to the env file reaches a container only when it is recreated (<code class=\"notion\">docker compose up -d --force-recreate &lt;service&gt;</code>); <code class=\"notion\">docker compose restart</code> does not re-read it.</p>\n\n<p class=\"notion\">With the <code class=\"notion\">drive</code> profile enabled expect <strong>12 containers</strong> - the 10 base services plus the <code class=\"notion\">drive-mcp</code> / <code class=\"notion\">drive-mcp-iag</code> pair; fewer means the profile didn't activate. (The demo's other optional profiles, <code class=\"notion\">crm</code> and <code class=\"notion\">erp</code>, add further containers - chapter 8's \"Beyond Drive\" section covers what they do.) Confirm the drive pair and prove the gateway is enforcing:</p>\n\n<pre class=\"code\"><code class=\"language-Bash\">docker compose logs drive-mcp | tail        # the wrapped server is listening on :8000, endpoint /mcp\ndocker compose logs drive-mcp-iag | tail    # the gateway is listening on :8887\ncurl -s -X POST http://localhost:8887/mcp -H \"Content-Type: application/json\" -d '{}'\n# {\"message\":\"Missing bearer token\"}   &lt;- alive and enforcing (chapter 2)\ncurl -s http://localhost:8887/.well-known/oauth-protected-resource/mcp\n# {\"resource\":\"http://drive-mcp-iag:8887/mcp\",\"authorization_servers\":[\"&lt;idp-issuer&gt;\"],\"bearer_methods_supported\":[\"header\"]}</code></pre>\n\n<p class=\"notion\">The second call needs no token: it is the gateway's OAuth protected resource metadata, and <code class=\"notion\">authorization_servers</code> must show the issuer of <strong>your</strong> IdP. A gateway that exited at start names the missing or invalid setting in its log.</p>\n\n<h3 class=\"\">3. Get an authorized user token</h3>\n<p class=\"notion\">Open <code class=\"notion\">http://localhost:3000</code> (use <code class=\"notion\">localhost</code>, not <code class=\"notion\">127.0.0.1</code>) in a fresh incognito window and log in as <strong>millicent</strong> - the one user granted <code class=\"notion\">CAN_TRIGGER</code> on <code class=\"notion\">wf-drive</code> in chapter 5. The chatbot sends you to your IdP's login page and comes back with an access token. She must exist as a login user in your IdP, with a token <code class=\"notion\">sub</code> equal to her node's <code class=\"notion\">external_id</code>; if she does not, either create her there or grant your own login user the <code class=\"notion\">CAN_TRIGGER</code> relationships instead. The demo's test scripts extract the logged-in user's access token from the chatbot session automatically; for the manual calls below, export it as <code class=\"notion\">TOKEN</code>. Tokens are short-lived, so run the calls soon after logging in.</p>\n\n<h3 class=\"\">4. The script version</h3>\n<pre class=\"code\"><code class=\"language-Bash\">./test-drive.sh                       # initialize → tools/list → resources/list → search, as millicent\nDRIVE_QUERY=budget ./test-drive.sh    # different search term\n./test-drive.sh &lt;user&gt;                # as a different logged-in user</code></pre>\n\n<h3 class=\"\">5. The manual version</h3>\n<p class=\"notion\">An MCP session against the gateway, step by step. All requests go to the <strong>gateway</strong> (<code class=\"notion\">:8887/mcp</code>), never to the Drive server directly:</p>\n\n<pre class=\"code\"><code class=\"language-Bash\">DRIVE=\"http://localhost:8887/mcp\"\nH=(-H \"Authorization: Bearer $TOKEN\" -H \"Content-Type: application/json\" \\\n   -H \"Accept: application/json, text/event-stream\")\n# 1. initialize - capture the MCP session id from the response headers\nSID=$(curl -s -D - -o /dev/null \"${H[@]}\" -X POST $DRIVE \\\n  -d '{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"initialize\",\n  \"params\": {\n    \"protocolVersion\": \"2025-11-25\",\n    \"capabilities\": {},\n    \"clientInfo\": {\n      \"name\": \"demo\",\n      \"version\": \"1.0\"\n    }\n  }\n}' \\\n  | grep -i mcp-session-id | tr -d '\\r' | awk '{print $2}')\necho \"session: $SID\"      # a UUID; empty means check the token or the gateway logs\n# every request after initialize must name the negotiated revision\nS=(-H \"Mcp-Session-Id: $SID\" -H \"Mcp-Protocol-Version: 2025-11-25\")\n# 2. initialized notification (expect HTTP 202)\ncurl -s -o /dev/null -w \"initialized -&gt; HTTP %{http_code}\\n\" \"${H[@]}\" \"${S[@]}\" -X POST $DRIVE \\\n  -d '{\n  \"jsonrpc\": \"2.0\",\n  \"method\": \"notifications/initialized\",\n  \"params\": {}\n}'\n# 3. list the Drive server's tools (expect: search)\ncurl -s \"${H[@]}\" \"${S[@]}\" -X POST $DRIVE \\\n  -d '{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 2,\n  \"method\": \"tools/list\",\n  \"params\": {}\n}'\n# 4. the search - full-text over the authorized account's Drive\ncurl -s -m 45 \"${H[@]}\" \"${S[@]}\" -X POST $DRIVE \\\n  -d '{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 3,\n  \"method\": \"tools/call\",\n  \"params\": {\n    \"name\": \"search\",\n    \"arguments\": {\n      \"query\": \"canbank\"\n    }\n  }\n}'</code></pre>\n<p class=\"notion\">The gateway forwards only MCP protocol revisions <code class=\"notion\">2025-06-18</code>, <code class=\"notion\">2025-11-25</code>, and <code class=\"notion\">2026-07-28</code>. The Drive reference server does not speak the stateless <code class=\"notion\">2026-07-28</code> revision (it rejects <code class=\"notion\">server/discover</code>), so this walkthrough uses <code class=\"notion\">2025-11-25</code>, the newest revision an <code class=\"notion\">initialize</code> handshake can agree on; an <code class=\"notion\">initialize</code> naming an older revision is forwarded with <code class=\"notion\">2025-11-25</code> instead. Every request after the handshake must carry <code class=\"notion\">Mcp-Protocol-Version</code>, or the gateway refuses it with <code class=\"notion\">400</code> and the JSON-RPC error <code class=\"notion\">Header mismatch: Mcp-Protocol-Version header is missing</code>. That is why the <code class=\"notion\">S</code> array above carries the header on every call.</p>\n<p class=\"notion\">What steps 3 and 4 answer depends on <code class=\"notion\">IAG_DRIVE_CAPABILITY_CHECKS</code> (chapter 6). With the checks off, the demo's default, admission alone decides every request: millicent gets the server's own answers, and anyone else gets <code class=\"notion\">403</code> from the first call on. With the checks on, the list holds <code class=\"notion\">search</code> only for a user admitted on the chain and is empty otherwise, and a <code class=\"notion\">tools/call</code> naming anything else answers <code class=\"notion\">403</code> with the JSON-RPC error <code class=\"notion\">-31403</code> without reaching the server.</p>\n\n<p class=\"notion\">Expected result of the search - lines of <code class=\"notion\">&lt;fileId&gt; &lt;name&gt; (&lt;mimeType&gt;)</code>; your files will differ, and matches are files whose <em>content</em> mentions the query; for example:</p>\n\n<pre class=\"code\"><code class=\"language-Text\">Found 3 files:\n1AbC...xYz Financial report (application/vnd.google-apps.document)\n1DeF...uVw Retail campaign (application/vnd.google-apps.document)\n1GhI...rSt video1.mp4 (video/mp4)</code></pre>\n\n<p class=\"notion\">Cross-check: open drive.google.com as the authorized Google account and type the same query into the search bar - same files. Between steps, note what just happened: the gateway had your IdP introspect millicent's token and exchange it for a delegation token with the chain <code class=\"notion\">[indykiteagent-drive]</code>, asked IndyKite whether <code class=\"notion\">User/millicent</code> may reach <code class=\"notion\">Agent/indykiteagent-drive</code> through that chain, audited the decision, swapped in the delegation token, and streamed the Drive server's response back - while the <code class=\"notion\">Mcp-Session-Id</code> minted downstream flowed through untouched.</p>\n\n<h3 class=\"\">6. The prompt versions (optional)</h3>\n<p class=\"notion\">The same authorization guards the longer chains modeled in chapter 5:</p>\n<ul class=\"bulleted-list\">\n<li style=\"list-style-type:disc\"><strong>Via the analyst</strong> (<code class=\"notion\">wf-drive-analyst</code>): with <code class=\"notion\">ANALYST_MCP_SERVER_URLS</code> set (chapter 6), send the analyst gateway (<code class=\"notion\">:8885</code>) an A2A <code class=\"notion\">message/send</code> with a prompt like <em>\"Search Google Drive for canbank\"</em> - the analyst then calls Drive as one of its MCP backends. Cross-backend prompts work too: <em>\"Search Google Drive for canbank, then check which internal policy documents mention the same topics.\"</em> (The repo's <code class=\"notion\">./demo-analyst-drive.sh</code> is a related smoke test: it sends the analyst a hello message and then runs the <em>direct</em> Drive search from step 5.)</li>\n<li style=\"list-style-type:disc\"><strong>Via the chatbot console</strong> (<code class=\"notion\">wf-drive-console</code>): as millicent, type <em>\"Search Google Drive for canbank and list the matching files\"</em> at <code class=\"notion\">http://localhost:3000</code>. Mentioning <strong>\"Google Drive\"</strong> (or \"Drive\") in the prompt is what routes it to the orchestrator's <code class=\"notion\">query_drive</code> tool instead of the retriever - a prompt like <em>\"search my files for canbank\"</em> silently goes to the retriever. Every hop - orchestrator, analyst, Drive - passes its own gateway and leaves its own audit record.</li>\n</ul>\n\n<p class=\"notion\">Prompt tips: Drive search is full-text, so to target a specific file prefer listing then reading (<em>\"Read the file 'X' from Google Drive and summarize it\"</em>), and point read prompts at Google-native documents or PDFs - the only formats that come back as readable text (chapter 4). For workflow prompts, <strong>name the agent</strong> (<em>\"Use the retriever to …\"</em>, <em>\"Ask the retriever for …\"</em>) so the orchestrator actually delegates instead of answering itself. Stock-quote prompts fetch live market data; an occasional <code class=\"notion\">429 Too Many Requests</code> is upstream rate-limiting, not an authorization failure - retry after a few minutes.</p>\n\n<h3 class=\"\">7. Prompts by persona</h3>\n<p class=\"notion\">The graph gives every demo user different access, so the same prompt can succeed for one login and be denied - or return nothing - for another. That asymmetry <em>is</em> the demo. Switch personas with a fresh incognito window per user. The repo's scripted tour of these prompts lives in <code class=\"notion\">usecases/canbank/DEMO_SCRIPT.md</code>. Chatbot console prompts:</p>\n\n<table class=\"simple-table\">\n<tbody>\n<tr>\n<td class=\"simple-table-header-color\"><strong>Persona (access)</strong></td>\n<td class=\"simple-table-header-color\"><strong>Prompts that work</strong></td>\n<td class=\"simple-table-header-color\"><strong>What is denied</strong></td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">millicent</code> - support + trading depts; <code class=\"notion\">wf1</code>, <code class=\"notion\">wf3</code>, all <code class=\"notion\">wf-drive*</code></td>\n<td class=\"\">Everything leslie can, plus the star turn: <em>\"Search Google Drive for canbank and list the matching files.\"</em>, <em>\"List the files in my Google Drive.\"</em>, <em>\"Read the file 'X' from Google Drive and summarize it.\"</em> Trading membership adds stock and AuthZEN prompts: <em>\"What is the price of META?\"</em>, <em>\"Am I allowed to retrieve a stock quote? Check with authzen.\"</em> (decision <code class=\"notion\">true</code>).</td>\n<td class=\"\">Asking authzen about a <em>different</em> user (e.g. subject <code class=\"notion\">roy</code>) returns <code class=\"notion\">false</code> by design - see the note below the table.</td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">leslie</code> - support dept → <code class=\"notion\">wf1</code>, <code class=\"notion\">wf2</code></td>\n<td class=\"\"><em>\"Use the retriever to find internal policy documents about refunds.\"</em>, <em>\"Ask the retriever which past decisions incorporated the refund_policy document.\"</em>, <em>\"What's the weather in London?\"</em></td>\n<td class=\"\">Drive and analyst calls → <code class=\"notion\">403</code>; stock prompts return nothing, and <em>\"Am I allowed to retrieve a stock quote?\"</em> answers <code class=\"notion\">false</code> - support holds no <code class=\"notion\">CAN_RETRIEVE</code> relationship.</td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">roy</code> - trading dept → <code class=\"notion\">wf1</code></td>\n<td class=\"\"><em>\"Use the retriever to get the NVDA stock price.\"</em>, <em>\"Ask the retriever how many shares of NVDA the customer rebecca can purchase.\"</em>, <em>\"Am I allowed to retrieve a stock quote? Check with authzen.\"</em> (decision <code class=\"notion\">true</code>).</td>\n<td class=\"\">Drive and analyst calls → <code class=\"notion\">403</code> - which makes roy the demo's grant-flow persona: chapter 8's deny → remediate → allow beat grants him Drive access with one click and revokes it again.</td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">carol</code> - <code class=\"notion\">wf1</code> only</td>\n<td class=\"\">Normal <code class=\"notion\">wf1</code> prompts (as leslie).</td>\n<td class=\"\">The designated deny persona: millicent's exact analyst and Drive requests with carol's token → <code class=\"notion\">403</code>. The \"same request, different user, different outcome\" money shot.</td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">jane</code> - <code class=\"notion\">wf2</code> only</td>\n<td class=\"\">Weather prompts: <em>\"What's the weather in London?\"</em>, <em>\"What's the weather at CanBank HQ?\"</em> The HQ variant goes through the <code class=\"notion\">get-hq-weather</code> knowledge query and its weather resolvers only when <code class=\"notion\">CIQ_QUERY_HQ_WEATHER</code> and that setup exist; otherwise weather prompts fall back to direct Open-Meteo.</td>\n<td class=\"\">All <code class=\"notion\">wf1</code> flows → <code class=\"notion\">403</code> - she cannot trigger the orchestrator workflow.</td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">joe</code> - plain <code class=\"notion\">wf1</code></td>\n<td class=\"\">Baseline <code class=\"notion\">wf1</code> prompts; handy as the default subject for a direct AuthZEN <code class=\"notion\">CAN_TRIGGER</code> evaluation.</td>\n<td class=\"\">Analyst and Drive → <code class=\"notion\">403</code>.</td>\n</tr>\n</tbody>\n</table>\n\n<p class=\"notion\">Note the three kinds of \"no\" in the table: a <code class=\"notion\">403</code> is a <strong>gateway</strong> refusing admission, because no workflow that user can trigger has the request's chain; an empty result is <strong>data-level</strong> scoping inside an authorized workflow (the retriever's queries respect department reach); an AuthZEN decision of <code class=\"notion\">false</code> is a <strong>policy</strong> answer delivered inside an authorized workflow - leslie asking about the stock quote gets a clean <code class=\"notion\">false</code>, not an error. One more <code class=\"notion\">false</code> is by design rather than policy: evaluations through the chatbot carry the logged-in user's token, and the platform binds them to that token's subject - asking about a <em>different</em> user always returns <code class=\"notion\">false</code>, regardless of that user's real permissions. Evaluate other subjects from a service context instead (the repo's Bruno <code class=\"notion\">authzen</code> folder, <code class=\"notion\">X-IK-ClientKey</code> app token).</p>\n\n<p class=\"notion\">When writing your own AuthZEN prompts or agents, use the policy vocabulary exactly: types, actions, and ids are case-sensitive graph terms (<code class=\"notion\">User</code>, <code class=\"notion\">CAN_RETRIEVE</code>, <code class=\"notion\">Quote</code>, <code class=\"notion\">stock_quote</code>). A guessed value such as <code class=\"notion\">user</code>, <code class=\"notion\">view</code>, or <code class=\"notion\">stock</code> evaluates to a <code class=\"notion\">false</code> indistinguishable from a real denial, and the MCP server's <code class=\"notion\">list_resources</code> returns only knowledge queries, not policy vocabulary - so the demo agents carry the exact triples as agent skills; give your own agents the vocabulary the same explicit way.</p>\n\n<p class=\"notion\">The customer in the stock prompts, <code class=\"notion\">rebecca</code>, is data in the graph, not a login. Which personas can actually <em>log in</em> depends on your IdP - the graph side comes from the chapter 5 ingest; if a persona cannot log in, create them in the IdP or grant your login user the equivalent relationships.</p>\n\n<h3 class=\"\">What comes next</h3>\n<p class=\"notion\">A successful search is only half the story. Chapter 8 proves the denials and reads the audit trail.</p>",
      "links": {
        "html": "/tutorials/tutorial-agent-gateway-mcp#chapter-7",
        "markdown": "/tutorials/tutorial-agent-gateway-mcp/7.md"
      }
    },
    {
      "chapter": 8,
      "title": "Verify denials and read the audit trail",
      "description": "Force NOT_AUTHORIZED outcomes on purpose, read the audit records, and fix the common failure modes.",
      "body": "<h2 class=\"\">Chapter 8: Verify denials and read the audit trail</h2>\n\n<p class=\"notion\">Confidence in an enforcement point comes from watching it say no. Tail the gateway while you test:</p>\n\n<pre class=\"code\"><code class=\"language-Bash\">docker compose logs -f drive-mcp-iag</code></pre>\n\n<h3 class=\"\">The money shot: same request, different user</h3>\n<p class=\"notion\">Log in as any user other than millicent (fresh incognito window) and repeat chapter 7's calls - <code class=\"notion\">./test-drive.sh leslie</code>, or the manual sequence with that user's token. Every request now returns:</p>\n\n<pre class=\"code\"><code class=\"language-JSON\">HTTP 403\n{\n  \"message\": \"Authorization check failed\"\n}</code></pre>\n\n<p class=\"notion\">Only millicent holds <code class=\"notion\">CAN_TRIGGER</code> on <code class=\"notion\">wf-drive</code> in the graph. Nothing else changed: same gateway, same MCP server, same request body - different subject, different decision. The identity provider did its part for both users alike: the token was active and the exchange succeeded. The refusal is IndyKite's answer about the graph. (With <code class=\"notion\">IAG_DRIVE_CAPABILITY_CHECKS=true</code>, the same user gets an empty <code class=\"notion\">tools/list</code> and the JSON-RPC error <code class=\"notion\">-31403</code> on the <code class=\"notion\">tools/call</code> instead - chapter 6.)</p>\n\n<h3 class=\"\">Other denial paths worth forcing once</h3>\n<ul class=\"bulleted-list\">\n<li style=\"list-style-type:disc\"><strong>Arrive through the wrong agents</strong> - call the Drive gateway with a delegation token that passed an agent no Drive workflow contains, for example one from the retriever hop, with the chain <code class=\"notion\">[indykiteagent, indykiteagent-2]</code>: the exchange appends the Drive client, and <code class=\"notion\">[indykiteagent, indykiteagent-2, indykiteagent-drive]</code> is the path of no workflow → <code class=\"notion\">403</code>. A token whose chain is the start of a Drive workflow, such as <code class=\"notion\">[indykiteagent, indykiteagent-4]</code>, is not a denial case: it continues along <code class=\"notion\">wf-drive-console</code> for a subject who can trigger it.</li>\n<li style=\"list-style-type:disc\"><strong>Break the model</strong> - remove the <code class=\"notion\">workflow_name</code> property from the <code class=\"notion\">INVOKES</code> relationship: the admission policy no longer matches the path → <code class=\"notion\">403</code>.</li>\n<li style=\"list-style-type:disc\"><strong>Revoke the grant</strong> - delete the <code class=\"notion\">CAN_TRIGGER</code> relationship: AuthZEN answers no → <code class=\"notion\">403</code>, once the gateway's cached decision expires.</li>\n<li style=\"list-style-type:disc\"><strong>Call another path</strong> - <code class=\"notion\">POST http://localhost:8887/</code> instead of <code class=\"notion\">/mcp</code> → <code class=\"notion\">404</code> <code class=\"notion\">{\"message\":\"Not Found\"}</code>, before the token is read.</li>\n</ul>\n\n<h3 class=\"\">Deny → remediate → allow: the grant button</h3>\n<p class=\"notion\">Authorization is data, and the demo makes that literal. With <code class=\"notion\">GRANT_WORKFLOW_MAP</code> set (chapter 6), a red <strong>NOT AUTHORIZED</strong> card from the Drive gateway in the chatbot's audit terminal carries a button that depends on who is looking: the denied person sees <strong>request access</strong> on their own card, people who can grant see <strong>grant access</strong> on other people's cards. Every console receives every audit card, so keep millicent logged in and open a second browser as roy. The scripted beat:</p>\n<ol type=\"1\" class=\"numbered-list\" start=\"1\">\n<li>roy: <em>\"List the files in my Google Drive.\"</em> → red NOT AUTHORIZED card from <code class=\"notion\">drive-mcp-iag</code>, in both consoles.</li>\n<li>roy clicks <strong>request access</strong> on his card → the request lands in millicent's access requests inbox on the Support page. He cannot self-serve: the grant is guarded by a live AuthZEN self-check (policy <code class=\"notion\">user-can-trigger-workflow</code>, chapter 5) - it only proceeds when the <em>logged-in</em> user can <code class=\"notion\">CAN_TRIGGER</code> every workflow in the bundle themselves, and answers <code class=\"notion\">403</code> to anyone else.</li>\n<li>millicent clicks <strong>grant access</strong> on the same card in her console, or <strong>Grant</strong> on the inbox item (she holds the drive workflows) → a Capture API upsert writes <code class=\"notion\">roy -CAN_TRIGGER-&gt; wf-drive*</code> relationships, and the why? graph shows the new path immediately.</li>\n<li>roy repeats the prompt → <strong>green</strong>, the real Drive listing - once the gateways' cached decisions expire (about 30 seconds with the demo's <code class=\"notion\">IAG_AUTHZEN_CACHE_TTL</code>, or restart the gateways: <code class=\"notion\">docker compose restart orchestrator-iag analyst-iag drive-mcp-iag</code>).</li>\n<li>millicent clicks <strong>revoke access</strong> (a Capture delete of the same relationships) → after the same cache window, roy is red again. The beat is repeatable.</li>\n</ol>\n<p class=\"notion\">Nothing but graph relationships changed between the red and green runs - same gateways, same MCP server, same prompt.</p>\n\n<h3 class=\"\">Explain the decision: the why? cards</h3>\n<p class=\"notion\">With <code class=\"notion\">EXPLAIN_STAFF_QUERY_ID</code> and <code class=\"notion\">EXPLAIN_DIRECT_QUERY_ID</code> set (chapter 6), every AUTHORIZED / NOT AUTHORIZED card also carries a <strong>why?</strong> button that renders the authorization path behind the decision, live from the graph: the staff leg (<code class=\"notion\">Subject -WORKS_IN-&gt; Department -CAN_TRIGGER-&gt; Workflow</code>) and the direct leg (<code class=\"notion\">Subject -CAN_TRIGGER-&gt; Workflow</code>). A denial renders as the two nodes with <em>no connecting path</em> - the graph shows why not. The two explain queries ship with the canbank dataset; because they run live, a grant or revoke changes the picture on the next click. An audit record names the delegation chain, not a workflow, so the chatbot takes the workflow to explain from the gateway's grant bundle (<code class=\"notion\">GRANT_WORKFLOW_MAP</code>).</p>\n<p class=\"notion\">Each gateway card also shows what the record says: a tag with the action (<code class=\"notion\">admission</code>, <code class=\"notion\">discovery</code>, <code class=\"notion\">invocation</code>, or <code class=\"notion\">refused early</code>), a <strong>chain</strong> line with the delegation chain, the reason, and a TOKEN card with the delegation token your IdP minted for that hop - the user as subject, the gateway clients as actors.</p>\n\n<h3 class=\"\">Reading the audit records</h3>\n<p class=\"notion\">Every decision emits one record on the audit stream configured in the mounted audit config (chapter 6), written before the request is forwarded: delivered either to a <strong>webhook</strong> (<code class=\"notion\">audit.delivery: webhook</code> plus the target URL and auth) or to a <strong>file</strong> (<code class=\"notion\">audit.delivery: file</code> with a storage path, <code class=\"notion\">csv</code>/<code class=\"notion\">json</code>/<code class=\"notion\">txt</code> format, and size- or time-based rotation). The demo posts records to a webhook on the chatbot, which displays them live. millicent's direct search of chapter 7 leaves this record:</p>\n\n<pre class=\"code\"><code class=\"language-JSON\">{\n  \"decision\": \"AUTHORIZED\",\n  \"reason\": \"subject User/millicent may reach Agent/indykiteagent-drive through the delegation chain\",\n  \"subject\": \"millicent\",\n  \"actor\": \"indykiteagent-drive\",\n  \"action\": \"ADMISSION\",\n  \"service\": \"drive-mcp-iag\",\n  \"timestamp\": \"2026-09-30T09:12:00.123456789Z\",\n  \"traceID\": \"4bf92f3577b34da6a3ce929d0e0e4736\",\n  \"cached\": {\n    \"admission\": false\n  },\n  \"actorsChain\": [\n    \"indykiteagent-drive\"\n  ]\n}</code></pre>\n\n<table class=\"simple-table\">\n<tbody>\n<tr>\n<td class=\"simple-table-header-color\"><strong>Field</strong></td>\n<td class=\"simple-table-header-color\"><strong>Meaning</strong></td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">action</code></td>\n<td class=\"\">The question the record answers. <code class=\"notion\">ADMISSION</code>: may the subject reach the protected server through the delegation chain. <code class=\"notion\">DISCOVERY</code> and <code class=\"notion\">INVOCATION</code>: the capability decisions for a list and for a call, written only with capability checks on. <code class=\"notion\">noop</code>: the request was refused before any question was asked, for example for a missing token.</td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">decision</code></td>\n<td class=\"\"><code class=\"notion\">AUTHORIZED</code>, <code class=\"notion\">NOT_AUTHORIZED</code> for every refusal including an MCP refusal, or <code class=\"notion\">ERROR</code> when the identity provider or IndyKite could not be consulted, so an outage is never counted as a denial.</td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">reason</code></td>\n<td class=\"\">Human-readable explanation. On admission, <code class=\"notion\">subject User/millicent may reach Agent/indykiteagent-drive through the delegation chain</code>, or on denial <code class=\"notion\">subject User/leslie may not reach Agent/indykiteagent-drive through the delegation chain</code>. The reason names the subject <code class=\"notion\">whoami</code> resolved and the chain, never a workflow. Refusals before the decision read <code class=\"notion\">no bearer token</code>, <code class=\"notion\">cannot introspect the subject token</code>, <code class=\"notion\">cannot resolve the subject of the access token</code>, or <code class=\"notion\">MCP request refused: &lt;message&gt;</code>.</td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">subject</code></td>\n<td class=\"\">The end user the request acts for (e.g. <code class=\"notion\">millicent</code>).</td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">actor</code> / <code class=\"notion\">actorsChain</code></td>\n<td class=\"\">The last agent of the chain and the full ordered delegation chain from the token's <code class=\"notion\">act</code> claim, oldest first.</td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">cached</code></td>\n<td class=\"\">Whether the answer came from the gateway's cache or from IndyKite during the request.</td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">permittedSet</code>, <code class=\"notion\">discovery</code>, <code class=\"notion\">capabilities</code></td>\n<td class=\"\">Only on capability records: the set a list was filtered to, how many entries the server listed and the caller kept, and the tool or resource a call named.</td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">service</code></td>\n<td class=\"\">The gateway instance that decided (<code class=\"notion\">drive-mcp-iag</code>) - how you tell the hops apart in a multi-gateway chain.</td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">timestamp</code> / <code class=\"notion\">traceID</code></td>\n<td class=\"\">RFC 3339 UTC time and the trace ID also found in the gateway's logs.</td>\n</tr>\n</tbody>\n</table>\n\n<p class=\"notion\">On a console-path request (chapter 7, <code class=\"notion\">wf-drive-console</code>) you should see <code class=\"notion\">AUTHORIZED</code> records from every gateway the request traversed - orchestrator, analyst, and Drive - each with an <code class=\"notion\">actorsChain</code> one client longer: <code class=\"notion\">[indykiteagent]</code>, <code class=\"notion\">[indykiteagent, indykiteagent-4]</code>, <code class=\"notion\">[indykiteagent, indykiteagent-4, indykiteagent-drive]</code>. The full record contract is in the <a href=\"/guides/guide-agent-gateway#audit\" class=\"fancy-link\">Agent Gateway guide</a>.</p>\n\n<h3 class=\"\">Troubleshooting</h3>\n<table class=\"simple-table\">\n<tbody>\n<tr>\n<td class=\"simple-table-header-color\"><strong>Symptom</strong></td>\n<td class=\"simple-table-header-color\"><strong>Cause / fix</strong></td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">401 Missing bearer token</code> on your own calls</td>\n<td class=\"\">Token missing or expired - tokens are short-lived; log in again and re-export <code class=\"notion\">TOKEN</code>.</td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">401</code> with <code class=\"notion\">\"errors\": [\"identity provider: the token is not active\"]</code></td>\n<td class=\"\">The IdP reports the token expired or unknown. Log in again; if it persists, check that the chatbot and the gateways use the same IdP instance (<code class=\"notion\">IDP_BASE_URL</code>) and the introspection path in <code class=\"notion\">iag-base-docker.yaml</code>.</td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">401</code> or <code class=\"notion\">403</code> with <code class=\"notion\">\"errors\": [\"identity provider: client credentials grant failed - …\"]</code> or <code class=\"notion\">[\"identity provider: token exchange failed - …\"]</code></td>\n<td class=\"\">The IdP refused the gateway's own client: a wrong <code class=\"notion\">DRIVE_MCP_IDP_CLIENT_SECRET</code>, or the <code class=\"notion\">indykiteagent-drive</code> client is not allowed the client credentials grant or the token exchange (chapter 5). The audit record says <code class=\"notion\">ERROR</code>.</td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">401</code> with <code class=\"notion\">\"errors\": [\"ContX IQ whoami failed\"]</code></td>\n<td class=\"\">No Token Introspect configuration matches the issuer and audience of the token the gateway received - at a gateway behind an agent, that can be the IdP's delegation token rather than the login token. Call <code class=\"notion\">GET /contx-iq/v1/whoami</code> with the same token and add the missing configuration (chapter 5).</td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">403</code> for a user you expected to pass</td>\n<td class=\"\">The admission policy answered no. Compare the record's <code class=\"notion\">actorsChain</code> with the workflow's <code class=\"notion\">INVOKES</code> path in the graph: the agents' <code class=\"notion\">external_id</code> must equal the client names your IdP writes into the chain, every hop needs its <code class=\"notion\">workflow_name</code>, and the subject needs a <code class=\"notion\">CAN_TRIGGER</code> path to that workflow - re-run the ingest from chapter 5. A chain shorter than expected means the IdP's token exchange does not nest the previous <code class=\"notion\">act</code> claim. Also check the type in the audit reason (<code class=\"notion\">subject &lt;type&gt;/&lt;id&gt; ...</code>): it comes from the Token Introspect configuration, and a KBAC policy for another type never matches. Replay the evaluation of chapter 5 by hand to see the platform's answer.</td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">401</code> or <code class=\"notion\">403</code> with <code class=\"notion\">\"errors\": [\"evaluating admission through AuthZEN failed\"]</code></td>\n<td class=\"\">IndyKite refused the AppAgent credential, or cannot read the delegation token in <code class=\"notion\">X-IK-Token</code>: no Token Introspect configuration matches its issuer and the audience <code class=\"notion\">indykiteagent-drive</code> (chapter 5). The audit record says <code class=\"notion\">ERROR</code>.</td>\n</tr>\n<tr>\n<td class=\"\">Empty <code class=\"notion\">tools/list</code>, or <code class=\"notion\">403</code> with JSON-RPC <code class=\"notion\">-31403</code> on <code class=\"notion\">tools/call</code>, for a user you expected to pass</td>\n<td class=\"\">Capability checks are on (<code class=\"notion\">IAG_DRIVE_CAPABILITY_CHECKS=true</code>) and the Drive server's tool is not in the caller's permitted set: nothing is modelled, the <code class=\"notion\">HAS</code> relationship lacks the <code class=\"notion\">workflow_name</code> of the shape in use, or the <code class=\"notion\">CAN_USE</code> policy for <code class=\"notion\">Tool</code> is missing. See chapter 6, or set the variable back to <code class=\"notion\">false</code>; the <code class=\"notion\">DISCOVERY</code> record in the audit trail shows the <code class=\"notion\">permittedSet</code> the gateway worked from.</td>\n</tr>\n<tr>\n<td class=\"\">AuthZEN decision <code class=\"notion\">false</code> when you expected <code class=\"notion\">true</code></td>\n<td class=\"\">Check the vocabulary casing (<code class=\"notion\">User</code>, <code class=\"notion\">CAN_RETRIEVE</code>, <code class=\"notion\">Quote</code> - a mistyped type or action evaluates <code class=\"notion\">false</code> with no error) and the subject: evaluations carrying a user token are bound to that token's subject, so another subject always evaluates <code class=\"notion\">false</code> - evaluate other users from a service context (<code class=\"notion\">X-IK-ClientKey</code>).</td>\n</tr>\n<tr>\n<td class=\"\">Empty <code class=\"notion\">Mcp-Session-Id</code> after <code class=\"notion\">initialize</code></td>\n<td class=\"\">Check <code class=\"notion\">docker compose logs drive-mcp-iag drive-mcp</code> - usually the graph ingest or the IdP client for <code class=\"notion\">indykiteagent-drive</code> is missing.</td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">404</code> on MCP methods</td>\n<td class=\"\">The client calls a path other than the gateway's one MCP endpoint, <code class=\"notion\">/mcp</code> (chapter 6).</td>\n</tr>\n<tr>\n<td class=\"\">A gateway exits at start</td>\n<td class=\"\">A setting is missing or invalid, and the gateway's log names it - typically <code class=\"notion\">IDP_ISSUER</code>, or a percent-encoded project gid in <code class=\"notion\">MCP_SERVER_PATH</code> (write <code class=\"notion\">gid:...</code>).</td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">manifest unknown</code> when pulling the gateway image</td>\n<td class=\"\">The image named in <code class=\"notion\">AGENT_GATEWAY_IMAGE</code> does not exist for your platform. Use <code class=\"notion\">indykite/agent-gateway:&lt;version&gt;</code> and, on Apple Silicon, add <code class=\"notion\">platform: linux/amd64</code> to the <code class=\"notion\">iag-base</code> service.</td>\n</tr>\n<tr>\n<td class=\"\"><code class=\"notion\">pull access denied for agent-gateway</code> when starting the stack</td>\n<td class=\"\">The image the gateways are told to run is not on Docker Hub: it is a name that exists only where the image was loaded locally. It comes either from <code class=\"notion\">AGENT_GATEWAY_IMAGE</code> in your shell or env file, or, when that is not set, from the demo's default. Set <code class=\"notion\">AGENT_GATEWAY_IMAGE=indykite/agent-gateway:&lt;version&gt;</code> (chapter 6) and run <code class=\"notion\">docker compose up -d</code> again.</td>\n</tr>\n<tr>\n<td class=\"\">A change in the env file has no effect</td>\n<td class=\"\"><code class=\"notion\">docker compose restart</code> does not re-read it - recreate the service: <code class=\"notion\">docker compose up -d --force-recreate &lt;service&gt;</code>.</td>\n</tr>\n<tr>\n<td class=\"\">A grant or revoke seems to have no effect</td>\n<td class=\"\">Each gateway keeps its decisions per subject and chain (30 seconds in the demo, <code class=\"notion\">IAG_AUTHZEN_CACHE_TTL</code>, chapter 6) - wait out the window or restart the affected gateways to clear the cache. The graph and AuthZEN answers change immediately; only the gateway cache lags.</td>\n</tr>\n<tr>\n<td class=\"\">Search fails with <code class=\"notion\">invalid_request</code> or credential errors</td>\n<td class=\"\">The two Google files in <code class=\"notion\">drive_mcp/.gdrive/</code> come from different OAuth clients or are missing - redo chapter 3 step 4.</td>\n</tr>\n<tr>\n<td class=\"\">File reads answer \"binary document\"</td>\n<td class=\"\">Only Google-native files and PDFs come back as text (chapter 4); an encrypted or scanned-image PDF also falls back to base64 - convert the file to a Google Doc.</td>\n</tr>\n</tbody>\n</table>\n\n<h3 class=\"\">Beyond Drive: two more protected downstreams</h3>\n<p class=\"notion\">The demo extends the same enforcement pattern in two optional directions. Neither is required for this tutorial, but both show where the recipe leads.</p>\n\n<h4 class=\"\">Graph-filtered ERP rows (compose profile <code class=\"notion\">erp</code>)</h4>\n<p class=\"notion\">A second non-IndyKite MCP server behind its own gateway - this time a plain <strong>Postgres \"ERP\"</strong> (one invoices table) whose rows are pre-filtered per caller by the knowledge graph before any SQL runs. Where Drive showcased MCP proxying, ERP showcases the <strong>AuthZEN search/resource API</strong> (enumeration) alongside the evaluate API (yes/no) used everywhere else:</p>\n<pre class=\"code\"><code class=\"language-Text\">console → orchestrator ──query_erp──&gt; analyst ──erp_list_invoices──&gt; erp-mcp-iag:8889 → erp-mcp\n                                                                                        │  AuthZEN search/resource:\n                                                                                        │  which Invoice ids may this subject CAN_VIEW?\n                                                                                        └─&gt; SELECT ... WHERE external_id = ANY(&lt;allowed ids&gt;)  @ erp-db</code></pre>\n<p class=\"notion\">The graph decides through <code class=\"notion\">Department -SERVES-&gt; Customer -HAS_INVOICE-&gt; Invoice</code> (staff) and the direct <code class=\"notion\">HAS_INVOICE</code> relationship (customers), backed by the <code class=\"notion\">staff-can-view-invoice</code> KBAC policy. The payoff prompt is <em>\"Show me the invoices\"</em>: <strong>same prompt, three row counts</strong> - millicent (support + trading) sees all 9, leslie (support) 6, roy (trading) 3. The database knows nothing about the graph; connecting to Postgres directly shows every row unfiltered.</p>\n<ul class=\"bulleted-list\">\n<li style=\"list-style-type:disc\"><strong>Everything ships in the canbank dataset</strong>: the <code class=\"notion\">Invoice</code> nodes, <code class=\"notion\">SERVES</code>/<code class=\"notion\">HAS_INVOICE</code> relationships, the KBAC policy, and the <code class=\"notion\">wf-erp</code> / <code class=\"notion\">wf-erp-analyst</code> / <code class=\"notion\">wf-erp-console</code> workflow chains - provisioned by the same instant-stack run as chapter 5.</li>\n<li style=\"list-style-type:disc\"><strong>To enable</strong>: create the <code class=\"notion\">indykiteagent-erp</code> IdP client, then in <code class=\"notion\">.env.canbank</code> add <code class=\"notion\">erp</code> to <code class=\"notion\">COMPOSE_PROFILES</code>, append <code class=\"notion\">,erp=http://erp-mcp-iag:8889/mcp</code> to <code class=\"notion\">ANALYST_MCP_SERVER_URLS</code>, set <code class=\"notion\">ERP_TOOL_ENABLED=true</code> and the <code class=\"notion\">ERP_MCP_IDP_CLIENT_SECRET</code>, and build with <code class=\"notion\">make new-erp-mcp</code>.</li>\n<li style=\"list-style-type:disc\"><strong>Trust boundary</strong>: <code class=\"notion\">erp-mcp</code> and <code class=\"notion\">erp-db</code> are not published to the host - only <code class=\"notion\">erp-mcp-iag</code> reaches them. The server reads the subject from the gateway-minted delegation token; exposing it directly would let a self-crafted token read other subjects' rows.</li>\n</ul>\n\n<h4 class=\"\">Delegation into a real SaaS: Salesforce cases (compose profile <code class=\"notion\">crm</code>)</h4>\n<p class=\"notion\">The <code class=\"notion\">crm</code> profile completes the picture for any usecase: the delegation chain the gateways verify can land in a <strong>real third-party SaaS</strong>. A staff login asks the console to open a case; the CRM agent (an A2A agent behind <code class=\"notion\">crm-iag</code>, workflow <code class=\"notion\">wf-crm</code>, in the demo's insurance usecase) reads the <code class=\"notion\">sub</code> and <code class=\"notion\">act</code> chain from the gateway-minted delegation token, exchanges a signed JWT Bearer assertion (RFC 7523) for a Salesforce access token, and creates the Case with <em>\"Filed on behalf of &lt;subject&gt; via agent chain …\"</em> in its description. <code class=\"notion\">wf-crm</code> is staff-only, so the same prompt from a customer login ends in the familiar red DENY - and the audit terminal shows two TOKEN cards per run: the delegation token from the IdP and the (redacted) Salesforce token. Like the ERP pair, the CRM agent's port is not published to the host - only <code class=\"notion\">crm-iag</code> reaches it, so the on-behalf-of attribution written into Salesforce always rests on a gateway-verified token.</p>\n<p class=\"notion\">To enable it: provision the <code class=\"notion\">wf-crm</code> workflow in your dataset, create the <code class=\"notion\">indykiteagent-crm</code> IdP client, set up a Salesforce Connected App with the JWT Bearer flow (digital signatures, <code class=\"notion\">api</code> + <code class=\"notion\">refresh_token/offline_access</code> scopes, pre-authorized profile), and fill the CRM entries in the usecase env file (<code class=\"notion\">CRM_IDP_CLIENT_ID/SECRET</code>, <code class=\"notion\">IAG_CRM_HOST</code>, <code class=\"notion\">SF_CONSUMER_KEY</code>, <code class=\"notion\">SF_USERNAME</code>, <code class=\"notion\">crm</code> in <code class=\"notion\">COMPOSE_PROFILES</code>). The orchestrator registers its <code class=\"notion\">query_crm</code> tool when <code class=\"notion\">CRM_HOST</code> is set. The repo's usecase <code class=\"notion\">DEMO_SCRIPT.md</code> files carry the full setup walkthrough.</p>\n\n<h3 class=\"\">Where you are now</h3>\n<p class=\"notion\">A third-party MCP server is running behind the Agent Gateway with per-user, graph-backed authorization and a full audit trail - and the MCP server itself never changed. The same recipe applies to any MCP Streamable HTTP server: wrap it if it speaks stdio (chapter 4), model who may reach it and through which chain (chapter 5), and point one gateway instance at it (chapter 6).</p>",
      "links": {
        "html": "/tutorials/tutorial-agent-gateway-mcp#chapter-8",
        "markdown": "/tutorials/tutorial-agent-gateway-mcp/8.md"
      }
    }
  ],
  "links": {
    "html": "/tutorials/tutorial-agent-gateway-mcp",
    "markdown": "/tutorials/tutorial-agent-gateway-mcp.md"
  }
}