Skip to main content
Glama

get_role_permissions

Retrieve detailed IAM role information, including permissions, for roles in GCP. Specify a role name or project ID for custom roles to analyze access controls systematically.

Instructions

    Get detailed information about an IAM role, including its permissions.
    
    Args:
        role_name: The name of the role (e.g., "roles/compute.admin" or "projects/my-project/roles/myCustomRole")
        project_id: Optional project ID for custom roles. Not needed if role_name is fully qualified.
    
    Returns:
        Detailed information about the IAM role
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_idNo
role_nameYes

Implementation Reference

  • The core handler function for the 'get_role_permissions' MCP tool. It resolves the role name, fetches the role using IAMClient.get_role, extracts details like title, description, permissions list, stage, and ETag, then formats and returns them. Includes input validation via type hints and docstring, and error handling.
        @mcp.tool()
        def get_role_permissions(role_name: str, project_id: Optional[str] = None) -> str:
            """
            Get detailed information about an IAM role, including its permissions.
            
            Args:
                role_name: The name of the role (e.g., "roles/compute.admin" or "projects/my-project/roles/myCustomRole")
                project_id: Optional project ID for custom roles. Not needed if role_name is fully qualified.
            
            Returns:
                Detailed information about the IAM role
            """
            try:
                from google.cloud import iam_v1
                
                # Initialize the IAM client
                client = iam_v1.IAMClient()
                
                # If project_id is provided and role_name doesn't include it, create fully qualified role name
                if project_id and not role_name.startswith("projects/") and not role_name.startswith("roles/"):
                    role_name = f"projects/{project_id}/roles/{role_name}"
                elif not role_name.startswith("projects/") and not role_name.startswith("roles/"):
                    role_name = f"roles/{role_name}"
                
                # Get role details
                request = iam_v1.GetRoleRequest(name=role_name)
                role = client.get_role(request=request)
                
                details = []
                details.append(f"Name: {role.name}")
                details.append(f"Title: {role.title}")
                details.append(f"Description: {role.description or 'No description'}")
                
                if role.included_permissions:
                    permissions_str = "\n".join([f"- {permission}" for permission in role.included_permissions])
                    details.append(f"Permissions ({len(role.included_permissions)}):\n{permissions_str}")
                else:
                    details.append("Permissions: None")
                
                if hasattr(role, 'stage'):
                    details.append(f"Stage: {role.stage}")
                
                if hasattr(role, 'etag'):
                    details.append(f"ETag: {role.etag}")
                
                return f"""
    IAM Role Details for {role.name}:
    {chr(10).join(details)}
    """
            except Exception as e:
                return f"Error getting role permissions: {str(e)}"
  • Top-level registration call for the IAM tools module in the MCP server, which includes the get_role_permissions tool. This invokes the module's register_tools function to add all IAM-related tools to the MCP instance.
    # Register IAM tools
    iam_tools.register_tools(mcp)
  • Import of the IAM tools module aliased as iam_tools, enabling its register_tools to be called for registering get_role_permissions and other IAM tools.
    from .gcp_modules.iam import tools as iam_tools

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

A3.7/5.0
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 does not mention whether the operation is read-only, what errors may occur (e.g., role not found), authentication requirements, or the structure of the returned details. The description only states the return is 'detailed information,' which is generic and lacks behavioral depth.

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, front-loaded with the purpose, and logically structured with Args and Returns sections. Every sentence contributes value: the purpose sentence, the parameter explanations, and the return statement. There is no redundancy or filler.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the low complexity (2 parameters, no output schema, no annotations), the description is adequate but incomplete. It lacks specific return detail fields and error handling behavior. However, for a simple read-only tool, the description sufficiently conveys what the tool does and how to invoke it. The vague 'detailed information' leaves some ambiguity.

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 schema provides only parameter names and types with 0% description coverage. The description compensates by explaining role_name with concrete examples ('roles/compute.admin' or fully-qualified custom role paths) and clarifying that project_id is optional for custom roles. This adds meaningful context beyond the schema, though it could be more explicit about interactions between 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 function: 'Get detailed information about an IAM role, including its permissions.' The verb 'Get' is specific, the resource 'IAM role' is well-defined, and the scope 'including its permissions' distinguishes it from sibling tools like list_roles (which lists roles) and check_iam_permissions (which checks permissions for principals).

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?

The description provides parameter guidance (role_name format, optional project_id) but does not explicitly state when to use this tool versus alternatives. No exclusions or comparison with sibling tools are given. Usage context is implied through the parameter explanations but not directly addressed.

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