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
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 of behavioral disclosure. It states the tool checks permissions but doesn't mention whether this is a read-only operation, what authentication is required, potential rate limits, or error conditions. The description is minimal and lacks crucial behavioral details for a tool that likely interacts with GCP IAM.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured and front-loaded with the main purpose, followed by Args and Returns sections. It's concise with no wasted sentences, though the formatting includes extra whitespace. Every sentence earns its place by explaining the tool's function and parameters efficiently.

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 permissions checking, no annotations, and no output schema, the description is incomplete. It doesn't explain the return format (e.g., list structure, permission strings), authentication requirements, error handling, or how it differs from similar tools. This leaves significant gaps for an AI agent to use the tool effectively.

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 description adds meaningful context for the single parameter 'project_id' by explaining it's 'The ID of the GCP project to check permissions for.' This clarifies the parameter's purpose beyond the schema's basic title ('Project Id'). With 0% schema description coverage and only one parameter, this compensation is adequate, though not exhaustive.

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: 'Check IAM permissions for the current user in a GCP project.' It specifies the verb ('check'), resource ('IAM permissions'), and scope ('current user in a GCP project'). However, it doesn't explicitly differentiate from sibling tools like 'get_role_permissions' or 'list_roles', which prevents a perfect score.

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 'get_role_permissions' or 'list_roles', nor does it specify prerequisites such as authentication or project access. The only implied context is checking permissions for the current user, but no explicit usage scenarios are provided.

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

Related 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/henihaddad/gcp-mcp'

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