Skip to main content
Glama
idoyudha

mcp-keycloak

by idoyudha

list_client_roles

Retrieve and filter client roles in Keycloak by specifying client ID, search criteria, and pagination options to manage access permissions.

Instructions

List roles for a specific client.

Args:
    client_id: Client database ID
    first: Pagination offset
    max: Maximum results size
    search: Search string
    realm: Target realm (uses default if not specified)

Returns:
    List of client roles

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
client_idYes
firstNo
maxNo
searchNo
realmNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The core handler function for the 'list_client_roles' MCP tool. Decorated with @mcp.tool() which registers it. Takes client_id and pagination/search params, uses KeycloakClient to GET /clients/{client_id}/roles.
    @mcp.tool()
    async def list_client_roles(
        client_id: str,
        first: Optional[int] = None,
        max: Optional[int] = None,
        search: Optional[str] = None,
        realm: Optional[str] = None,
    ) -> List[Dict[str, Any]]:
        """
        List roles for a specific client.
    
        Args:
            client_id: Client database ID
            first: Pagination offset
            max: Maximum results size
            search: Search string
            realm: Target realm (uses default if not specified)
    
        Returns:
            List of client roles
        """
        params = {}
        if first is not None:
            params["first"] = first
        if max is not None:
            params["max"] = max
        if search:
            params["search"] = search
    
        return await client._make_request(
            "GET", f"/clients/{client_id}/roles", params=params, realm=realm
        )
  • The _make_request helper method in KeycloakClient class, called by list_client_roles to perform the authenticated GET request to Keycloak API.
    async def _make_request(
        self,
        method: str,
        endpoint: str,
        data: Optional[Dict] = None,
        params: Optional[Dict] = None,
        skip_realm: bool = False,
        realm: Optional[str] = None,
    ) -> Any:
        """Make authenticated request to Keycloak API"""
        if skip_realm:
            url = f"{self.server_url}/auth/admin{endpoint}"
        else:
            # Use provided realm or fall back to configured realm
            target_realm = realm if realm is not None else self.realm_name
            url = f"{self.server_url}/auth/admin/realms/{target_realm}{endpoint}"
    
        try:
            client = await self._ensure_client()
            headers = await self._get_headers()
    
            response = await client.request(
                method=method,
                url=url,
                headers=headers,
                json=data,
                params=params,
            )
    
            # If token expired, refresh and retry
            if response.status_code == 401:
                await self._get_token()
                headers = await self._get_headers()
                response = await client.request(
                    method=method,
                    url=url,
                    headers=headers,
                    json=data,
                    params=params,
                )
    
            response.raise_for_status()
    
            if response.content:
                return response.json()
            return None
    
        except httpx.RequestError as e:
            raise Exception(f"Keycloak API request failed: {str(e)}")
  • src/main.py:22-22 (registration)
    Import of role_tools module in main.py, which triggers execution of @mcp.tool() decorators to register all tools including list_client_roles with the MCP server.
    from .tools import role_tools  # noqa: F401
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions pagination parameters (first, max) and search functionality, which is helpful. However, it doesn't describe important behavioral aspects like whether this is a read-only operation (implied but not stated), what permissions are required, rate limits, error conditions, or how the returned list is structured beyond 'List of client roles'.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with clear sections for Args and Returns. It's appropriately sized at 7 lines total. The purpose statement is front-loaded, and each parameter explanation is concise. There's no wasted text, though the formatting with quotes and line breaks could be slightly cleaner.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has 5 parameters (1 required), no annotations, but has an output schema, the description is moderately complete. It explains all parameters well and states the return type. However, for a tool with no annotations, it should provide more behavioral context about permissions, side effects, and typical usage patterns. The presence of an output schema reduces the need to describe return values in detail.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description provides meaningful context for all 5 parameters beyond what the schema offers (0% coverage). It explains that 'client_id' is a 'Client database ID', 'first' is a 'Pagination offset', 'max' is 'Maximum results size', 'search' is a 'Search string', and 'realm' is 'Target realm (uses default if not specified)'. This adds significant value over the bare schema with just titles.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states 'List roles for a specific client' which is a specific verb+resource combination. It distinguishes from sibling tools like 'list_realm_roles' and 'list_clients' by specifying client roles rather than realm roles or clients themselves. However, it doesn't explicitly differentiate from 'get_client' or 'get_client_service_account' which might also return role information.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention when this tool is appropriate versus 'get_client' (which might return role information), 'list_realm_roles', or other role-related tools like 'assign_client_role_to_user'. There's no context about prerequisites, permissions needed, or typical use cases.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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