Mcp Opa Authz

io.github.kanywst由 GitHub 帳號 kanywst 發布v0.6.2更新於 Oct 26, 2026

Authorization answers from real policy code: evaluate Rego locally, or ask an AuthZEN 1.0 PDP.

已驗證STDIO僅桌面開發者工具安全與監控

概覽

AI 產生的概覽

依真實策略程式碼回答授權問題:在本機評估 Rego,或向 AuthZEN 1.0 策略決策點查詢。

可以做什麼
  • 在行程內評估 Rego 策略原始碼,可附帶 input/data 文件、選擇語法版本並回傳求值追蹤
  • 向策略決策點請求單次存取決策,帶入主體、動作、資源與情境
  • 對一組資源批次求值,並可選擇合併語意
  • 在 PDP 上搜尋誰可以執行某動作、主體可存取哪些資源、或可執行哪些動作,支援分頁
  • 讀取 PDP 的 AuthZEN 中介資料與所公布的端點
適用情境
適合助手需要依真實策略而非猜測回答「是否允許」的情況:撰寫或除錯手上有原始碼的 Rego,或向實際管控生產環境的 PDP 核對決策。它會把「策略未定義」與「PDP 未回應」和「拒絕」區分開來。
執行需求
以本機 stdio 行程執行,可透過 Homebrew、go install 或已發布的容器映像安裝。只有 evaluate_policy 不需設定;AuthZEN 相關工具需要 AUTHZEN_PDP_URL 指向可連線的 PDP,通常還需 AUTHZEN_PDP_TOKEN 作為 Authorization 標頭。逾時與大小限制以環境變數設定。
安裝前請注意
AUTHZEN_PDP_TOKEN 是密鑰,會以 Authorization 標頭送往 PDP,因此只應指向可信任的 PDP。evaluate_policy 會在伺服器行程內編譯並執行由模型產生的 Rego;網路類內建函式預設移除,MCP_OPA_ALLOW_NETWORK_BUILTINS 可重新啟用,風險自負。此伺服器只查詢決策,並不負責強制執行。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 Mcp Opa Authz,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

mcp-opa-authz

[ci] [Go Reference] [Go Report Card] [License: MIT]

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.

bash
brew install kanywst/tap/mcp-opa-authz# or, without Homebrew:go install github.com/kanywst/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

Two layers, same question

ToolAnswersNeeds
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_batchThe 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

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.
  • 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": [      "Enter data.rbac.allow",      "| Eval some role in roles[input.user]",      "| Fail roles[\"bob\"]",      …    ]  }
Bob has no entry in `roles` at all — the rule never reaches the permissioncheck. 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" }

Tools

evaluate_policy

ParamRequiredDescription
regoyesRego source with a package declaration.
queryyesRego query, e.g. data.example.allow.
input_jsonnoJSON-encoded input document.
data_jsonnoJSON-encoded base document for the data namespace.
rego_versionnov1 (default) or v0 for pre-OPA-1.0 syntax.
tracenoReturn a pretty-printed evaluation trace. Verbose; bounded at 4000 events, 200 lines, 1 KiB per line.

Returns defined, value, the raw OPA result_set (omitted with result_set_omitted past 256 KiB encoded), any print() output (200 lines of 1 KiB), and the trace when asked for.

authzen_evaluate

ParamRequiredDescription
subjectyesJSON object. AuthZEN requires type and id.
actionyesJSON object. AuthZEN requires name.
resourceyesJSON object. AuthZEN requires type and id.
contextnoJSON object with runtime context (IP, time, MFA strength).
pdp_urlnoOverride AUTHZEN_PDP_URL for this call.

Returns decision, the PDP's context if any, the pdp_url that answered, and the request_id sent as X-Request-ID — so a decision in a transcript can be found in the PDP's logs.

authzen_evaluate_batch

Same arguments, plus evaluations (a JSON array whose entries override the top-level defaults) and evaluations_semantic (execute_all, deny_on_first_deny, permit_on_first_permit). Capped at 100 entries per call. Without pdp_url, the endpoint is the access_evaluations_endpoint the PDP advertises in its metadata, or /access/v1/evaluations under the root of AUTHZEN_PDP_URL when it advertises none — the same resolution, cache and same-origin rule as authzen_search. endpoint_source in the result says which was used.

json
{  "subject": "{\"type\":\"user\",\"id\":\"alice\"}",  "action": "{\"name\":\"read\"}",  "evaluations": "[{\"resource\":{\"type\":\"doc\",\"id\":\"1\"}},{\"resource\":{\"type\":\"doc\",\"id\":\"2\"}}]"}

authzen_search

The AuthZEN Search APIs. search picks which entity is being listed; that entity carries only its type.

searchAskssubjectactionresource
subjectWho may do this to that resource?type onlyrequiredtype and id
resourceWhich resources of a type may the subject act on?type and idrequiredtype only
actionWhat may the subject do to the resource?type and idmust be omittedtype and id

context, pdp_url, page_limit and page_token are optional. Without pdp_url, the endpoint is the one the PDP advertises in its metadata (search_subject_endpoint etc.), as the specification requires, falling back to the default path (/access/v1/search/{subject,resource,action}) under the root of AUTHZEN_PDP_URL when it has no usable metadata. The metadata is cached per PDP for five minutes, and endpoint_source in the result says which one was used. An advertised endpoint has to be on the PDP's own origin, because the PDP token goes with the request; a cross-origin one is refused unless passed explicitly as pdp_url. Returns results, has_more and next_page_token; pass the token back as page_token, with every other argument unchanged, for the next page. A response whose page object has no next_token is an error even though the specification's own example has one: without it nothing says whether the list is complete.

