Skip to main content
Glama

check_policy

Check whether a specific action (tool call, secret key read, or command execution) is permitted by the project's policy without actually executing it. Use as a dry-run to avoid blocked operations.

Instructions

[policy] Ask whether a single intended action would be allowed by the project's .q-ring.json policy without actually performing it. Use as a dry-run before calling a potentially-blocked tool, attempting to read a sensitive key, or invoking exec_with_secrets with a non-trivial command; prefer get_policy_summary for a one-shot overview of the entire policy. Read-only. Returns JSON { allowed, reason?, policySource } describing the decision. Returns an error 'Missing required parameter for the selected action type' if the matching argument for the chosen action is not supplied.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionYesWhich policy surface to query. 'tool' = MCP tool gate (needs `toolName`); 'key_read' = secret read gate (needs `key`); 'exec' = exec_with_secrets command gate (needs `command`).
toolNameNoTool id to evaluate, e.g. 'rotate_secret'. Required when `action` is 'tool'.
keyNoSecret key name to evaluate. Required when `action` is 'key_read'.
commandNoCommand to evaluate against the exec allowlist/denylist. Required when `action` is 'exec'.
projectPathNoAbsolute path to the project root for project-scoped secrets and policy resolution. Defaults to the MCP server's current working directory when omitted.

Implementation Reference

  • The main handler for the 'check_policy' tool. Dispatches to checkToolPolicy, checkKeyReadPolicy, or checkExecPolicy based on the 'action' parameter.
    async (params) => {
      if (params.action === "tool" && params.toolName) {
        const d = checkToolPolicy(params.toolName, params.projectPath);
        return text(JSON.stringify(d, null, 2));
      }
      if (params.action === "key_read" && params.key) {
        const d = checkKeyReadPolicy(params.key, undefined, params.projectPath);
        return text(JSON.stringify(d, null, 2));
      }
      if (params.action === "exec" && params.command) {
        const d = checkExecPolicy(params.command, params.projectPath);
        return text(JSON.stringify(d, null, 2));
      }
      return text(
        "Missing required parameter for the selected action type",
        true,
      );
    },
  • Zod input schema for the 'check_policy' tool: 'action' enum + optional toolName/key/command + projectPath.
      action: z
        .enum(["tool", "key_read", "exec"])
        .describe(
          "Which policy surface to query. 'tool' = MCP tool gate (needs `toolName`); 'key_read' = secret read gate (needs `key`); 'exec' = exec_with_secrets command gate (needs `command`).",
        ),
      toolName: z
        .string()
        .optional()
        .describe(
          "Tool id to evaluate, e.g. 'rotate_secret'. Required when `action` is 'tool'.",
        ),
      key: z
        .string()
        .optional()
        .describe(
          "Secret key name to evaluate. Required when `action` is 'key_read'.",
        ),
      command: z
        .string()
        .optional()
        .describe(
          "Command to evaluate against the exec allowlist/denylist. Required when `action` is 'exec'.",
        ),
      projectPath,
    },
  • Registration of the 'check_policy' MCP tool via server.tool() in registerPolicyTools.
    server.tool(
      "check_policy",
      [
        "[policy] Ask whether a single intended action would be allowed by the project's `.q-ring.json` policy without actually performing it.",
        "Use as a dry-run before calling a potentially-blocked tool, attempting to read a sensitive key, or invoking `exec_with_secrets` with a non-trivial command; prefer `get_policy_summary` for a one-shot overview of the entire policy.",
        "Read-only. Returns JSON `{ allowed, reason?, policySource }` describing the decision. Returns an error 'Missing required parameter for the selected action type' if the matching argument for the chosen `action` is not supplied.",
      ].join(" "),
      {
        action: z
          .enum(["tool", "key_read", "exec"])
          .describe(
            "Which policy surface to query. 'tool' = MCP tool gate (needs `toolName`); 'key_read' = secret read gate (needs `key`); 'exec' = exec_with_secrets command gate (needs `command`).",
          ),
        toolName: z
          .string()
          .optional()
          .describe(
            "Tool id to evaluate, e.g. 'rotate_secret'. Required when `action` is 'tool'.",
          ),
        key: z
          .string()
          .optional()
          .describe(
            "Secret key name to evaluate. Required when `action` is 'key_read'.",
          ),
        command: z
          .string()
          .optional()
          .describe(
            "Command to evaluate against the exec allowlist/denylist. Required when `action` is 'exec'.",
          ),
        projectPath,
      },
      async (params) => {
        if (params.action === "tool" && params.toolName) {
          const d = checkToolPolicy(params.toolName, params.projectPath);
          return text(JSON.stringify(d, null, 2));
        }
        if (params.action === "key_read" && params.key) {
          const d = checkKeyReadPolicy(params.key, undefined, params.projectPath);
          return text(JSON.stringify(d, null, 2));
        }
        if (params.action === "exec" && params.command) {
          const d = checkExecPolicy(params.command, params.projectPath);
          return text(JSON.stringify(d, null, 2));
        }
        return text(
          "Missing required parameter for the selected action type",
          true,
        );
      },
    );
  • Core helper that checks if a tool is allowed by project policy (allow/deny lists).
    export function checkToolPolicy(toolName: string, projectPath?: string): PolicyDecision {
      const policy = loadPolicy(projectPath);
      if (!policy.mcp) return { allowed: true, policySource: "no-policy" };
    
      if (policy.mcp.denyTools?.includes(toolName)) {
        return {
          allowed: false,
          reason: `Tool "${toolName}" is denied by project policy`,
          policySource: ".q-ring.json policy.mcp.denyTools",
        };
      }
    
      if (policy.mcp.allowTools && !policy.mcp.allowTools.includes(toolName)) {
        return {
          allowed: false,
          reason: `Tool "${toolName}" is not in the allowlist`,
          policySource: ".q-ring.json policy.mcp.allowTools",
        };
      }
    
      return { allowed: true, policySource: ".q-ring.json" };
    }
  • Core helper that checks if a command is allowed by exec policy (allow/deny commands).
    export function checkExecPolicy(command: string, projectPath?: string): PolicyDecision {
      const policy = loadPolicy(projectPath);
      if (!policy.exec) return { allowed: true, policySource: "no-policy" };
    
      if (policy.exec.denyCommands) {
        const denied = policy.exec.denyCommands.find((d) => command.includes(d));
        if (denied) {
          return {
            allowed: false,
            reason: `Command containing "${denied}" is denied by project policy`,
            policySource: ".q-ring.json policy.exec.denyCommands",
          };
        }
      }
    
      if (policy.exec.allowCommands) {
        const allowed = policy.exec.allowCommands.some((a) => command.startsWith(a));
        if (!allowed) {
          return {
            allowed: false,
            reason: `Command "${command}" is not in the exec allowlist`,
            policySource: ".q-ring.json policy.exec.allowCommands",
          };
        }
      }
    
      return { allowed: true, policySource: ".q-ring.json" };
    }
