Skip to main content
Glama

Partially evaluate a Rego query

rego_compile_query

Compile a Rego query into a SQL WHERE clause, UCAST tree, or Lucene query via an OPA server to translate policy filters for downstream systems.

Instructions

Run partial evaluation on a query -- substitute known values and return the residual policy. Defaults unknowns to ["input"] (treat input as unknown), so the residual encodes "given input X, this is what would have to be true." OPA does not use an input value at or under an unknown, so an input with the default unknowns is refused; to substitute known fields, name only the unknown ones, e.g. ["input.region"]. Use this for offline policy slicing or pre-computing decision sets. To turn a filter rule into a SQL WHERE clause, a UCAST tree or a Lucene query, load the policy into an OPA server and use opa_compile_query with target; the opa CLI has no such output.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "query": "<query>"
    },
    "name": "rego_compile_query"
  }
}

Input Schema

NameRequiredDescriptionDefault
inputNoInline input document.
pathsNoPolicy / data file or directory paths. Each must be inside an allowed root.
queryYesRego query to evaluate, e.g. "data.example.allow".
sourceNoInline Rego policy source. Optional: without `source` or `paths` the query runs on its own, which is enough to try a built-in or an expression.
partialNoRun partial evaluation rather than full evaluation.
unknownsNoRefs to treat as unknown during partial evaluation.
inputPathNoPath to a JSON input file. Mutually exclusive with `input`.
v0CompatibleNoRead the policy as Rego v0 (`--v0-compatible`), the syntax OPA used before 1.0: rules without `if`, partial sets as `deny[msg] { ... }`. Needed for a policy that has not been migrated, which OPA 1.x otherwise refuses to load. Where the tool also takes a query, the query is read as v0 too, with the future keywords imported so `in`, `every` and `some x in` still work in it.
strictBuiltinErrorsNoTreat builtin errors as fatal instead of returning undefined.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changedv0.8.0
    • changedInput schema / properties / v0Compatible / description
      Previous value: -"Read the policy as Rego v0 (`--v0-compatible`), the syntax OPA used before 1.0: rules without `if`, partial sets as `deny[msg] { ... }`. Needed for a policy that has not been migrated, which OPA 1.x otherwise refuses to load."New value: +"Read the policy as Rego v0 (`--v0-compatible`), the syntax OPA used before 1.0: rules without `if`, partial sets as `deny[msg] { ... }`. Needed for a policy that has not been migrated, which OPA 1.x otherwise refuses to load. Where the tool also takes a query, the query is read as v0 too, with the future keywords imported so `in`, `every` and `some x in` still work in it."
  2. Changed2 schema fields changedv0.7.0
    • changedInput schema / properties / source / description
      Previous value: -"Inline Rego policy source. Mutually exclusive with `paths`."New value: +"Inline Rego policy source. Optional: without `source` or `paths` the query runs on its own, which is enough to try a built-in or an expression."
    • addedInput schema / properties / v0Compatible
      Added value: +{
      +  "description": "Read the policy as Rego v0 (`--v0-compatible`), the syntax OPA used before 1.0: rules without `if`, partial sets as `deny[msg] { ... }`. Needed for a policy that has not been migrated, which OPA 1.x otherwise refuses to load.",
      +  "type": "boolean"
      +}
  3. Addedv0.1.13
  4. Removedv0.1.5
  5. Addedv0.1.2
  6. Removedv0.1.1
  7. First observedv0.1.0

TDQS

A4.5/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations supply only readOnlyHint=false and openWorldHint=true, so the description carries most of the burden and does well: it discloses the default value of `unknowns`, the meaning of the residual, and a specific failure mode where an input at or under an unknown is refused. It does not address cost, size limits on returned residuals, or why this is flagged non-read-only despite being a compilation step.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Front-loaded with the core definition and the default/refusal behavior immediately after, which is the right order. A few sentences are long and multi-clause, and the closing SQL/UCAST/Lucene tangent is dense, but each block still carries information an agent needs to call the tool correctly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 9-parameter tool with no output schema, the description covers purpose, default semantics, a refusal condition, and when to go to a different tool, which is most of what is needed. What remains thin is the shape of the returned residual (structural form, how to read it) and nothing is said about the v0/policy-loading params, though the schema documents those.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so the baseline is 3; this description goes beyond by explaining the interaction between `input` and the default `unknowns`, and by showing the idiomatic way to substitute known fields (`["input.region"]`). One weak spot: it references a `target` parameter that is not in this tool's schema, which could momentarily confuse an agent reading it as a local param.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific operation (partial evaluation) on a specific resource (a Rego query) and immediately defines what the output is: known values substituted, residual policy returned. It is clearly distinguishable from full-evaluation siblings and from the OPA-server `opa_compile_query` path named later.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Gives explicit use cases (offline policy slicing, pre-computing decision sets) and an explicit alternative, routing SQL WHERE / UCAST / Lucene translation to an OPA server with `opa_compile_query` plus `target`, noting the CLI has no such output. It also states the concrete condition that triggers a refusal (passing `input` under the default `unknowns`) and how to avoid it.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.