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

# Overview

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

<img src="https://raw.githubusercontent.com/dyokto/.github/main/assets/projects/mcp-opa-authz.png" width="96" alt="mcp-opa-authz">

# mcp-opa-authz


**Stop letting your agent guess at authorization.** This is an [MCP](https://modelcontextprotocol.io) server that answers "is this allowed?" from real policy code — either Rego you hand it, or the [OpenID AuthZEN 1.0](https://openid.net/specs/authorization-api-1_0.html) PDP that actually governs your system.

Ask a model whether Alice may delete that document and it will produce a confident, plausible, unfalsifiable answer. Give it these tools and the answer comes from the policy.

<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://github.com/dyokto/mcp-opa-authz/raw/main/demo/demo-dark.gif">
  <img alt="An MCP tools/call to evaluate_policy over stdio with examples/rbac.rego: bob writing is defined and false, the trace shows bob resolving to viewer, viewer granting only read, and line 25 failing on write equals read; alice, an editor, gets true" src="https://github.com/dyokto/mcp-opa-authz/raw/main/demo/demo-light.gif" width="800">
</picture>

```bash
brew install kanywst/tap/mcp-opa-authz
# or, without Homebrew:
go install github.com/dyokto/mcp-opa-authz@latest

claude mcp add opa-authz -- mcp-opa-authz
```

That is enough for `evaluate_policy`. Point it at a PDP to get the rest:

```bash
claude mcp add opa-authz \
  --env AUTHZEN_PDP_URL=http://localhost:8181/access/v1/evaluation \
  -- mcp-opa-authz
```

The [quick start](https://dyokto.github.io/mcp-opa-authz/quickstart/) installs it, connects an MCP client, and asks `evaluate_policy` for one denied and one allowed answer without a model. Docs site: <https://dyokto.github.io/mcp-opa-authz/>.

## Two layers, same question

| Tool | Answers | Needs |
| --- | --- | --- |
| `evaluate_policy` | "What does this Rego say?" Evaluated in-process by [OPA](https://www.openpolicyagent.org/). | Nothing external |
| `authzen_evaluate` | "What does the PDP that governs this system say?" | A reachable PDP |
| `authzen_evaluate_batch` | The same, over a list — which of these may the subject touch? | A reachable PDP |
| `authzen_search` | "Who may…", "which resources may…", "what may…" — the PDP lists what is permitted. | A PDP with the Search APIs |
| `authzen_discover` | "Which endpoints does this PDP offer?" | A reachable PDP |
| `coaz_map` | "What request does a COAZ-MCP enforcement point send for this MCP call?" | Nothing external; a PDP with `evaluate` |

Use `evaluate_policy` while authoring or debugging a policy you have the source of. Use `authzen_evaluate` when the decision has to come from production, not from a policy pasted into the chat. The server's MCP instructions tell the model the same thing, so it usually picks correctly on its own.

## What makes this different from `opa eval` in a shell tool

An agent given shell access can already run `opa eval`. What it cannot do is get an answer it is allowed to trust:

- **Undefined is not false.** A Rego query with no matching rule and no default returns `[]`. Every model reads that as a deny. `evaluate_policy` returns `defined` alongside `value`, so "the policy denied" and "the policy has no opinion" stop being the same answer.
- **A PDP that did not answer is not a deny.** AuthZEN makes `decision` a required member. A response missing it decodes into a Go `bool` as `false` — a broken PDP would look like a strict one. This server treats a missing `decision` as a failure, never as a deny. Same for a 401: that means *this server* failed to authenticate, not that the subject was denied, and the error says so.
- **The policy runs in a sandbox.** Rego handed to an MCP server was written by a model, from text that may have come from a web page. OPA's `http.send` would let that policy make arbitrary HTTP requests from your laptop, and `opa.runtime()` would hand it your environment. Both are compiled out. See [Security](#security).
- **Batch decisions carry their index.** `permit_on_first_permit` legitimately returns fewer decisions than you sent. Zipping the arrays would attach a decision to the wrong resource.
- **An empty search is not a failed search.** `results: []` means nothing is permitted; a response with no `results` member, or a result of the wrong entity type, is an error.

## Demo

Debugging a policy that is denying when it should not:

```text
> Why is bob getting denied on doc-1? Here's the policy and the input.

  evaluate_policy(rego=…, query="data.rbac.allow", input_json=…, trace=true)

  {
    "defined": true,
    "value": false,
    "printed": ["checking roles for bob"],
    "trace": [
      "policy.rego:16     | Enter data.rbac.allow",
      …
      "policy.rego:17     | | Eval internal.print([__local8__, __local9__])",
      "policy.rego:18     | | Eval __local10__ = input.user",
      "policy.rego:18     | | Unify __local10__ = input.user",
      "policy.rego:18     | | Unify \"bob\" = __local10__",
      "policy.rego:18     | | Eval role = data.rbac.roles[__local10__][__local0__]",
      …
      "policy.rego:18     | | Fail role = data.rbac.roles[__local10__][__local0__]",
      …
      "policy.rego:3      | Enter data.rbac.allow",
      "policy.rego:3      | | Eval true",
      "policy.rego:3      | | Unify true = _",
      "policy.rego:3      | | Exit data.rbac.allow early",
      …
    ]
  }

Line 18 fails on `roles["bob"]`: bob has no entry in `roles` at all, so the
rule body never reaches the permission check and the `default` on line 3
answers. Adding "bob": {"viewer"} fixes it.
```

Then confirming against the PDP that actually runs:

```text
> Does production agree?

  authzen_evaluate(subject={"type":"user","id":"bob"}, …)

  { "decision": false, "context": { "reason": "no role binding" },
    "request_id": "3f9c…", "pdp_url": "https://pdp.internal/access/v1/evaluation" }
```

## Documentation

- [docs/quickstart.md](https://dyokto.github.io/mcp-opa-authz/quickstart/): install, connect a client, then one denied and one allowed decision over stdio
- [docs/tools.md](https://dyokto.github.io/mcp-opa-authz/tools/): every tool's parameters and results
- [docs/configuration.md](https://dyokto.github.io/mcp-opa-authz/configuration/): environment variables and their defaults
- [docs/running.md](https://dyokto.github.io/mcp-opa-authz/running/): from source, in a container, and in Cursor and other MCP clients; PDPs it works with
- [docs/standards.md](https://dyokto.github.io/mcp-opa-authz/standards/): which parts of AuthZEN 1.0 and COAZ-MCP are implemented
- [docs/sandbox.md](https://dyokto.github.io/mcp-opa-authz/sandbox/): the Rego sandbox and the limits on the PDP client
- [CHANGELOG.md](https://dyokto.github.io/mcp-opa-authz/changelog/), [CONTRIBUTING.md](https://dyokto.github.io/mcp-opa-authz/contributing/), [SECURITY.md](https://dyokto.github.io/mcp-opa-authz/security/)

## Security

`evaluate_policy` runs model-written Rego with `http.send`, `net.lookup_ip_addr` and `opa.runtime` removed, and the PDP client refuses redirects and caps what it reads. [docs/sandbox.md](https://dyokto.github.io/mcp-opa-authz/sandbox/) has the details.

Reporting a vulnerability: see [SECURITY.md](https://dyokto.github.io/mcp-opa-authz/security/).

## Examples

[`examples/`](https://dyokto.github.io/mcp-opa-authz/examples/) has reference Rego policies for `evaluate_policy`:

- [`rbac.rego`](https://github.com/dyokto/mcp-opa-authz/blob/main/examples/rbac.rego) — role to permission mapping
- [`abac.rego`](https://github.com/dyokto/mcp-opa-authz/blob/main/examples/abac.rego) — clearance level comparison
- [`k8s_admission.rego`](https://github.com/dyokto/mcp-opa-authz/blob/main/examples/k8s_admission.rego) — admission control: required labels

## Verifying a release

Releases ship a `cosign`-signed checksum file (Sigstore keyless via GitHub OIDC) and a CycloneDX SBOM per archive. The signature and its certificate travel together in one Sigstore bundle, `*-checksums.txt.sigstore.json`.

```bash
TAG=v0.8.0
gh release download "$TAG" -R dyokto/mcp-opa-authz -p '*-checksums.txt*'

# The workflow that signed the release: dyokto/mcp-opa-authz for releases after
# v0.7.0, kanywst/mcp-opa-authz (the repository's earlier name) up to v0.7.0.
SIGNER=dyokto/mcp-opa-authz

cosign verify-blob \
  --bundle "mcp-opa-authz-${TAG#v}-checksums.txt.sigstore.json" \
  --certificate-identity "https://github.com/${SIGNER}/.github/workflows/release.yml@refs/tags/${TAG}" \
  --certificate-oidc-issuer 'https://token.actions.githubusercontent.com' \
  "mcp-opa-authz-${TAG#v}-checksums.txt"
```

Then check the archive you downloaded against that file:

```bash
sha256sum -c "mcp-opa-authz-${TAG#v}-checksums.txt" --ignore-missing
```

## Contributing

Issues and pull requests are welcome — see [CONTRIBUTING.md](https://dyokto.github.io/mcp-opa-authz/contributing/). Good first contributions: another example policy, a PDP this has not been tried against, or a gap against the AuthZEN text.

This repo is the merge of the former `0-draft/mcp-opa` and `0-draft/mcp-authzen`. Both histories are preserved here.

## License

Apache-2.0. See [LICENSE](https://github.com/dyokto/mcp-opa-authz/blob/main/LICENSE) and [NOTICE](https://github.com/dyokto/mcp-opa-authz/blob/main/NOTICE). Releases up to v0.7.0 were published under MIT.
