@mcp.tool()
async def create_user(
username: str,
email: Optional[str] = None,
first_name: Optional[str] = None,
last_name: Optional[str] = None,
enabled: bool = True,
email_verified: bool = False,
temporary_password: Optional[str] = None,
attributes: Optional[Dict[str, List[str]]] = None,
realm: Optional[str] = None,
) -> Dict[str, str]:
"""
Create a new user.
Args:
username: Username for the new user
email: Email address
first_name: First name
last_name: Last name
enabled: Whether the user is enabled
email_verified: Whether the email is verified
temporary_password: Initial password (user will be required to change it)
attributes: Additional user attributes
realm: Target realm (uses default if not specified)
Returns:
Dict with status and location of created user
"""
user_data = {
"username": username,
"enabled": enabled,
"emailVerified": email_verified,
}
if email:
user_data["email"] = email
if first_name:
user_data["firstName"] = first_name
if last_name:
user_data["lastName"] = last_name
if attributes:
user_data["attributes"] = attributes
if temporary_password:
user_data["credentials"] = [
{"type": "password", "value": temporary_password, "temporary": True}
]
# Create user returns no content, but includes Location header
await client._make_request("POST", "/users", data=user_data, realm=realm)
return {"status": "created", "message": f"User {username} created successfully"}