update_user
Modify user account details in Keycloak, including username, email, name, status, and attributes, by providing the user ID and updated values.
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 |
|---|---|---|---|
| user_id | Yes | ||
| username | No | ||
| No | |||
| first_name | No | ||
| last_name | No | ||
| enabled | No | ||
| email_verified | No | ||
| attributes | No | ||
| realm | No |
Implementation Reference
- src/tools/user_tools.py:120-171 (handler)This is the main handler function for the 'update_user' tool. It is decorated with @mcp.tool() which registers it as an MCP tool. The function fetches the current user data from Keycloak, updates only the provided fields, and performs a PUT request to update the user.@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"}