add_user_to_group
Adds a user to a specified group in Keycloak IAM. Requires user ID, group ID, and optional realm. Returns status confirmation for user-group association.
Instructions
Add a user to a group.
Args:
user_id: User ID
group_id: Group ID
realm: Target realm (uses default if not specified)
Returns:
Status message
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| group_id | Yes | ||
| realm | No | ||
| user_id | Yes |
Implementation Reference
- src/tools/group_tools.py:170-188 (handler)The handler function for the 'add_user_to_group' tool. It is decorated with @mcp.tool() which serves as the registration. The function signature defines the input schema (user_id, group_id, optional realm) and return type (Dict[str, str]). It uses the KeycloakClient to make a PUT request to add the user to the group.@mcp.tool() async def add_user_to_group( user_id: str, group_id: str, realm: Optional[str] = None ) -> Dict[str, str]: """ Add a user to a group. Args: user_id: User ID group_id: Group ID realm: Target realm (uses default if not specified) Returns: Status message """ await client._make_request( "PUT", f"/users/{user_id}/groups/{group_id}", realm=realm ) return {"status": "added", "message": f"User {user_id} added to group {group_id}"}