Skip to main content
Glama
OrygnsCode

opa-mcp-server

Compile (partially evaluate) a query on OPA

opa_compile_query

Partially evaluate a Rego query by sending it to OPA's compile endpoint. Returns the residual query after substituting known data.

Instructions

Send a query to the OPA server's /v1/compile endpoint for partial evaluation. Returns the residual query — what remains after substituting in everything that's known.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesRego query to compile, e.g. "data.rbac.allow == true".
inputNoOptional partial input document.
unknownsNoRefs to treat as unknown (default: ["input"]).

Implementation Reference

  • Handler function for the opa_compile_query tool. Sends a POST to OPA's /v1/compile endpoint for partial evaluation, returning the residual query.
      async ({ query, input, unknowns }) => {
        return withToolEnvelope<{ result: unknown }>(config, async () => {
          try {
            const body: Record<string, unknown> = { query };
            if (input !== undefined) body['input'] = input;
            body['unknowns'] = unknowns?.length ? unknowns : ['input'];
            const data = await opa.request<{ result: unknown }>({
              method: 'POST',
              path: '/v1/compile',
              body,
            });
            return ok({ result: data.result });
          } catch (e) {
            return mapOpaClientError(e);
          }
        });
      },
    );
  • Input schema and metadata for the opa_compile_query tool, defining the 'query' (required string), 'input' (optional unknown), and 'unknowns' (optional array of strings) parameters.
    {
      title: 'Compile (partially evaluate) a query on OPA',
      description:
        "Send a query to the OPA server's `/v1/compile` endpoint for partial evaluation. Returns the residual query — what remains after substituting in everything that's known.",
      inputSchema: {
        query: z.string().min(1).describe('Rego query to compile, e.g. "data.rbac.allow == true".'),
        input: z.unknown().optional().describe('Optional partial input document.'),
        unknowns: z
          .array(z.string())
          .optional()
          .describe('Refs to treat as unknown (default: ["input"]).'),
      },
    },
  • Tool registration on the MCP server via server.registerTool, within the registerDecisionTools function exported from the decisions module.
    server.registerTool(
      'opa_compile_query',
      {
        title: 'Compile (partially evaluate) a query on OPA',
        description:
          "Send a query to the OPA server's `/v1/compile` endpoint for partial evaluation. Returns the residual query — what remains after substituting in everything that's known.",
        inputSchema: {
          query: z.string().min(1).describe('Rego query to compile, e.g. "data.rbac.allow == true".'),
          input: z.unknown().optional().describe('Optional partial input document.'),
          unknowns: z
            .array(z.string())
            .optional()
            .describe('Refs to treat as unknown (default: ["input"]).'),
        },
      },
      async ({ query, input, unknowns }) => {
        return withToolEnvelope<{ result: unknown }>(config, async () => {
          try {
            const body: Record<string, unknown> = { query };
            if (input !== undefined) body['input'] = input;
            body['unknowns'] = unknowns?.length ? unknowns : ['input'];
            const data = await opa.request<{ result: unknown }>({
              method: 'POST',
              path: '/v1/compile',
              body,
            });
            return ok({ result: data.result });
          } catch (e) {
            return mapOpaClientError(e);
          }
        });
      },
    );
  • Error mapping helper used by the tool handler to translate OPA client exceptions into structured error envelopes.
    export function mapOpaClientError(
      e: unknown,
      notFoundCode: ToolErrorCode = 'UNKNOWN_ERROR',
    ): ToolEnvelope<never> {
      if (e instanceof OpaUnreachableError) {
        return err('OPA_UNREACHABLE', `OPA server unreachable at ${e.url}`, {
          hint: 'Confirm OPA_URL points at a running OPA server (e.g. `curl $OPA_URL/health`).',
          details: { url: e.url },
        });
      }
      if (e instanceof OpaAuthError) {
        return err('OPA_AUTH_FAILED', 'OPA rejected the request with 401 Unauthorized.', {
          hint: 'Set OPA_TOKEN to a valid bearer token, or remove the auth requirement on the OPA server.',
        });
      }
      if (e instanceof OpaHttpError) {
        if (e.status === 404) {
          return err(notFoundCode, `OPA returned 404 Not Found.`, {
            details: { status: e.status, body: e.body },
          });
        }
        return err('UNKNOWN_ERROR', `OPA returned HTTP ${e.status}.`, {
          details: { status: e.status, body: e.body },
        });
      }
      const message = e instanceof Error ? e.message : 'Unknown error';
      return err('UNKNOWN_ERROR', message, {
        details: e instanceof Error ? { stack: e.stack } : { value: e },
      });
    }
Behavior2/5

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

With no annotations provided, the description must fully disclose behavioral traits. It only states the return value (residual query) but omits side effects (network call), error conditions, required permissions, and performance implications. The agent lacks critical information about what happens during execution.

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

Conciseness5/5

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

Two concise sentences with a front-loaded verb ('Send'). Every word serves a purpose—describing action, endpoint, and outcome. No extraneous information.

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

Completeness2/5

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

Without output schema or annotations, the description should compensate by explaining return values, error handling, and usage examples. It only mentions 'residual query' without elaboration. For a tool making a server request, this is insufficient for robust agent decision-making.

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

Parameters3/5

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

Schema description coverage is 100%, so the baseline is 3. The description adds context about partial evaluation and residual query but does not provide additional parameter-level details beyond what the schema already offers. The agent can rely on the schema for parameter meaning, so the description is adequate but not superior.

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?

The description clearly states the action: sending a query to the OPA server's /v1/compile endpoint for partial evaluation. It specifies the resource (OPA server) and the result (residual query). This distinguishes it from siblings like opa_query_decision or rego_eval, which serve different purposes.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It does not mention prerequisites (e.g., OPA server must be running) or when partial evaluation is preferable to full evaluation. The agent receives no context for appropriate invocation.

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

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/OrygnsCode/opa-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server