Skip to main content
Glama
mcp-opa-authz

mcp-opa-authz

mcp-opa-authz

ci Go Reference Go Report Card License: Apache-2.0 Glama

Stop letting your agent guess at authorization. This is an MCP server that answers "is this allowed?" from real policy code — either Rego you hand it, or the OpenID AuthZEN 1.0 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.

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:

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

The quick start 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.

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.

Related MCP server: enterprise-auth-mcp-server

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.

  • 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:

> 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:

> 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

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 has the details.

Reporting a vulnerability: see SECURITY.md.

Examples

examples/ has reference Rego policies for evaluate_policy:

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.

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:

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

Contributing

Issues and pull requests are welcome — see CONTRIBUTING.md. 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 and NOTICE. Releases up to v0.7.0 were published under MIT.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers