get_user_groups
Retrieve all groups associated with a specific user in Keycloak identity management to manage access permissions and organizational structure.
Instructions
Get all groups for a user.
Args:
user_id: User ID
realm: Target realm (uses default if not specified)
Returns:
List of groups the user belongs to
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| user_id | Yes | ||
| realm | No |
Implementation Reference
- src/tools/group_tools.py:215-229 (handler)The main handler function for the 'get_user_groups' tool. It is decorated with @mcp.tool() for registration and uses the KeycloakClient to fetch the list of groups a user belongs to via the Keycloak API.@mcp.tool() async def get_user_groups( user_id: str, realm: Optional[str] = None ) -> List[Dict[str, Any]]: """ Get all groups for a user. Args: user_id: User ID realm: Target realm (uses default if not specified) Returns: List of groups the user belongs to """ return await client._make_request("GET", f"/users/{user_id}/groups", realm=realm)
- src/tools/group_tools.py:216-218 (schema)Input schema defined by function parameters (user_id: str required, realm: Optional[str]) and output as List[Dict[str, Any]].async def get_user_groups( user_id: str, realm: Optional[str] = None ) -> List[Dict[str, Any]]:
- src/tools/group_tools.py:215-215 (registration)Registration of the tool using the @mcp.tool() decorator.@mcp.tool()