Behavior4/5

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

The description discloses that the tool is read-only and returns a JSON object with specific fields ('allowed, reason?, policySource'). It also documents a potential error message for missing parameters. While no annotations are provided, the description adequately covers behavioral traits, though it could mention rate limits or authentication requirements if applicable.

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 concise, using only a few sentences. It front-loads the core purpose and immediate usage guidance, with no unnecessary words. Every sentence adds value.

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?

Given the absence of an output schema, the description fully explains the return value structure. All five parameters are covered by the schema, and the description provides sufficient context for usage and error cases. The tool's complexity is moderate, and the description is complete.

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?

The input schema has 100% description coverage, so the baseline is 3. The description adds extra meaning by explaining the three action types ('tool', 'key_read', 'exec') and their required parameters, as well as the return format and error handling, which goes beyond the schema's descriptions.

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's purpose: to check if a single intended action would be allowed by the project's policy without performing it. It uses a specific verb ('Ask whether...') and resource ('.q-ring.json' policy), and explicitly distinguishes from the sibling tool 'get_policy_summary'.

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?

The description provides explicit guidance on when to use this tool: as a dry-run before calling a potentially-blocked tool, reading a sensitive key, or invoking 'exec_with_secrets'. It also specifies when to prefer the alternative 'get_policy_summary' for a one-shot overview, giving clear context for usage.

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/I4cTime/quantum_ring'

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