MCP server that exposes OPA Rego evaluation as a tool an LLM agent can call.
Paste a Rego module and an input doc into a Claude / Cursor session. The model picks the query, mcp-opa runs opa.Eval, returns the decision set.
go install github.com/0-draft/mcp-opa@latestPre-built signed binaries are on the releases page.
# Build and run the smoke test (no MCP client needed).
make smoke
# → ✓ smoke: allow=truemake smoke builds the binary, feeds it a synthetic MCP initialize →
tools/list → tools/call sequence over stdio, and asserts the policy
returned allow=true. It exits non-zero on protocol failure.
claude mcp add opa -- mcp-opaThen in a session: paste a Rego policy, an input doc, and ask the model what
the decision should be. The model calls evaluate_policy, gets the answer
from OPA (not from its training data).
| Param | Required | Description |
|---|---|---|
rego |
yes | Rego source with a package declaration. |
query |
yes | Rego query, e.g. data.example.allow. |
input_json |
no | JSON-encoded input document. |
data_json |
no | JSON-encoded base document for the data namespace. |
Returns the OPA ResultSet as JSON.
examples/ has reference policies:
rbac.rego— role → permission mappingabac.rego— clearance level comparisonk8s_admission.rego— admission control: required labels
Flat on purpose. A single-binary MCP server with one tool does not need
cmd/, internal/, or pkg/. When a second tool joins, the natural split is
a sibling file (evaluate.go, lint.go, ...) — still no subpackages.
.
├── main.go # server bootstrap + tool registration
├── main_test.go
├── examples/ # reference Rego policies
├── scripts/smoke.sh
├── .goreleaser.yml
└── .github/
Releases ship a cosign-signed checksum file (Sigstore keyless via GitHub OIDC) and a CycloneDX SBOM per archive.
TAG=v0.1.0
gh release download "$TAG" -R 0-draft/mcp-opa -p '*-checksums.txt*'
cosign verify-blob \
--certificate "mcp-opa-${TAG#v}-checksums.txt.pem" \
--signature "mcp-opa-${TAG#v}-checksums.txt.sig" \
--certificate-identity-regexp 'https://github.com/0-draft/mcp-opa/.github/workflows/release.yml@refs/tags/' \
--certificate-oidc-issuer 'https://token.actions.githubusercontent.com' \
"mcp-opa-${TAG#v}-checksums.txt"MIT.
{ "mcpServers": { "opa": { "command": "mcp-opa" } } }