Skip to main content
Glama
krzko

Google Cloud MCP Server

by krzko

Test Resource-Specific IAM Permissions

gcp-iam-test-resource-permissions

Test which permissions the current caller has on specific Google Cloud resources to verify access before performing operations.

Instructions

Test which permissions the current caller has on specific Google Cloud resources

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
resourceYesThe full resource name (e.g., "projects/my-project/buckets/my-bucket", "projects/my-project/zones/us-central1-a/instances/my-instance")
permissionsYesList of permissions to test on the resource

Implementation Reference

  • The async handler function that tests IAM permissions on a specific resource using the ResourceManagerClient.testIamPermissions API, categorizes granted and denied permissions, formats the results as structured Markdown, and handles errors.
    async ({ resource, permissions }) => {
      try {
        const resourceManager = getResourceManagerClient();
    
        const [response] = await resourceManager.testIamPermissions({
          resource,
          permissions,
        });
    
        const grantedPermissions = response.permissions || [];
        const deniedPermissions = permissions.filter(
          (p) => !grantedPermissions.includes(p),
        );
    
        let result = `# Resource IAM Permissions Test\n\nResource: ${resource}\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## ❌ Denied Permissions (${deniedPermissions.length})\n\n`;
        if (deniedPermissions.length > 0) {
          deniedPermissions.forEach((permission) => {
            result += `- ${permission}\n`;
          });
        } else {
          result += `*All permissions granted*\n`;
        }
    
        result += `\n**Summary:** ${grantedPermissions.length}/${permissions.length} permissions granted on resource ${resource}\n`;
    
        return {
          content: [
            {
              type: "text",
              text: result,
            },
          ],
        };
      } catch (error: unknown) {
        const errorMessage =
          error instanceof Error ? error.message : "Unknown error";
        logger.error(`Error testing resource IAM permissions: ${errorMessage}`);
    
        return {
          content: [
            {
              type: "text",
              text: `# Error Testing Resource IAM Permissions\n\nFailed to test IAM permissions on resource "${resource}": ${errorMessage}\n\nPlease ensure:\n- The resource name is correct and properly formatted\n- The resource exists and is accessible\n- You have the required permissions to test IAM permissions on this resource`,
            },
          ],
          isError: true,
        };
      }
    },
  • Zod input schema defining the required 'resource' (full resource name) and 'permissions' (array of strings) parameters for the tool.
    inputSchema: {
      resource: z
        .string()
        .describe(
          'The full resource name (e.g., "projects/my-project/buckets/my-bucket", "projects/my-project/zones/us-central1-a/instances/my-instance")',
        ),
      permissions: z
        .array(z.string())
        .describe("List of permissions to test on the resource"),
    },
  • The server.registerTool call that registers the 'gcp-iam-test-resource-permissions' tool, including its name, title, description, input schema, and handler function.
    server.registerTool(
      "gcp-iam-test-resource-permissions",
      {
        title: "Test Resource-Specific IAM Permissions",
        description:
          "Test which permissions the current caller has on specific Google Cloud resources",
        inputSchema: {
          resource: z
            .string()
            .describe(
              'The full resource name (e.g., "projects/my-project/buckets/my-bucket", "projects/my-project/zones/us-central1-a/instances/my-instance")',
            ),
          permissions: z
            .array(z.string())
            .describe("List of permissions to test on the resource"),
        },
      },
      async ({ resource, permissions }) => {
        try {
          const resourceManager = getResourceManagerClient();
    
          const [response] = await resourceManager.testIamPermissions({
            resource,
            permissions,
          });
    
          const grantedPermissions = response.permissions || [];
          const deniedPermissions = permissions.filter(
            (p) => !grantedPermissions.includes(p),
          );
    
          let result = `# Resource IAM Permissions Test\n\nResource: ${resource}\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## ❌ Denied Permissions (${deniedPermissions.length})\n\n`;
          if (deniedPermissions.length > 0) {
            deniedPermissions.forEach((permission) => {
              result += `- ${permission}\n`;
            });
          } else {
            result += `*All permissions granted*\n`;
          }
    
          result += `\n**Summary:** ${grantedPermissions.length}/${permissions.length} permissions granted on resource ${resource}\n`;
    
          return {
            content: [
              {
                type: "text",
                text: result,
              },
            ],
          };
        } catch (error: unknown) {
          const errorMessage =
            error instanceof Error ? error.message : "Unknown error";
          logger.error(`Error testing resource IAM permissions: ${errorMessage}`);
    
          return {
            content: [
              {
                type: "text",
                text: `# Error Testing Resource IAM Permissions\n\nFailed to test IAM permissions on resource "${resource}": ${errorMessage}\n\nPlease ensure:\n- The resource name is correct and properly formatted\n- The resource exists and is accessible\n- You have the required permissions to test IAM permissions on this resource`,
              },
            ],
            isError: true,
          };
        }
      },
    );
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states what the tool does but doesn't describe important behavioral traits: it doesn't specify whether this is a read-only operation, what the output format looks like, whether there are rate limits, authentication requirements, or error conditions. For a permission-testing tool with zero annotation coverage, this leaves significant gaps.

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 that states the core purpose without unnecessary words. It's appropriately sized for a straightforward tool and front-loads the essential information. Every word earns its place.

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?

For a permission-testing tool with no annotations and no output schema, the description is insufficiently complete. It doesn't explain what the tool returns (e.g., which permissions are granted/denied), doesn't mention authentication requirements, and provides no context about error handling or usage constraints. Given the complexity of IAM permission testing, more contextual information would be valuable.

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 fully documents both parameters. The description doesn't add any parameter-specific information beyond what's in the schema descriptions. It doesn't provide examples of valid permission strings, explain resource naming conventions beyond the schema examples, or clarify the relationship between the two parameters.

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 with a specific verb ('Test') and resource ('permissions the current caller has on specific Google Cloud resources'). It distinguishes from sibling tools like 'gcp-iam-test-project-permissions' by specifying 'resource-specific' permissions testing rather than project-level testing.

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 doesn't mention sibling tools like 'gcp-iam-test-project-permissions' for project-level testing or 'gcp-iam-analyse-permission-gaps' for gap analysis, nor does it specify prerequisites or appropriate contexts for resource-specific permission testing.

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