Skip to main content
Glama
OrygnsCode

opa-mcp-server

OPA health check

opa_health

Check the health of an Open Policy Agent instance. Optionally require bundle or plugin subsystems to be healthy by setting query flags.

Instructions

Hit the OPA /health endpoint. Returns { healthy: true } on 200. Supports bundles and plugins query flags to require those subsystems to also be healthy.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
bundlesNoRequire bundle plugin to be healthy as well.
pluginsNoRequire all plugins to be healthy.

Implementation Reference

  • The main handler function for opa_health. Executes an HTTP GET to OPA's /health endpoint with optional 'bundles' and 'plugins' query parameters. Returns { healthy: true } on 200, or a structured error envelope otherwise.
    async ({ bundles, plugins }) => {
      return withToolEnvelope<{ healthy: boolean }>(config, async () => {
        try {
          const query: Record<string, boolean> = {};
          if (bundles) query['bundles'] = true;
          if (plugins) query['plugins'] = true;
          await opa.request({
            method: 'GET',
            path: '/health',
            query,
          });
          return ok({ healthy: true });
        } catch (e) {
          if (e instanceof OpaUnreachableError) {
            return mapOpaClientError(e);
          }
          // Any non-2xx counts as unhealthy without raising.
          return err('OPA_UNREACHABLE', 'OPA reported unhealthy.', {
            details: { error: e instanceof Error ? e.message : String(e) },
          });
        }
      });
    },
  • Input schema for opa_health: optional 'bundles' and 'plugins' boolean flags to require those subsystems to be healthy.
    inputSchema: {
      bundles: z.boolean().optional().describe('Require bundle plugin to be healthy as well.'),
      plugins: z.boolean().optional().describe('Require all plugins to be healthy.'),
    },
  • Registration of the 'opa_health' tool via server.registerTool(), including its title, description, input schema, and handler.
    server.registerTool(
      'opa_health',
      {
        title: 'OPA health check',
        description:
          'Hit the OPA `/health` endpoint. Returns `{ healthy: true }` on 200. Supports `bundles` and `plugins` query flags to require those subsystems to also be healthy.',
        inputSchema: {
          bundles: z.boolean().optional().describe('Require bundle plugin to be healthy as well.'),
          plugins: z.boolean().optional().describe('Require all plugins to be healthy.'),
        },
      },
      async ({ bundles, plugins }) => {
        return withToolEnvelope<{ healthy: boolean }>(config, async () => {
          try {
            const query: Record<string, boolean> = {};
            if (bundles) query['bundles'] = true;
            if (plugins) query['plugins'] = true;
            await opa.request({
              method: 'GET',
              path: '/health',
              query,
            });
            return ok({ healthy: true });
          } catch (e) {
            if (e instanceof OpaUnreachableError) {
              return mapOpaClientError(e);
            }
            // Any non-2xx counts as unhealthy without raising.
            return err('OPA_UNREACHABLE', 'OPA reported unhealthy.', {
              details: { error: e instanceof Error ? e.message : String(e) },
            });
          }
        });
      },
    );
  • The registerStatusTools function that registers opa_health, opa_status, and opa_config on the MCP server.
    export function registerStatusTools(server: McpServer, config: Config): void {
  • The OpaClient.request() method used by the opa_health handler to make HTTP requests to the OPA server.
    async request<T = unknown>(opts: RequestOptions): Promise<T> {
      const url = this.buildUrl(opts.path, opts.query);
    
      const headers: Record<string, string> = {
        Accept: 'application/json',
        ...(opts.headers ?? {}),
      };
      if (this.config.opaToken) {
        headers['Authorization'] = `Bearer ${this.config.opaToken}`;
      }
    
      let bodyToSend: string | undefined;
      if (opts.rawBody !== undefined) {
        if (opts.body !== undefined) {
          throw new Error('OpaClient.request: pass either `body` or `rawBody`, not both.');
        }
        bodyToSend = opts.rawBody;
        if (!headers['Content-Type']) {
          headers['Content-Type'] = opts.rawContentType ?? 'text/plain';
        }
      } else if (opts.body !== undefined) {
        bodyToSend = JSON.stringify(opts.body);
        if (!headers['Content-Type']) {
          headers['Content-Type'] = 'application/json';
        }
      }
    
      const controller = new AbortController();
      const timer = setTimeout(() => controller.abort(), this.config.httpTimeoutMs);
    
      const init: RequestInit = {
        method: opts.method,
        headers,
        signal: controller.signal,
      };
      if (bodyToSend !== undefined) {
        init.body = bodyToSend;
      }
    
      let response: Response;
      try {
        response = await fetch(url, init);
      } catch (e) {
        throw new OpaUnreachableError(this.config.opaUrl, e);
      } finally {
        clearTimeout(timer);
      }
    
      if (response.status === 401) {
        throw new OpaAuthError();
      }
    
      const contentType = response.headers.get('content-type') ?? '';
      const isJson = contentType.includes('application/json');
      const payload: unknown = isJson ? await response.json() : await response.text();
    
      if (!response.ok) {
        throw new OpaHttpError(response.status, payload);
      }
    
      return payload as T;
    }
Behavior4/5

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

No annotations provided, so the description carries full burden. It explains the endpoint, return value on 200, and query flags. It does not mention non-200 responses, but the tool is simple and non-destructive, so transparency is adequate.

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 succinct sentences with no wasted words. The main purpose is front-loaded, and the optional parameters are clearly explained.

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?

The tool is simple with no output schema. The description covers the return value and optional behavior. Could mention it's a GET request, but it's not necessary for understanding.

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 coverage is 100% with inline descriptions for both parameters. The description adds marginal value by explaining the flags require subsystems to be healthy. Baseline of 3 is appropriate.

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 tool hits the OPA /health endpoint and returns a specific object. It distinguishes itself from 31 sibling tools focused on policy management, evaluation, and testing by being a simple health check.

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 explains that the tool is for checking OPA health and mentions optional flags for subsystem checks. While it doesn't explicitly state when not to use this tool, its purpose is distinct from siblings, making usage clear.

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