create_client_role
Define and manage client roles in Keycloak by specifying role name, description, and composite status for targeted realms or defaults.
Instructions
Create a new client role.
Args:
client_id: Client database ID
name: Role name
description: Role description
composite: Whether this is a composite role
realm: Target realm (uses default if not specified)
Returns:
Status message
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| client_id | Yes | ||
| composite | No | ||
| description | No | ||
| name | Yes | ||
| realm | No |
Implementation Reference
- src/tools/role_tools.py:176-205 (handler)The @mcp.tool() decorated async function that defines and implements the 'create_client_role' tool. It creates a client role in Keycloak by sending a POST request with role data to the appropriate endpoint.@mcp.tool() async def create_client_role( client_id: str, name: str, description: Optional[str] = None, composite: bool = False, realm: Optional[str] = None, ) -> Dict[str, str]: """ Create a new client role. Args: client_id: Client database ID name: Role name description: Role description composite: Whether this is a composite role realm: Target realm (uses default if not specified) Returns: Status message """ role_data = {"name": name, "composite": composite, "clientRole": True} if description: role_data["description"] = description await client._make_request( "POST", f"/clients/{client_id}/roles", data=role_data, realm=realm ) return {"status": "created", "message": f"Client role {name} created successfully"}