Skip to main content
Glama
krzko

Google Cloud MCP Server

by krzko

Analyse Permission Gaps

gcp-iam-analyse-permission-gaps

Identify missing IAM permissions by comparing current access against required permissions for Google Cloud operations to resolve authorization issues.

Instructions

Compare current permissions against required permissions for specific operations and identify gaps

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectNoProject ID (defaults to current project)
requiredPermissionsYesList of permissions required for the intended operation
operationDescriptionNoDescription of the operation being attempted (for context)

Implementation Reference

  • Registers the 'gcp-iam-analyse-permission-gaps' tool on the MCP server instance.
    // Tool to analyse permission gaps for a specific resource and operation
    server.registerTool(
      "gcp-iam-analyse-permission-gaps",
  • Defines the input schema for the tool using Zod, including optional project ID, array of required permissions, and optional operation description.
    {
      title: "Analyse Permission Gaps",
      description:
        "Compare current permissions against required permissions for specific operations and identify gaps",
      inputSchema: {
        project: z
          .string()
          .optional()
          .describe("Project ID (defaults to current project)"),
        requiredPermissions: z
          .array(z.string())
          .describe("List of permissions required for the intended operation"),
        operationDescription: z
          .string()
          .optional()
          .describe(
            "Description of the operation being attempted (for context)",
          ),
      },
    },
  • Executes the tool logic: retrieves project ID, tests IAM permissions via GCP API, identifies gaps between required and granted permissions, and outputs a comprehensive Markdown analysis including suggestions for roles.
    async ({ project, requiredPermissions, operationDescription }) => {
      try {
        const projectId = project || (await getProjectId());
        const resourceManager = getResourceManagerClient();
    
        const [response] = await resourceManager.testIamPermissions({
          resource: `projects/${projectId}`,
          permissions: requiredPermissions,
        });
    
        const grantedPermissions = response.permissions || [];
        const missingPermissions = requiredPermissions.filter(
          (p) => !grantedPermissions.includes(p),
        );
    
        let result = `# Permission Gap Analysis\n\n`;
        result += `**Project:** ${projectId}\n`;
        if (operationDescription) {
          result += `**Operation:** ${operationDescription}\n`;
        }
        result += `**Total Required Permissions:** ${requiredPermissions.length}\n\n`;
    
        // Overall status
        const hasAllPermissions = missingPermissions.length === 0;
        result += `## 🎯 Status: ${hasAllPermissions ? "✅ AUTHORISED" : "❌ INSUFFICIENT PERMISSIONS"}\n\n`;
    
        if (hasAllPermissions) {
          result += `✅ You have all required permissions for this operation.\n\n`;
        } else {
          result += `❌ Missing ${missingPermissions.length} permission(s). Operation will likely fail.\n\n`;
        }
    
        // Detailed breakdown
        result += `## Permission Analysis\n\n`;
    
        result += `### ✅ Granted Permissions (${grantedPermissions.length})\n\n`;
        if (grantedPermissions.length > 0) {
          grantedPermissions.forEach((permission) => {
            result += `- ${permission}\n`;
          });
        } else {
          result += `*No permissions granted*\n`;
        }
    
        result += `\n### ❌ Missing Permissions (${missingPermissions.length})\n\n`;
        if (missingPermissions.length > 0) {
          missingPermissions.forEach((permission) => {
            result += `- ${permission}\n`;
          });
        } else {
          result += `*No missing permissions*\n`;
        }
    
        // Recommendations
        if (missingPermissions.length > 0) {
          result += `\n## 📋 Recommendations\n\n`;
          result += `1. **Contact your GCP administrator** to request the missing permissions\n`;
          result += `2. **Use predefined roles** that include these permissions:\n`;
    
          // Suggest some common roles that might contain these permissions
          const suggestedRoles = [];
          if (missingPermissions.some((p) => p.startsWith("compute."))) {
            suggestedRoles.push(
              "roles/compute.admin",
              "roles/compute.instanceAdmin",
            );
          }
          if (missingPermissions.some((p) => p.startsWith("storage."))) {
            suggestedRoles.push(
              "roles/storage.admin",
              "roles/storage.objectAdmin",
            );
          }
          if (missingPermissions.some((p) => p.startsWith("run."))) {
            suggestedRoles.push("roles/run.admin", "roles/run.developer");
          }
          if (missingPermissions.some((p) => p.startsWith("container."))) {
            suggestedRoles.push(
              "roles/container.admin",
              "roles/container.developer",
            );
          }
          if (missingPermissions.some((p) => p.startsWith("iam."))) {
            suggestedRoles.push(
              "roles/iam.serviceAccountUser",
              "roles/iam.serviceAccountAdmin",
            );
          }
    
          if (suggestedRoles.length > 0) {
            suggestedRoles.forEach((role) => {
              result += `   - ${role}\n`;
            });
          } else {
            result += `   - Contact administrator for custom role assignment\n`;
          }
    
          result += `3. **Create a custom role** with exactly these permissions if predefined roles are too broad\n`;
        }
    
        return {
          content: [
            {
              type: "text",
              text: result,
            },
          ],
        };
      } catch (error: unknown) {
        const errorMessage =
          error instanceof Error ? error.message : "Unknown error";
        logger.error(`Error analysing permission gaps: ${errorMessage}`);
    
        return {
          content: [
            {
              type: "text",
              text: `# Error Analysing Permission Gaps\n\nFailed to analyse permissions: ${errorMessage}\n\nPlease ensure the project ID is correct and accessible.`,
            },
          ],
          isError: true,
        };
      }
    },
Behavior2/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 describes the action ('compare' and 'identify gaps') but lacks behavioral details such as whether this is a read-only analysis, if it requires specific IAM roles, how it handles errors, or what the output format looks like. This is a significant gap for a tool that likely involves sensitive permission data.

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 a single, efficient sentence: 'Compare current permissions against required permissions for specific operations and identify gaps.' It's front-loaded with the core purpose and has zero wasted words, making it easy to parse quickly.

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?

Given the complexity of IAM permission analysis, no annotations, and no output schema, the description is incomplete. It doesn't explain what 'gaps' mean, how results are presented, or any behavioral aspects like rate limits or authentication needs. This leaves the agent with insufficient context to use the tool effectively beyond basic parameter input.

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 schema already documents all three parameters with descriptions. The description adds no additional meaning beyond the schema, such as examples or constraints. However, it implies the tool's purpose involves 'requiredPermissions' and 'operationDescription,' which aligns with the schema, so it meets the baseline of 3 without adding extra value.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/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: 'Compare current permissions against required permissions for specific operations and identify gaps.' It specifies the verb 'compare' and resource 'permissions,' making the function understandable. However, it doesn't differentiate from sibling tools like 'gcp-iam-test-project-permissions' or 'gcp-iam-validate-deployment-permissions,' which might have overlapping purposes, so it's not a perfect 5.

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 mentions 'specific operations' but doesn't clarify context, prerequisites, or exclusions. With sibling tools like 'gcp-iam-test-project-permissions' that might test permissions directly, there's no explicit comparison or usage scenario provided, leaving the agent to guess.

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/krzko/google-cloud-mcp'

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