remove_realm_role_from_user
Remove realm roles from a Keycloak user to manage access permissions. Specify user ID and role names to revoke specific privileges in identity management.
Instructions
Remove realm roles from a user.
Args:
user_id: User ID
role_names: List of role names to remove
realm: Target realm (uses default if not specified)
Returns:
Status message
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| user_id | Yes | ||
| role_names | Yes | ||
| realm | No |
Implementation Reference
- src/tools/role_tools.py:238-265 (handler)The handler function decorated with @mcp.tool(), implementing the logic to remove realm roles from a user by fetching roles and deleting mappings via Keycloak API.@mcp.tool() async def remove_realm_role_from_user( user_id: str, role_names: List[str], realm: Optional[str] = None ) -> Dict[str, str]: """ Remove realm roles from a user. Args: user_id: User ID role_names: List of role names to remove 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"/roles/{role_name}", realm=realm) roles.append(role) await client._make_request( "DELETE", f"/users/{user_id}/role-mappings/realm", data=roles, realm=realm ) return { "status": "removed", "message": f"Roles {role_names} removed from user {user_id}", }