get_user_groups
Retrieve a list of groups associated with a specific user in Keycloak. Specify the user ID and optionally the realm to manage access and identity effectively.
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 |
|---|---|---|---|
| realm | No | ||
| user_id | Yes |
Implementation Reference
- src/tools/group_tools.py:215-229 (handler)The handler function implementing the 'get_user_groups' tool logic. Decorated with @mcp.tool() which handles registration and infers the input schema from type annotations and docstring.@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/main.py:23-23 (registration)Import of the group_tools module in the main entrypoint, which executes the @mcp.tool() decorators to register the tool with the MCP server.from .tools import group_tools # noqa: F401
- src/tools/group_tools.py:6-6 (helper)Global KeycloakClient instance used by the get_user_groups handler to make the API request.client = KeycloakClient()
- src/tools/group_tools.py:3-3 (helper)Import of KeycloakClient helper class used in the tool implementation.from .keycloak_client import KeycloakClient