create_realm_role
Define and manage access permissions by creating new realm roles in Keycloak, specifying name, description, type, and target realm.
Instructions
Create a new realm role.
Args:
name: Role name
description: Role description
composite: Whether this is a composite role
client_role: Whether this is a client role
realm: Target realm (uses default if not specified)
Returns:
Status message
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| client_role | No | ||
| composite | No | ||
| description | No | ||
| name | Yes | ||
| realm | No |
Implementation Reference
- src/tools/role_tools.py:54-82 (handler)The main handler function decorated with @mcp.tool(), implementing the create_realm_role tool logic using KeycloakClient to POST a new role.@mcp.tool() async def create_realm_role( name: str, description: Optional[str] = None, composite: bool = False, client_role: bool = False, realm: Optional[str] = None, ) -> Dict[str, str]: """ Create a new realm role. Args: name: Role name description: Role description composite: Whether this is a composite role client_role: Whether this is a client role realm: Target realm (uses default if not specified) Returns: Status message """ role_data = {"name": name, "composite": composite, "clientRole": client_role} if description: role_data["description"] = description await client._make_request("POST", "/roles", data=role_data, realm=realm) return {"status": "created", "message": f"Realm role {name} created successfully"}