# OPA behind AuthZEN: a policy decision point for MCP tool calls

> I wrote a Rego policy for MCP tool calls, tested it on OPA 1.22.4 and put an AuthZEN endpoint in front. A $90 payment over a $50 limit is denied with a reason.

- URL: https://iamops.dev/opa-authzen-mcp-tool-call-policy/
- Language: en
- Author: Argo
- Published: 2026-11-11
- Category: Labs
- Depth: Practitioner
- Time: 20 min
- Topics: OPA, AuthZEN, MCP, Authorization, AI agents

## TL;DR

- On 11 November 2026 [IndyKite](https://iamops.dev/opa-authzen-mcp-tool-call-policy/#what-the-lab-builds) and Obsidian each described the same shape: the agent or its runtime proposes a call, and a separate [decision point](https://iamops.dev/authzen-opa-cedar-explained/#what-authzen-standardises) answers for each call.
- I built that shape locally: a [Rego](https://iamops.dev/opa-authzen-mcp-tool-call-policy/#the-policy) policy in [OPA 1.22.4](https://iamops.dev/opa-authzen-mcp-tool-call-policy/#one-request-offline), six unit tests, and a small [AuthZEN](https://iamops.dev/opa-authzen-mcp-tool-call-policy/#the-authzen-endpoint) Access Evaluation endpoint in front of OPA. A $90 payment against a $50 limit came back as decision false with the reason over delegated limit.
- The policy [denies by default](https://iamops.dev/opa-authzen-mcp-tool-call-policy/#the-policy). An [unknown tool](https://iamops.dev/opa-authzen-mcp-tool-call-policy/#other-refusals-and-opa-going-away), a missing scope, a payment over the limit and an unconfirmed payment were all refused, and I broke one rule on purpose to see a test fail.
- When I stopped [OPA](https://iamops.dev/opa-authzen-mcp-tool-call-policy/#other-refusals-and-opa-going-away), my shim gave no answer at all, so the enforcement point has to treat a [missing decision](https://iamops.dev/opa-authzen-mcp-tool-call-policy/#other-refusals-and-opa-going-away) as a deny.
- [Not run](https://iamops.dev/opa-authzen-mcp-tool-call-policy/#what-was-not-run): a real MCP gateway as the enforcement point, [AuthZEN](https://iamops.dev/authzen-opa-cedar-explained/#what-authzen-standardises) conformance tests, the batch and search APIs, and decision logging.

On 11 November 2026 two vendors published the same idea from different sides. IndyKite released its Intent Agent, which turns a prompt into [AuthZEN](https://openid.net/specs/authorization-api-1_0-final.html) evaluations and, in the words of its [developer guide](https://developer.indykite.com/guides/guide-intent-agent), does not decide anything: the decision stays with the AuthZEN service. Obsidian described a [Runtime Policy Decision Engine](https://www.obsidiansecurity.com/blog/runtime-policy-decision-engine) where an MCP Security Proxy, an agent runtime or a customer gateway pauses a tool call, asks for a decision and applies the answer.

Both split the work the same way. Something that holds the request asks, and something else decides. I wanted to run that split on my own machine with nothing but open-source parts, so I built it: a policy engine (OPA) with a policy for MCP tool calls, and a thin AuthZEN endpoint in front of it.

I wrote a short [explainer of AuthZEN, OPA and Cedar](https://iamops.dev/authzen-opa-cedar-explained/).

## What the lab builds

- A Rego policy that takes an AuthZEN-shaped request (subject, action, resource, context) for an MCP `tools/call` and returns a boolean plus reasons.
- Six unit tests that run offline with OPA's test runner.
- A small Python endpoint that answers `POST /access/v1/evaluation` and the PDP metadata document, and forwards the request to OPA as input.
- Two refusals I wanted to see: a payment over the agent's delegated limit, and what happens when OPA is not there.

Money is in US cents. The agent may pay up to 5000 cents, which is $50.

![Sequence diagram: a caller sends an AuthZEN evaluation for an MCP tools/call to a small endpoint, which forwards it to OPA 1.22.4. A 9000-cent payment against a 5000-cent limit is denied with the reason over delegated limit, 4500 cents is allowed, other bad calls are denied with reasons, and a stopped OPA returns no HTTP answer.](https://iamops.dev/media/opa-authzen-mcp-tool-call-policy/00-flow.webp)

*The decision. The request names the agent, the tools/call, the tool, the amount and the confirmation. 9000 cents against a 5000-cent limit comes back as decision false with the reason over delegated limit. 4500 cents with confirmation is allowed. Missing scope, no confirmation or an unknown tool are denied with reasons. If OPA is stopped, the endpoint gives no HTTP answer at all.*

## Setup

OPA 1.22.4 is a single static binary from the [release page](https://github.com/open-policy-agent/opa/releases/tag/v1.22.4). The endpoint is a file of under 40 lines of Python 3.13 standard library. You also need curl and jq. There is no Docker, no database and no account. The lab opens ports 8181 for OPA and 8282 for the endpoint, both on localhost.

## The policy

The request is the one an enforcement point would build from an MCP [`tools/call`](https://modelcontextprotocol.io/specification/2026-07-28/server/tools). The subject is the agent with its scopes and limit, the resource is the tool, and the context carries the amount and whether the user confirmed.

The policy has a tool catalog that says which scope each tool needs and whether it moves money. `decision` is `false` unless a rule makes it `true`. Reading tools need their scope. A tool that moves money needs the scope, an amount at or under the limit, and a confirmation:

```rego
decision if {
	input.subject.type == "agent"
	input.action.name == "tools/call"
	tool.scope in input.subject.properties.scopes
	tool.moves_money
	input.context.amount_cents <= input.subject.properties.limit_cents
	input.context.user_confirmed
}
```

A second set, `reasons`, explains denials. The full files are in the lab steps below.

## Tests first

The `opa test` runner finds `test_` rules in `_test.rego` files. I wrote six: a read is allowed, a write without the scope is denied, a confirmed payment within the limit is allowed, a payment over the limit is denied with the right reason, an unconfirmed payment is denied, and an unknown tool is denied. `opa check --strict` and `opa fmt` passed before the tests ran.

![Terminal output of OPA 1.22.4: version information, fmt and strict check passing, and six unit tests listed as PASS with a summary of 6 out of 6.](https://iamops.dev/media/opa-authzen-mcp-tool-call-policy/02-tests.webp)

*Checks and tests. The format check, the strict check and all six tests pass on OPA 1.22.4.*

To see that the tests can fail, I deleted the `user_confirmed` line from the second rule in a copy. Five tests still passed and `test_payment_needs_confirmation` failed. That is the test doing its job.

## One request, offline

`opa eval` takes the policy and one request file without starting a server. The request is the agent `support-bot` with both scopes and a 5000-cent limit, calling `send_payment` for 9000 cents with the user's confirmation.

![Terminal output of two opa eval commands: the decision is false and the reasons set contains over delegated limit.](https://iamops.dev/media/opa-authzen-mcp-tool-call-policy/03-eval.webp)

*A $90 payment against a $50 limit. The decision is false and the reason is "over delegated limit".*

## The AuthZEN endpoint

OPA runs as a server on port 8181, and the endpoint on port 8282 sits in front of it. The [AuthZEN spec](https://openid.net/specs/authorization-api-1_0-final.html) defines the request as subject, action, resource and context, and the response as a required boolean `decision` with an optional `context`. It leaves the content of that context to the implementation. I put the denial reasons under `reason_admin`, which is the key its non-normative example uses. The metadata document lives at `/.well-known/authzen-configuration`.

![Terminal output: the PDP metadata document with two URLs, a denial with decision false and the reason over delegated limit, and an allow with decision true after the amount is changed to 4500 cents.](https://iamops.dev/media/opa-authzen-mcp-tool-call-policy/04-authzen.webp)

*The same request through AuthZEN. 9000 cents is denied with a reason. Changing only the amount to 4500 cents returns decision true.*

The endpoint is a teaching shim. It does not authenticate callers, does not validate input, and has no batch or search API, so it is not a conformant PDP.

## Other refusals, and OPA going away

I sent three more requests through a small shell function called `ask`. With only the read scope, the payment was denied for a missing scope, and for the limit too, because the amount was still 9000. With a 4500-cent amount and `user_confirmed` set to false, it was denied for the missing confirmation. A tool named `delete_account` was denied as unknown.

![Terminal output of three denied requests with reasons missing scope and over delegated limit, user did not confirm, and unknown tool, followed by a request after OPA was stopped that returns HTTP status 000.](https://iamops.dev/media/opa-authzen-mcp-tool-call-policy/05-denials.webp)

*Three more denials. Each comes with its reasons. After OPA is stopped, the request gets no HTTP answer at all, shown by curl as 000.*

Then I stopped OPA and sent the 4500-cent request again. The shim raised an exception and dropped the connection, so curl printed `000`. There was no `decision: false` to enforce. A gateway that waits for a true can treat that as a deny. A gateway that only blocks on an explicit false would let the call through. I did not test a real gateway, so this is a reason to check yours, not a finding about any product.

## Gotchas

- **Unknown tools need no rule.** When the tool is not in the catalog, `tool` is undefined, so every `decision` rule is undefined and the default `false` applies. A test pins that down.
- **Reasons can stack.** `reasons` is a set, and the request with only the read scope returned two at once.
- **The policy trusts the context.** `user_confirmed` is only as good as the enforcement point that sets it. A model must never be able to fill it in. IndyKite's guide makes a similar point for the subject: it comes from the caller's verified identity, never from the prompt text.
- **Default deny is a choice.** Obsidian's post says tool calls that match no policy proceed. Mine are refused. Neither is wrong, but decide on purpose.

## What I would do with this

1. Put the enforcement point at the gateway or proxy that sees every `tools/call`, not inside the agent.
2. Build the subject from the verified token and the delegation record, not from anything the model wrote.
3. Keep the policy in a repository with its tests, and run `opa test` in CI.
4. Make the enforcement point fail closed, and test that by stopping the decision point.

## What was not run

I did not run a real MCP gateway as the enforcement point. I did not run AuthZEN conformance tests, the batch evaluations API, the search APIs or any other AuthZEN decision point. I did not test OPA bundles, decision logs or policy performance. There is no recording for this lab. The lab uses no credentials or tokens.

*Terminal images were rendered from the saved output of the run on 20 November 2026.*

## Repeat this lab

This lab needs Linux on amd64, curl, jq and Python 3.13. Plan for about 20 minutes. Open each step, copy the blocks and compare the output with mine.

Every value in angle brackets is a placeholder for your own test environment. Nothing on this page is a real identifier or secret.

**Set your variables once** `env.sh` (bash)

```bash
# Paste into every terminal you use for this lab. No secrets are involved.
export OPA_VERSION="1.22.4"
export OPA_URL="http://localhost:8181"
export PDP_URL="http://localhost:8282"
```

### Step 1: Download OPA

**Goal.** Fetch the single static OPA binary at a pinned version and print its version.

**Prerequisites**

- Linux on amd64 (for macOS or arm64 take the matching file from the release page), curl, jq and Python 3.13
- Ports 8181 and 8282 free

`get-opa.sh` (bash)

```bash
curl -sSL -o opa "https://github.com/open-policy-agent/opa/releases/download/v$OPA_VERSION/opa_linux_amd64_static"
chmod +x opa
./opa version | head -1
```

**Expected output**

```text
Version: 1.22.4
```

### Step 2: Write the policy

**Goal.** Create the Rego policy: a tool catalog, a default of false, two decision rules and a set of denial reasons.

**Prerequisites**

- Step 1 done, in the same folder

`write-policy.sh` (bash)

```bash
cat > mcp_tools.rego <<'EOF'
# Which MCP tools may an agent call? The input has the shape of an
# AuthZEN Access Evaluation request: subject, action, resource, context.
package mcp.tools

default decision := false

# Tool catalog: the scope each tool needs and whether it moves money.
catalog := {
	"get_balance": {"scope": "payments.read", "moves_money": false},
	"list_transactions": {"scope": "payments.read", "moves_money": false},
	"send_payment": {"scope": "payments.write", "moves_money": true},
}

tool := catalog[input.resource.id]

decision if {
	input.subject.type == "agent"
	input.action.name == "tools/call"
	tool.scope in input.subject.properties.scopes
	not tool.moves_money
}

decision if {
	input.subject.type == "agent"
	input.action.name == "tools/call"
	tool.scope in input.subject.properties.scopes
	tool.moves_money
	input.context.amount_cents <= input.subject.properties.limit_cents
	input.context.user_confirmed
}

# Explain denials, the way a PDP would put reasons in the AuthZEN context.
reasons contains "unknown tool" if not catalog[input.resource.id]

reasons contains "missing scope" if {
	tool
	not tool.scope in input.subject.properties.scopes
}

reasons contains "over delegated limit" if {
	tool.moves_money
	input.context.amount_cents > input.subject.properties.limit_cents
}

reasons contains "user did not confirm" if {
	tool.moves_money
	not input.context.user_confirmed
}
EOF
head -3 mcp_tools.rego
```

**Expected output**

```text
# Which MCP tools may an agent call? The input has the shape of an
# AuthZEN Access Evaluation request: subject, action, resource, context.
package mcp.tools
```

### Step 3: Write the tests and run them

**Goal.** Write six unit tests, then run the formatter, the strict checker and the test runner. All of them should pass.

**Prerequisites**

- The policy file from the previous step

`unit-tests.sh` (bash)

```bash
cat > mcp_tools_test.rego <<'EOF'
package mcp.tools_test

import data.mcp.tools

agent(scopes, limit) := {"type": "agent", "id": "support-bot", "properties": {"scopes": scopes, "limit_cents": limit}}

call(subject, tool, ctx) := {"subject": subject, "action": {"name": "tools/call"}, "resource": {"type": "mcp_tool", "id": tool}, "context": ctx}

test_read_allowed if {
	tools.decision with input as call(agent(["payments.read"], 0), "get_balance", {})
}

test_write_needs_scope if {
	not tools.decision with input as call(agent(["payments.read"], 50000), "send_payment", {"amount_cents": 100, "user_confirmed": true})
}

test_payment_within_limit_confirmed if {
	tools.decision with input as call(agent(["payments.write"], 5000), "send_payment", {"amount_cents": 4500, "user_confirmed": true})
}

test_payment_over_limit_denied if {
	r := tools.reasons with input as call(agent(["payments.write"], 5000), "send_payment", {"amount_cents": 9000, "user_confirmed": true})
	"over delegated limit" in r
}

test_payment_needs_confirmation if {
	not tools.decision with input as call(agent(["payments.write"], 5000), "send_payment", {"amount_cents": 4500, "user_confirmed": false})
}

test_unknown_tool_denied if {
	not tools.decision with input as call(agent(["payments.write"], 5000), "delete_account", {})
}
EOF
./opa fmt --list --fail . && ./opa check --strict . && echo "fmt + strict check: OK"
./opa test . -v
```

**Expected output**

```text
fmt + strict check: OK
mcp_tools_test.rego:30:
data.mcp.tools_test.test_unknown_tool_denied: PASS (970.514µs)
mcp_tools_test.rego:17:
data.mcp.tools_test.test_payment_within_limit_confirmed: PASS (984.282µs)
mcp_tools_test.rego:26:
data.mcp.tools_test.test_payment_needs_confirmation: PASS (1.131509ms)
mcp_tools_test.rego:21:
data.mcp.tools_test.test_payment_over_limit_denied: PASS (1.197352ms)
mcp_tools_test.rego:13:
data.mcp.tools_test.test_write_needs_scope: PASS (1.433506ms)
mcp_tools_test.rego:9:
data.mcp.tools_test.test_read_allowed: PASS (1.255784ms)
--------------------------------------------------------------------------------
PASS: 6/6
```

### Step 4: Evaluate one request offline

**Goal.** Write an AuthZEN-shaped request for a $90 payment against a $50 limit and evaluate it with opa eval, without a server.

**Prerequisites**

- Amounts are in cents: 9000 is $90 and 5000 is $50

`eval-offline.sh` (bash)

```bash
cat > request.json <<'EOF'
{
  "subject": { "type": "agent", "id": "support-bot",
               "properties": { "scopes": ["payments.read", "payments.write"], "limit_cents": 5000 } },
  "action": { "name": "tools/call" },
  "resource": { "type": "mcp_tool", "id": "send_payment" },
  "context": { "amount_cents": 9000, "user_confirmed": true }
}
EOF
./opa eval -d mcp_tools.rego -i request.json 'data.mcp.tools.decision' --format pretty
./opa eval -d mcp_tools.rego -i request.json 'data.mcp.tools.reasons' --format pretty
```

**Expected output**

```text
false
[
  "over delegated limit"
]
```

### Step 5: Run OPA as a server and add the AuthZEN endpoint

**Goal.** Serve the policy from OPA on port 8181, check its own decision API, then start the small Python endpoint on port 8282 and read its metadata document.

**Prerequisites**

- Steps 2 to 4 done
- The endpoint is a teaching shim, not a conformant AuthZEN PDP; keep it on localhost

`serve-opa.sh` (bash)

```bash
./opa run --server --addr localhost:8181 mcp_tools.rego > opa-server.log 2>&1 &
sleep 2
curl -s $OPA_URL/health
curl -s $OPA_URL/v1/data/mcp/tools/decision -d '{"input":'"$(cat request.json)"'}'
```

`start-endpoint.sh` (bash)

```bash
cat > authzen_pdp.py <<'EOF'
"""A minimal AuthZEN Access Evaluation endpoint in front of OPA.
Standard library only (Python 3.10+). OPA runs on :8181 with mcp_tools.rego loaded.
This is a teaching shim, not a conformant AuthZEN PDP."""
import json
import urllib.request
from http.server import BaseHTTPRequestHandler, HTTPServer

OPA = "http://localhost:8181/v1/data/mcp/tools"


class PDP(BaseHTTPRequestHandler):
    def _send(self, code, body):
        data = json.dumps(body).encode()
        self.send_response(code)
        self.send_header("content-type", "application/json")
        self.end_headers()
        self.wfile.write(data)

    def do_GET(self):
        if self.path == "/.well-known/authzen-configuration":
            base = f"http://{self.headers['host']}"
            return self._send(200, {"policy_decision_point": base,
                                    "access_evaluation_endpoint": f"{base}/access/v1/evaluation"})
        self._send(404, {})

    def do_POST(self):
        if self.path != "/access/v1/evaluation":
            return self._send(404, {})
        request = json.loads(self.rfile.read(int(self.headers["content-length"])))
        opa_req = urllib.request.Request(OPA, data=json.dumps({"input": request}).encode(),
                                         headers={"content-type": "application/json"})
        result = json.load(urllib.request.urlopen(opa_req)).get("result", {})
        body = {"decision": bool(result.get("decision"))}
        if not body["decision"]:
            body["context"] = {"reason_admin": {"403": ", ".join(sorted(result.get("reasons", [])))}}
        self._send(200, body)


HTTPServer(("127.0.0.1", 8282), PDP).serve_forever()
EOF
python3 authzen_pdp.py > pdp.log 2>&1 &
sleep 1
curl -s $PDP_URL/.well-known/authzen-configuration | jq .
```

**Expected output**

```text
{}
{"result":false}
{
  "policy_decision_point": "http://localhost:8282",
  "access_evaluation_endpoint": "http://localhost:8282/access/v1/evaluation"
}
```

### Step 6: Ask for a decision: $90, then $45

**Goal.** Send the request to the AuthZEN evaluation endpoint. It should deny with a reason. Then change only the amount to 4500 cents and ask again.

**Prerequisites**

- OPA and the endpoint are running

`evaluate.sh` (bash)

```bash
curl -s $PDP_URL/access/v1/evaluation -H 'content-type: application/json' -d @request.json | jq .
jq '.context.amount_cents=4500' request.json \
  | curl -s $PDP_URL/access/v1/evaluation -H 'content-type: application/json' -d @- | jq .
```

**Expected output**

```text
{
  "decision": false,
  "context": {
    "reason_admin": {
      "403": "over delegated limit"
    }
  }
}
{
  "decision": true
}
```

### Step 7: Try more denials, then stop OPA

**Goal.** Send three more requests: a missing scope, an unconfirmed payment and an unknown tool. Then stop OPA and ask again to see that no decision comes back.

**Prerequisites**

- The endpoint is running

`denials.sh` (bash)

```bash
ask() { curl -s $PDP_URL/access/v1/evaluation -H 'content-type: application/json' -d @- | jq -c .; }
jq '.subject.properties.scopes=["payments.read"]' request.json | ask
jq '.context.user_confirmed=false | .context.amount_cents=4500' request.json | ask
jq '.resource.id="delete_account"' request.json | ask
# Now stop OPA and ask again: no decision comes back
pkill -f "opa run --server"
sleep 1
curl -s -o /dev/null -w "%{http_code}\n" -m 5 $PDP_URL/access/v1/evaluation -H 'content-type: application/json' -d @request.json
```

**Expected output**

```text
{"decision":false,"context":{"reason_admin":{"403":"missing scope, over delegated limit"}}}
{"decision":false,"context":{"reason_admin":{"403":"user did not confirm"}}}
{"decision":false,"context":{"reason_admin":{"403":"unknown tool"}}}
000
```

### Step 8: Clean up

**Goal.** Stop both processes and delete the files the lab created.

**Prerequisites**

- Nothing else uses ports 8181 and 8282

`cleanup.sh` (bash)

```bash
pkill -f "opa run --server" || true
pkill -f authzen_pdp.py || true
rm -f opa mcp_tools.rego mcp_tools_test.rego request.json authzen_pdp.py opa-server.log pdp.log
unset -f ask
# check: nothing listens on ports 8181 and 8282 any more
curl -s -o /dev/null -w "%{http_code}\n" "$OPA_URL/health"
curl -s -o /dev/null -w "%{http_code}\n" "$PDP_URL/"
```

**Expected output**

```text
000
000
```


## Sources

- [IndyKite, IndyKite open sources the Intent Agent (11 Nov 2026)](https://www.indykite.ai/news/indykite-open-sources-the-intent-agent-to-set-a-standard-for-how-ai-agents-express-intent)
- [IndyKite Developer Hub, Intent Agent: turn a prompt into AuthZEN evaluations](https://developer.indykite.com/guides/guide-intent-agent)
- [Obsidian Security, Introducing the Runtime Policy Decision Engine](https://www.obsidiansecurity.com/blog/runtime-policy-decision-engine)
- [Help Net Security, Obsidian expands AI agent security with runtime policy enforcement (11 Nov 2026)](https://www.helpnetsecurity.com/2026/11/11/obsidian-security-runtime-policy-decision-engine/)
- [OpenID AuthZEN Authorization API 1.0 (Final)](https://openid.net/specs/authorization-api-1_0-final.html)
- [Open Policy Agent: Policy Testing](https://www.openpolicyagent.org/docs/policy-testing)
- [Open Policy Agent: REST API](https://www.openpolicyagent.org/docs/rest-api)
- [Open Policy Agent: v1.22.4 release](https://github.com/open-policy-agent/opa/releases/tag/v1.22.4)
- [Model Context Protocol specification: Tools](https://modelcontextprotocol.io/specification/2026-07-28/server/tools)

Discuss: [X](https://x.com/iamopsdev/status/2124171025315213384) | [LinkedIn](https://www.linkedin.com/feed/update/urn:li:share:7529937437150707714)
