update_user
Modify user details in Keycloak, including username, email, name, and attributes. Use to enable/disable accounts, verify emails, or update user info in specified or default realms.
Instructions
Update an existing user.
Args:
user_id: The user's ID
username: New username
email: New email address
first_name: New first name
last_name: New last name
enabled: Whether the user is enabled
email_verified: Whether the email is verified
attributes: Updated user attributes
realm: Target realm (uses default if not specified)
Returns:
Status message
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| attributes | No | ||
| No | |||
| email_verified | No | ||
| enabled | No | ||
| first_name | No | ||
| last_name | No | ||
| realm | No | ||
| user_id | Yes | ||
| username | No |
Implementation Reference
- src/tools/user_tools.py:120-171 (handler)The async handler function for the 'update_user' MCP tool. Decorated with @mcp.tool() for automatic registration and schema inference from parameters. Updates user attributes in Keycloak by merging provided changes with existing data.@mcp.tool() async def update_user( user_id: str, username: Optional[str] = None, email: Optional[str] = None, first_name: Optional[str] = None, last_name: Optional[str] = None, enabled: Optional[bool] = None, email_verified: Optional[bool] = None, attributes: Optional[Dict[str, List[str]]] = None, realm: Optional[str] = None, ) -> Dict[str, str]: """ Update an existing user. Args: user_id: The user's ID username: New username email: New email address first_name: New first name last_name: New last name enabled: Whether the user is enabled email_verified: Whether the email is verified attributes: Updated user attributes realm: Target realm (uses default if not specified) Returns: Status message """ # First get the current user data current_user = await client._make_request("GET", f"/users/{user_id}", realm=realm) # Update only provided fields if username is not None: current_user["username"] = username if email is not None: current_user["email"] = email if first_name is not None: current_user["firstName"] = first_name if last_name is not None: current_user["lastName"] = last_name if enabled is not None: current_user["enabled"] = enabled if email_verified is not None: current_user["emailVerified"] = email_verified if attributes is not None: current_user["attributes"] = attributes await client._make_request( "PUT", f"/users/{user_id}", data=current_user, realm=realm ) return {"status": "updated", "message": f"User {user_id} updated successfully"}