reset-user-password
Reset or set password for a user in a Keycloak realm, with optional temporary flag.
Instructions
Reset or set a new password for a user in a specific realm
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| realm | Yes | Realm name | |
| userId | Yes | User ID | |
| password | Yes | New password | |
| temporary | No | Whether the password is temporary |
Implementation Reference
- src/index.ts:282-300 (handler)The actual handler method `resetUserPassword` on the KeycloakService class. It authenticates, sets the realm, and calls the Keycloak admin client's `users.resetPassword` API with the password credential.
async resetUserPassword(params: { realm: string; userId: string; password: string; temporary?: boolean; }) { await this.authenticate(); this.client.setConfig({ realmName: params.realm }); await this.client.users.resetPassword({ id: params.userId, realm: params.realm, credential: { type: "password", value: params.password, temporary: params.temporary || false, }, }); } - src/index.ts:484-489 (schema)Zod validation schema `ResetUserPasswordSchema` defining the input: realm (string), userId (string), password (string), and temporary (boolean with default false).
const ResetUserPasswordSchema = z.object({ realm: z.string(), userId: z.string(), password: z.string(), temporary: z.boolean().default(false), }); - src/index.ts:424-437 (registration)Tool registration in the ListToolsRequestSchema handler, defining the tool name 'reset-user-password', description, and input schema (realm, userId, password, temporary).
{ name: "reset-user-password", description: "Reset or set a new password for a user in a specific realm", inputSchema: { type: "object", properties: { realm: { type: "string", description: "Realm name" }, userId: { type: "string", description: "User ID" }, password: { type: "string", description: "New password" }, temporary: { type: "boolean", description: "Whether the password is temporary", default: false }, }, required: ["realm", "userId", "password"], }, }, - src/index.ts:584-597 (handler)The case branch in CallToolRequestSchema handler: parses args with ResetUserPasswordSchema, calls keycloakService.resetUserPassword(), and returns a success message indicating whether the password was set as temporary.
case "reset-user-password": { const params = ResetUserPasswordSchema.parse(args); await keycloakService.resetUserPassword(params); return { content: [ { type: "text", text: `Password ${params.temporary ? "temporarily " : ""}reset successfully for user ${params.userId} in realm ${params.realm}${ params.temporary ? ". User will be required to change password on next login." : "." }`, }, ], }; }