Skip to main content
Glama
HaithamOumerzoug

Keycloak MCP Server

list-client-roles

Retrieve roles for a specific client in Keycloak realms using the Model Context Protocol server, enabling efficient management of user permissions and access rights.

Instructions

List roles in a specific client

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
clientUniqueIdYes
realmYes

Implementation Reference

  • The core handler function that parses input arguments, fetches client roles from Keycloak Admin Client, and returns a formatted list.
    public async listClientRoles(args: unknown): Promise<string> {
      const { realm, clientUniqueId } = ListClientRolesSchema.parse(args);
      const roles: RoleRepresentation[] =
        await this.kcAdminClient.clients.listRoles({
          id: clientUniqueId,
          realm,
        });
      return `Roles in client ${clientUniqueId} in realm ${realm}:\n${roles
        .map((r) => `- ${r.name}`)
        .join("\n")}`;
    }
  • JSON schema definition for the 'list-client-roles' tool input, used in tool registration.
    "list-client-roles": {
      type: "object",
      properties: {
        realm: { type: "string" },
        clientUniqueId: { type: "string" },
      },
      required: ["realm", "clientUniqueId"],
    },
  • src/server.ts:76-80 (registration)
    Tool registration in the ListTools response, including name, description, and input schema reference.
    {
      name: "list-client-roles",
      description: "List roles in a specific client",
      inputSchema: InputSchema["list-client-roles"],
    },
  • Dispatch handler in the CallToolRequest switch statement that invokes the KeycloakService handler.
    case "list-client-roles":
      return {
        content: [
          {
            type: "text",
            text: await keycloakService.listClientRoles(args),
          },
        ],
      };
  • Zod schema for input validation used within the handler.
    export const ListClientRolesSchema = z.object({
      realm: z.string(),
      clientUniqueId: z.string(),
    });
Install Server

Other Tools

Related 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/HaithamOumerzoug/keycloak-mcp'

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