
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.
概览
依据真实策略代码回答授权问题:在本地评估 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 头。超时与大小限制通过环境变量设置。
安装
在 SourceWeft 中
- 打开 控制台中的 Mcp Opa Authz,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
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.
That is enough for evaluate_policy. Point it at a PDP to get the rest:
Two layers, same question
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_policyreturnsdefinedalongsidevalue, 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
decisiona required member. A response missing it decodes into a Goboolasfalse— a broken PDP would look like a strict one. This server treats a missingdecisionas 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.sendwould let that policy make arbitrary HTTP requests from your laptop, andopa.runtime()would hand it your environment. Both are compiled out. See Security. - Batch decisions carry their index.
permit_on_first_permitlegitimately 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 noresultsmember, or a result of the wrong entity type, is an error.
Demo
Debugging a policy that is denying when it should not:
Then confirming against the PDP that actually runs:
Tools
evaluate_policy
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
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.
authzen_search
The AuthZEN Search APIs. search picks which entity is being listed; that entity carries only its type.
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.
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:
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
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:
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
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
Cursor and other MCP clients
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:
rbac.rego— role to permission mappingabac.rego— clearance level comparisonk8s_admission.rego— admission control: required labels
Layout
Flat on purpose. A single-binary MCP server does not need cmd/, internal/ or pkg/.
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.
Then check the archive you downloaded against that file:
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版本历史
5- v0.6.2最新Oct 26, 2026
- v0.6.1Oct 7, 2026
- v0.6.0Oct 3, 2026
- v0.3.1Sep 28, 2026
- v0.3.0Sep 16, 2026
评分
已满足适用检查项的 50%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分