Skip to main content
Glama
idoyudha

mcp-keycloak

by idoyudha

assign_client_role_to_user

Assign client-specific roles to users in Keycloak for precise access control. Specify user, client, and roles to manage permissions.

Instructions

Assign client roles to a user.

Args:
    user_id: User ID
    client_id: Client database ID
    role_names: List of role names to assign
    realm: Target realm (uses default if not specified)

Returns:
    Status message

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
user_idYes
client_idYes
role_namesYes
realmNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function for the 'assign_client_role_to_user' tool, decorated with @mcp.tool() which serves as the registration. It fetches client role details and assigns them to the specified user via Keycloak's admin API.
    @mcp.tool()
    async def assign_client_role_to_user(
        user_id: str, client_id: str, role_names: List[str], realm: Optional[str] = None
    ) -> Dict[str, str]:
        """
        Assign client roles to a user.
    
        Args:
            user_id: User ID
            client_id: Client database ID
            role_names: List of role names to assign
            realm: Target realm (uses default if not specified)
    
        Returns:
            Status message
        """
        # Get role representations
        roles = []
        for role_name in role_names:
            role = await client._make_request(
                "GET", f"/clients/{client_id}/roles/{role_name}", realm=realm
            )
            roles.append(role)
    
        await client._make_request(
            "POST",
            f"/users/{user_id}/role-mappings/clients/{client_id}",
            data=roles,
            realm=realm,
        )
        return {
            "status": "assigned",
            "message": f"Client roles {role_names} assigned to user {user_id}",
        }
  • The @mcp.tool() decorator registers the function as an MCP tool.
    @mcp.tool()
  • Function signature with type hints and docstring defining the input schema and output type.
    async def assign_client_role_to_user(
        user_id: str, client_id: str, role_names: List[str], realm: Optional[str] = None
    ) -> Dict[str, str]:
        """
        Assign client roles to a user.
    
        Args:
            user_id: User ID
            client_id: Client database ID
            role_names: List of role names to assign
            realm: Target realm (uses default if not specified)
Behavior2/5

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

No annotations are provided, so the description carries full burden for behavioral disclosure. While 'Assign' implies a mutation operation, the description doesn't address critical aspects like required permissions, whether assignments are additive or replace existing roles, error conditions, or side effects. This leaves significant gaps for a tool that modifies user access.

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 appropriately sized and well-structured with clear sections for purpose, arguments, and returns. The Args and Returns sections are efficiently formatted, though the opening statement could be slightly more specific about the scope of assignment.

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 presence of an output schema (which handles return values) and good parameter explanation, the description is moderately complete. However, as a mutation tool with no annotations, it lacks important behavioral context about permissions, idempotency, and error handling that would be needed for full completeness.

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?

With 0% schema description coverage, the description compensates well by explaining all four parameters in the Args section. It clarifies that 'user_id' identifies the user, 'client_id' is a database ID, 'role_names' is a list, and 'realm' is optional with default behavior. This adds meaningful context beyond the bare schema.

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 action ('Assign client roles') and target ('to a user'), providing a specific verb+resource combination. However, it doesn't differentiate this tool from similar sibling tools like 'assign_realm_role_to_user' or 'add_user_to_group', which would require explicit comparison for a score of 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. With sibling tools like 'assign_realm_role_to_user' and 'add_user_to_group' available, there's no indication of the specific context for client roles versus realm roles or group membership, leaving the agent without usage direction.

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/idoyudha/mcp-keycloak'

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