Skip to main content
Glama
idoyudha

mcp-keycloak

by idoyudha

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
NameRequiredDescriptionDefault
user_idYes
usernameNo
emailNo
first_nameNo
last_nameNo
enabledNo
email_verifiedNo
attributesNo
realmNo

Implementation Reference

  • 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"}

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/idoyudha/mcp-keycloak'

If you have feedback or need assistance with the MCP directory API, please join our Discord server