add-user-to-group
Assign a user to a specific group in Keycloak by specifying the realm, user ID, and group ID. Streamlines group management for organized user access and permissions.
Instructions
Add a user to a group
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| groupId | Yes | ||
| realm | Yes | ||
| userId | Yes |
Implementation Reference
- src/services/keycloak.ts:89-97 (handler)The core handler function for 'add-user-to-group' tool. Parses input arguments using Zod schema and calls Keycloak admin client to add the user to the specified group.public async addUserToGroup(args: unknown): Promise<string> { const { realm, userId, groupId } = AddUserToGroupSchema.parse(args); await this.kcAdminClient.users.addToGroup({ realm, id: userId, groupId, }); return `User ${userId} added to group ${groupId} in realm ${realm}`; }
- src/schemas/index.ts:88-96 (schema)JSON schema definition for the 'add-user-to-group' tool input, used in tool registration."add-user-to-group": { type: "object", properties: { realm: { type: "string" }, userId: { type: "string" }, groupId: { type: "string" }, }, required: ["realm", "userId", "groupId"], },
- src/schemas/index.ts:27-31 (schema)Zod schema for validating inputs in the handler, corresponding to the tool's input schema.export const AddUserToGroupSchema = z.object({ realm: z.string(), userId: z.string(), groupId: z.string(), });
- src/server.ts:61-65 (registration)Tool registration in the ListTools handler, defining name, description, and input schema.{ name: "add-user-to-group", description: "Add a user to a group", inputSchema: InputSchema["add-user-to-group"], },
- src/server.ts:128-136 (registration)Dispatch in the CallTool request handler that routes to the keycloakService.addUserToGroup method.case "add-user-to-group": return { content: [ { type: "text", text: await keycloakService.addUserToGroup(args), }, ], };