Assign a realm role to a user
keycloak_user_role_assignAssign a realm-level role to a user in Keycloak. The operation is idempotent and returns confirmation or an explanation if the user or role is not found.
Instructions
Write: grants a single realm-level role to a user (not a client role). This is idempotent — assigning a role the user already has succeeds without changing anything. The role must already exist in the realm; list candidates with keycloak_role_list and verify current assignments with keycloak_user_roles_get. Returns a confirmation that the role was assigned, or a message explaining why it was not (for example, the user or role was not found).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| role | Yes | The name of an existing realm role to grant (e.g. 'admin'), as returned by keycloak_role_list. This is the role name, not its ID. | |
| userId | Yes | The Keycloak user ID (the user's UUID, e.g. 'f47ac10b-58cc-4372-a567-0e02b2c3d479'), not the username. Identifies the user who receives the role. |