json
{  "search": "resource",  "subject": "{\"type\":\"user\",\"id\":\"alice\"}",  "action": "{\"name\":\"read\"}",  "resource": "{\"type\":\"document\"}"}

authzen_discover

Fetches /.well-known/authzen-configuration from a PDP root. pdp_url may be a root or an evaluation endpoint — the known AuthZEN path suffix is stripped. For a PDP mounted under a prefix, the well-known string goes between the host and the prefix, as RFC 8615 and the specification place it (https://gw.example.com/.well-known/authzen-configuration/pdp); the older appended form (…/pdp/.well-known/authzen-configuration) is tried if that 404s. A document whose policy_decision_point is not the root it was fetched from is rejected, as the specification requires.

Standards conformance

Implements Authorization API 1.0, approved as an OpenID Final Specification in January 2026:

SectionStatus
Access Evaluation (POST /access/v1/evaluation)authzen_evaluate
Access Evaluations, batch (POST /access/v1/evaluations)authzen_evaluate_batch
PDP Metadata (GET /.well-known/authzen-configuration)authzen_discover
Subject / Action / Resource information modelRequired members validated before the request is sent
X-Request-ID correlationSent on every call, returned in the result
Search APIs (subject / resource / action, with pagination)authzen_search

Related work worth knowing about: the AuthZEN working group's COAZ profile binds AuthZEN to MCP tool calls themselves, so a gateway can authorize tools/call with an x-authzen-mapping declared in a tool's inputSchema. That is the enforcement side of the same problem — this server is the inspection side, and the two compose.

Configuration

VariableDefaultDescription
AUTHZEN_PDP_URL—Default Access Evaluation endpoint.
AUTHZEN_PDP_TOKEN—Authorization header value. A value with no scheme is sent as Bearer <token>.
AUTHZEN_PDP_TIMEOUT10sPer-request timeout.
AUTHZEN_PDP_MAX_RESPONSE_BYTES1048576Response read limit.
MCP_OPA_EVAL_TIMEOUT5sWall-clock limit on one Rego evaluation.
MCP_MAX_ARG_BYTES1048576Per-argument size limit.
MCP_OPA_ALLOW_NETWORK_BUILTINSfalseRe-enable the network built-ins. See below.

A malformed value stops the server at startup rather than being silently replaced by the default — a bound an operator believes is in place should be in place.

Security

evaluate_policy compiles and runs Rego that a model produced, inside this process. Three OPA built-ins are removed from the capability set for that reason:

Built-inWhy
http.sendArbitrary HTTP from wherever the server runs — a laptop or CI runner, inside whatever network boundary that sits behind. It is the whole SSRF surface, and it contradicts the tool's own description.
net.lookup_ip_addrEnough to exfiltrate input one DNS label at a time, with no port reachable.
opa.runtimeReturns the runtime configuration, including the process environment and every credential in it.

Time, JWT, UUID and random built-ins are untouched — those appear in real authorization policies. A policy using a removed built-in fails to compile with a message naming it, and pointing at MCP_OPA_ALLOW_NETWORK_BUILTINS for the cases where you genuinely want it.

The PDP client is constrained too: pdp_url must be an absolute http(s) URL with a host and no userinfo, redirects are refused rather than followed with the Authorization header attached, responses are read through a byte cap, and PDP error bodies are truncated before they reach the model's context.

Reporting a vulnerability: see SECURITY.md.

Running it

From source

bash
make smoke

Builds the binary, stands up a fake AuthZEN PDP, drives one real MCP stdio session through all five tools, and asserts each answered — including that http.send is still rejected. No MCP client and no real PDP needed.

Container

bash
docker run -i --rm \  -e AUTHZEN_PDP_URL=https://pdp.example.com/access/v1/evaluation \  ghcr.io/kanywst/mcp-opa-authz

Cursor and other MCP clients

jsonc
{  "mcpServers": {    "opa-authz": {      "command": "mcp-opa-authz",      "env": { "AUTHZEN_PDP_URL": "http://localhost:8181/access/v1/evaluation" }    }  }}

A local opa-authzen-plugin on :8181 works as the PDP. So does Topaz, Cerbos, Keycloak with its experimental AuthZEN support, or anything else on the interop list.

Examples

examples/ has reference Rego policies for evaluate_policy:

Layout

Flat on purpose. A single-binary MCP server does not need cmd/, internal/ or pkg/.

text
main.go               server bootstrap, CLI, tool registrationconfig.go             environment, bounds, defaultsargs.go               tool argument decodingtool_opa.go           evaluate_policyopa_capabilities.go   the Rego sandboxauthzen.go            AuthZEN 1.0 wire types and PDP clienttool_authzen.go       authzen_evaluate, _batch, _discovertool_authzen_search.go  authzen_searchscripts/smoke.sh      end-to-end MCP session

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.3.0gh release download "$TAG" -R kanywst/mcp-opa-authz -p '*-checksums.txt*'
cosign verify-blob \  --bundle "mcp-opa-authz-${TAG#v}-checksums.txt.sigstore.json" \  --certificate-identity-regexp 'https://github.com/kanywst/mcp-opa-authz/.github/workflows/release.yml@refs/tags/' \  --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. 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

MIT. See LICENSE.

來源:README.md,提交 8264c10

工具

0
SourceWeft 曾在隔離沙箱中以無憑證方式啟動該軟體包一次,以列出其工具,但未能完成:該軟體包類型無法在沙箱中執行。

版本歷史

5
  1. v0.6.2最新Oct 26, 2026
  2. v0.6.1Oct 7, 2026
  3. v0.6.0Oct 3, 2026
  4. v0.3.1Sep 28, 2026
  5. v0.3.0Sep 16, 2026

評分

已滿足適用檢查項的 50%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分

    請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。

  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具15 分

    請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。

  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分