Skip to main content
Glama

check_iam_permissions

Verify IAM permissions for the current user in a specified GCP project to ensure access and compliance with required roles and policies.

Instructions

    Check IAM permissions for the current user in a GCP project.
    
    Args:
        project_id: The ID of the GCP project to check permissions for
    
    Returns:
        List of IAM permissions for the current user in the specified GCP project
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_idYes

Implementation Reference

  • The handler function for the 'check_iam_permissions' tool. It retrieves the IAM policy for the specified GCP project and lists the roles assigned to the current user or service account.
        @mcp.tool()
        def check_iam_permissions(project_id: str) -> str:
            """
            Check IAM permissions for the current user in a GCP project.
            
            Args:
                project_id: The ID of the GCP project to check permissions for
            
            Returns:
                List of IAM permissions for the current user in the specified GCP project
            """
            try:
                from google.cloud import resourcemanager_v3
                from google.iam.v1 import iam_policy_pb2
                
                # Initialize the Resource Manager client
                client = resourcemanager_v3.ProjectsClient()
                
                # Get the IAM policy for the project
                request = iam_policy_pb2.GetIamPolicyRequest(
                    resource=f"projects/{project_id}"
                )
                policy = client.get_iam_policy(request=request)
                
                # Get the current user
                import google.auth
                credentials, _ = google.auth.default()
                user = credentials.service_account_email if hasattr(credentials, 'service_account_email') else "current user"
                
                # Check which roles the user has
                user_bindings = []
                for binding in policy.bindings:
                    role = binding.role
                    members = binding.members
                    
                    # Check if the current user is in the members list
                    for member in members:
                        if member == f"user:{user}" or member == "serviceAccount:{user}" or member == "allUsers" or member == "allAuthenticatedUsers":
                            user_bindings.append(f"- {role}")
                            break
                
                if not user_bindings:
                    return f"No explicit IAM permissions found for {user} in project {project_id}."
                
                user_bindings_str = "\n".join(user_bindings)
                
                return f"""
    IAM Permissions for {user} in GCP Project {project_id}:
    {user_bindings_str}
    """
            except Exception as e:
                return f"Error checking IAM permissions: {str(e)}"
  • Registration of the IAM tools module, which defines and registers the check_iam_permissions tool via its register_tools function.
    iam_tools.register_tools(mcp)
  • Import of the IAM tools module alias, enabling registration of check_iam_permissions.
    from .gcp_modules.iam import tools as iam_tools

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

A4/5.0
Behavior3/5

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

With no annotations provided, the description must carry the behavioral burden. It states that it returns a list of permissions for the current user, implying a read-only check, but does not explicitly say it makes no modifications, what permission types are included, or any error conditions. It adds some context by specifying scope to the current user and project, but lacks richer behavioral disclosure.

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 and well-structured: a one-line purpose statement followed by Args and Returns sections. Every sentence adds value, and the essential information is front-loaded. There is no wasted text.

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?

For a simple read-only tool with one parameter and no output schema, the description covers the core aspects: what it does, the parameter, and the return type. It lacks some nuance (e.g., whether permissions are project-level or resource-level), but it is sufficiently complete for a basic check operation.

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 provides only a title 'Project Id' with no description (0% coverage). The description compensates with an Args section explaining that project_id is 'The ID of the GCP project to check permissions for.' This adds meaningful semantics for the single parameter, though it could be more detailed about expected formats.

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 ('Check') and resource ('IAM permissions') scoped to 'the current user in a GCP project.' This distinguishes it from siblings like add_iam_policy_binding (which modifies permissions) and get_role_permissions (which lists permissions for a role).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Usage is implied by the purpose: if you need to check the current user's permissions in a project, use this tool. However, there is no explicit guidance on when to use it versus alternatives, no exclusions, and no mention of related tools like list_roles or get_role_permissions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.