Skip to content

0-draft/mcp-opa

Repository files navigation

mcp-opa

ci Go Reference License: MIT

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.

Install

go install github.com/0-draft/mcp-opa@latest

Pre-built signed binaries are on the releases page.

Quickstart

# Build and run the smoke test (no MCP client needed).
make smoke
# → ✓ smoke: allow=true

make smoke builds the binary, feeds it a synthetic MCP initializetools/listtools/call sequence over stdio, and asserts the policy returned allow=true. It exits non-zero on protocol failure.

Wire it to Claude Code

claude mcp add opa -- mcp-opa

Then 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).

Wire it to Cursor / other clients

{
  "mcpServers": {
    "opa": { "command": "mcp-opa" }
  }
}

Tool: evaluate_policy

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

examples/ has reference policies:

Layout

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/

Verify a release

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"

License

MIT.

About

MCP server exposing Open Policy Agent (OPA) Rego evaluation as a tool — for Claude Code, Cursor, and other MCP clients

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors