Skip to main content
Glama

assign_client_role_to_user

Assign specific client roles to a user in Keycloak by providing user ID, client ID, and role names. Optionally specify a target realm for role assignment.

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
client_idYes
realmNo
role_namesYes
user_idYes

Implementation Reference

  • The async handler function decorated with @mcp.tool() that implements the logic to assign client roles to a user by fetching role details and posting to Keycloak's user role mappings endpoint.
    @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}", }

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