list-users
Retrieve and display user accounts within a specified Keycloak realm to manage access and review user data.
Instructions
List users in a specific realm
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| realm | Yes | Realm name |
Implementation Reference
- src/index.ts:537-550 (handler)The tool handler for 'list-users' that parses the input arguments using ListUsersSchema, retrieves the list of users from the Keycloak service, and formats the response as a text list of usernames and IDs.case "list-users": { const { realm } = ListUsersSchema.parse(args); const users = await keycloakService.listUsers(realm); return { content: [ { type: "text", text: `Users in realm ${realm}:\n${users .map((u) => `- ${u.username} (${u.id})`) .join("\n")}`, }, ], }; }
- src/index.ts:151-155 (helper)The core implementation in KeycloakService that authenticates the client, sets the realm configuration, and fetches all users using the Keycloak admin client API.async listUsers(realm: string) { await this.authenticate(); this.client.setConfig({ realmName: realm }); return await this.client.users.find(); }
- src/index.ts:467-469 (schema)Zod schema used for runtime validation of the tool's input parameters (requires 'realm' as a string).const ListUsersSchema = z.object({ realm: z.string(), });
- src/index.ts:387-396 (registration)Tool registration entry in the listTools handler, defining the name, description, and JSON schema for input validation.name: "list-users", description: "List users in a specific realm", inputSchema: { type: "object", properties: { realm: { type: "string", description: "Realm name" }, }, required: ["realm"], }, },