Skip to main content
Glama
OrygnsCode

opa-mcp-server

Describe Rego policy

rego_describe_policy

Parse a Rego policy to obtain a structured summary of its package, imports, rules, and annotations, serving as the initial step in understanding a policy's functionality.

Instructions

Parse a Rego policy and return a structured summary: package, imports, rules (with default/args/body-length flags), and inline annotations. Useful as the first step in any "what does this policy do" workflow.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sourceYesRego source to describe.

Implementation Reference

  • The handler function that registers and implements the 'rego_describe_policy' tool. It parses Rego source via `opa parse --format=json`, then extracts package name, imports, rules (with metadata like default/args/body-length), and annotations into a structured summary.
    export function registerRegoDescribePolicy(server: McpServer, config: Config): void {
      const opa = new OpaCli(config);
    
      server.registerTool(
        'rego_describe_policy',
        {
          title: 'Describe Rego policy',
          description:
            'Parse a Rego policy and return a structured summary: package, imports, rules (with default/args/body-length flags), and inline annotations. Useful as the first step in any "what does this policy do" workflow.',
          inputSchema: RegoDescribePolicyInput,
        },
        async ({ source }) => {
          return withToolEnvelope<RegoDescribePolicyOutput>(config, async () => {
            const result = await opa.parse({ source });
            const subprocessFailure = mapSubprocessFailure(result, 'opa');
            if (subprocessFailure) return subprocessFailure;
            if (result.exitCode !== 0) {
              return err('INVALID_REGO', 'opa parse rejected the source.', {
                details: { stderr: result.stderr.trim() },
              });
            }
            const ast = tryParseJson<ParsedAst>(result.stdout);
            if (ast === undefined) {
              return err('UNKNOWN_ERROR', 'opa parse produced no parseable JSON.');
            }
    
            const packageParts = ast.package?.path?.slice(1) ?? [];
            const packageName = refToString(packageParts);
    
            const imports = (ast.imports ?? []).map((imp) => {
              const path = refToString(imp.path?.value);
              return imp.alias ? `${path} as ${imp.alias}` : path;
            });
    
            const seen = new Map<string, DescribedRule>();
            for (const rule of ast.rules ?? []) {
              const name = rule.head?.name ?? refToString(rule.head?.ref);
              if (!name) continue;
              const existing = seen.get(name);
              if (existing) {
                existing.bodyLength += rule.body?.length ?? 0;
                continue;
              }
              seen.set(name, {
                name,
                isDefault: rule.default === true,
                hasArgs: Array.isArray(rule.head?.args) && (rule.head?.args.length ?? 0) > 0,
                bodyLength: rule.body?.length ?? 0,
                annotations: rule.annotations,
              });
            }
            const rules = [...seen.values()];
    
            return ok<RegoDescribePolicyOutput>({
              package: packageName,
              imports,
              ruleCount: rules.length,
              rules,
              packageAnnotations: ast.annotations,
            });
          });
        },
      );
    }
  • Input schema for the tool: a single 'source' string field (Rego source) validated with Zod.
    const RegoDescribePolicyInput = {
      source: z.string().min(1).describe('Rego source to describe.'),
    };
  • Output type definition (RegoDescribePolicyOutput) containing package name, imports list, rule count, rule details, and package-level annotations.
    export interface RegoDescribePolicyOutput {
      package: string;
      imports: string[];
      ruleCount: number;
      rules: DescribedRule[];
      packageAnnotations?: AstAnnotations[];
    }
  • Registration bridge: 'registerHelperTools' calls 'registerRegoDescribePolicy(server, config)' to wire the tool into the MCP server.
    export function registerHelperTools(server: McpServer, config: Config): void {
      registerRegoExplainDecision(server, config);
      registerRegoGenerateTestSkeleton(server, config);
      registerRegoDescribePolicy(server, config);
      registerRegoSuggestFix(server, config);
    }
  • Top-level registration entry point: 'registerTools' calls 'registerHelperTools' which ultimately registers rego_describe_policy.
    export function registerTools(server: McpServer, config: Config): void {
      registerAuthoringTools(server, config);
      registerEvaluationTools(server, config);
      registerBundleTools(server, config);
      registerServerManagementTools(server, config);
      registerHelperTools(server, config);
    }
Behavior3/5

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

No annotations are provided, so the description carries the full burden. It explains what the tool returns (structured summary) but does not disclose potential side effects, performance implications, or any destructive actions. Since it is a parsing tool, it is likely read-only, but this is not explicitly stated.

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?

The description is extremely concise, consisting of two sentences that front-load the main action and output, followed by a clear usage recommendation. Every word is valuable, and there is no fluff.

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

Completeness5/5

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

For a simple tool with one parameter and no output schema, the description provides sufficient information: what it does, what it returns, and when to use it. It is complete enough for an agent to understand and invoke the tool correctly.

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?

The input schema has 100% coverage with a description for the 'source' parameter, so the baseline is 3. The description does not add any additional information about the parameter beyond what the schema provides, such as expected format or length constraints.

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 it parses a Rego policy and returns a structured summary with specific elements like package, imports, rules. It distinguishes itself from sibling tools like rego_check or rego_eval by being a 'describe' tool focused on understanding policy structure.

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

Usage Guidelines4/5

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

The description explicitly recommends using this tool as the first step in a 'what does this policy do' workflow, providing clear context for when to use it. However, it does not explicitly mention when not to use it or alternatives, which would make it a 5.

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