reset_password_send_code
Send a verification code to reset a user's password in AWS Cognito by providing their username.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| username | Yes |
Implementation Reference
- index.ts:285-333 (handler)Handler function that initiates password reset by calling forgotPassword on CognitoUser, sending a verification code to the user.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)Input schema for the tool, defining 'username' as a required string using Zod validation.{ username: z.string(), },
- index.ts:280-334 (registration)Registration of the 'reset_password_send_code' tool using server.tool(), including inline schema and handler.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'}`, } ] }); }, }); }); } )