reset_password_send_code
Initiate password reset by sending a verification code to the user's registered contact method, enabling secure account recovery.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| username | Yes |
Implementation Reference
- index.ts:285-333 (handler)The main handler function for the 'reset_password_send_code' tool. It creates a CognitoUser instance for the given username and calls forgotPassword to send a password reset code. On success, it returns details about the delivery; on failure, it rejects with error information.async ({ username }) => { const cognitoUser = new CognitoUser({ Username: username, Pool: userPool, }); return new Promise((resolve, reject) => { cognitoUser.forgotPassword({ onSuccess: (data) => { console.log('Password reset request successful:', data); resolve({ content: [ { type: "text" as const, text: "Code sent successfully", }, { type: "text" as const, text: `Delivery method: ${data.CodeDeliveryDetails?.DeliveryMedium || 'Unknown'}`, }, { type: "text" as const, text: `Destination: ${data.CodeDeliveryDetails?.Destination || 'Unknown'}`, }, { type: "text" as const, text: `Attribute name: ${data.CodeDeliveryDetails?.AttributeName || 'Unknown'}`, } ] }); }, onFailure: (err) => { console.error('Password reset request failed:', err.message); reject({ content: [ { type: "text" as const, text: `Password reset request failed: ${err.message}`, }, { type: "text" as const, text: `Error code: ${(err as any).code || 'Unknown'}`, } ] }); }, }); }); }
- index.ts:282-284 (schema)Zod schema defining the input parameters for the tool: a required 'username' string.{ username: z.string(), },
- index.ts:280-334 (registration)The server.tool call that registers the 'reset_password_send_code' tool, including its name, input schema, and inline handler function.server.tool( "reset_password_send_code", { username: z.string(), }, async ({ username }) => { const cognitoUser = new CognitoUser({ Username: username, Pool: userPool, }); return new Promise((resolve, reject) => { cognitoUser.forgotPassword({ onSuccess: (data) => { console.log('Password reset request successful:', data); resolve({ content: [ { type: "text" as const, text: "Code sent successfully", }, { type: "text" as const, text: `Delivery method: ${data.CodeDeliveryDetails?.DeliveryMedium || 'Unknown'}`, }, { type: "text" as const, text: `Destination: ${data.CodeDeliveryDetails?.Destination || 'Unknown'}`, }, { type: "text" as const, text: `Attribute name: ${data.CodeDeliveryDetails?.AttributeName || 'Unknown'}`, } ] }); }, onFailure: (err) => { console.error('Password reset request failed:', err.message); reject({ content: [ { type: "text" as const, text: `Password reset request failed: ${err.message}`, }, { type: "text" as const, text: `Error code: ${(err as any).code || 'Unknown'}`, } ] }); }, }); }); } )