get_user_realm_roles
Retrieve realm roles for a specific user in Keycloak. Specify user ID, realm, and whether to include composite roles for comprehensive role assignment details.
Instructions
Get realm roles for a user.
Args:
user_id: User ID
effective: Get effective roles (including composite roles)
realm: Target realm (uses default if not specified)
Returns:
List of realm roles
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| effective | No | ||
| realm | No | ||
| user_id | Yes |
Implementation Reference
- src/tools/role_tools.py:268-288 (handler)The main handler function decorated with @mcp.tool() that implements the get_user_realm_roles tool. It fetches the user's realm roles (effective or direct) from Keycloak using the KeycloakClient.@mcp.tool() async def get_user_realm_roles( user_id: str, effective: bool = False, realm: Optional[str] = None ) -> List[Dict[str, Any]]: """ Get realm roles for a user. Args: user_id: User ID effective: Get effective roles (including composite roles) realm: Target realm (uses default if not specified) Returns: List of realm roles """ endpoint = f"/users/{user_id}/role-mappings/realm" if effective: endpoint += "/composite" return await client._make_request("GET", endpoint, realm=realm)