Skip to main content
Glama
OrygnsCode

opa-mcp-server

Patch data on OPA

opa_patch_data

Apply JSON Patch operations to modify OPA data documents. Use add, remove, or replace operations at specified paths.

Instructions

Apply a JSON Patch (RFC 6902) to the data document. Each operation is { op, path, value? }.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesData path the patch is applied to. Use "" for the root.
operationsYesArray of JSON Patch operations.

Implementation Reference

  • The tool handler for 'opa_patch_data'. Registers an MCP tool that accepts a 'path' and 'operations' (JSON Patch), sends a PATCH request to the OPA server with Content-Type application/json-patch+json, and returns success/failure.
    server.registerTool(
      'opa_patch_data',
      {
        title: 'Patch data on OPA',
        description:
          'Apply a JSON Patch (RFC 6902) to the data document. Each operation is `{ op, path, value? }`.',
        inputSchema: {
          path: z.string().min(1).describe('Data path the patch is applied to. Use "" for the root.'),
          operations: z
            .array(
              z.object({
                op: z.enum(['add', 'remove', 'replace']),
                path: z.string(),
                value: z.unknown().optional(),
              }),
            )
            .min(1)
            .describe('Array of JSON Patch operations.'),
        },
      },
      async ({ path, operations }) => {
        return withToolEnvelope<{ path: string; patched: boolean }>(config, async () => {
          try {
            await opa.request({
              method: 'PATCH',
              path: dataPath(path),
              body: operations,
              headers: { 'Content-Type': 'application/json-patch+json' },
            });
            return ok({ path, patched: true });
          } catch (e) {
            return mapOpaClientError(e);
          }
        });
      },
    );
  • Input schema for opa_patch_data using Zod. Defines 'path' (string) and 'operations' (array of {op: 'add'|'remove'|'replace', path: string, value?: unknown}) as required inputs.
    inputSchema: {
      path: z.string().min(1).describe('Data path the patch is applied to. Use "" for the root.'),
      operations: z
        .array(
          z.object({
            op: z.enum(['add', 'remove', 'replace']),
            path: z.string(),
            value: z.unknown().optional(),
          }),
        )
        .min(1)
        .describe('Array of JSON Patch operations.'),
    },
  • The top-level registration entry point. registerTools() calls registerServerManagementTools() which in turn calls registerDataTools() where opa_patch_data is registered.
    export function registerTools(server: McpServer, config: Config): void {
      registerAuthoringTools(server, config);
      registerEvaluationTools(server, config);
      registerBundleTools(server, config);
      registerServerManagementTools(server, config);
      registerHelperTools(server, config);
    }
  • registerServerManagementTools() calls registerDataTools() which registers opa_patch_data among other data tools.
    export function registerServerManagementTools(server: McpServer, config: Config): void {
      registerPolicyTools(server, config);
      registerDataTools(server, config);
      registerDecisionTools(server, config);
      registerStatusTools(server, config);
    }
  • mapOpaClientError helper function used in the opa_patch_data handler to translate OpaClient 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 },
      });
    }
Behavior3/5

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

The description discloses that the tool applies a JSON Patch per RFC 6902, but does not elaborate on validation behavior, atomicity, error handling, or whether the patch modifies the in-memory data only or persists. Since no annotations are provided, more behavioral detail would be beneficial.

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 sentences with zero waste. The structure is front-loaded with the core action, then additional detail on operation format. Every word serves a purpose.

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

Completeness3/5

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

Given no annotations, no output schema, and a moderately complex tool (mutation), the description provides minimal behavioral context. It does not explain return values, error conditions, or performance implications. However, referencing a well-known standard (RFC 6902) helps compensate somewhat.

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 baseline is 3. The description adds value by explaining that each operation is `{ op, path, value? }`, clarifying that 'value' is optional and depends on the operation type. This goes beyond the schema which only defines the fields.

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 verb 'Apply' and the resource 'data document' with the specific method 'JSON Patch (RFC 6902)'. This distinguishes it from sibling tools like 'opa_put_data' which replaces data entirely, and 'opa_get_data' which retrieves data.

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?

No guidance is provided on when to use this tool versus alternatives (e.g., opa_put_data for full replacement, or other patch-like operations). The description does not mention prerequisites or context where patching is appropriate.

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