Skip to main content
Glama
HaithamOumerzoug

Keycloak MCP Server

list-users

Retrieve a list of users within a specified Keycloak realm using the MCP server, enabling efficient user management and administrative oversight.

Instructions

List users in a specific realm

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
realmYes

Implementation Reference

  • The main implementation of the list-users tool, which parses input arguments using ListUsersSchema, queries Keycloak for users in the specified realm, and returns a formatted list.
    public async listUsers(args: unknown): Promise<string> {
      const { realm } = ListUsersSchema.parse(args);
      const users: UserRepresentation[] = await this.kcAdminClient.users.find({
        realm,
      });
      return `Users in realm ${realm}:\n${users
        .map((u) => `- ${u.username} (${u.id})`)
        .join("\n")}`;
    }
  • Zod input schema for validating arguments in the listUsers handler (requires 'realm' string).
    export const ListUsersSchema = z.object({
      realm: z.string(),
    });
  • JSON Schema definition for list-users tool input, used in tool registration (requires 'realm' string).
    "list-users": {
      type: "object",
      properties: {
        realm: { type: "string" },
      },
      required: ["realm"],
    },
  • src/server.ts:52-56 (registration)
    Registration of the list-users tool in the ListToolsRequestHandler response.
      name: "list-users",
      description: "List users in a specific realm",
      inputSchema: InputSchema["list-users"],
    },
    {
  • Handler dispatch in CallToolRequestHandler that calls the Keycloak service's listUsers method.
    case "list-users":
      return {
        content: [
          { type: "text", text: await keycloakService.listUsers(args) },
        ],
      };
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