change_password
Change your AWS Cognito user password by providing your current password and setting a new one for enhanced account security.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| newPassword | Yes | ||
| oldPassword | Yes |
Implementation Reference
- index.ts:469-542 (handler)The handler function executes the password change logic using Amazon Cognito's changePassword method on the current user after checking the session.async ({ oldPassword, newPassword }) => { return new Promise((resolve, reject) => { const cognitoUser = userPool.getCurrentUser(); if (!cognitoUser) { resolve({ content: [ { type: "text" as const, text: "No user currently signed in", } ] }); return; } cognitoUser.getSession((err: Error | null, _session: CognitoUserSession) => { if (err) { reject({ content: [ { type: "text" as const, text: `Error getting session: ${err.message}`, } ] }); return; } cognitoUser.changePassword(oldPassword, newPassword, (err, result) => { if (err) { reject({ content: [ { type: "text" as const, text: `Failed to change password: ${err.message}`, }, { type: "text" as const, text: `Error code: ${(err as any).code || 'Unknown'}`, }, { type: "text" as const, text: `Time: ${new Date().toISOString()}`, } ] }); return; } resolve({ content: [ { type: "text" as const, text: "Password changed successfully", }, { type: "text" as const, text: `Username: ${cognitoUser.getUsername()}`, }, { type: "text" as const, text: `Result: ${result}`, }, { type: "text" as const, text: `Time: ${new Date().toISOString()}`, } ] }); }); }); }); } )
- index.ts:465-468 (schema)Zod schema defining input parameters: oldPassword and newPassword as strings.{ oldPassword: z.string(), newPassword: z.string(), },
- index.ts:463-543 (registration)The server.tool call that registers the change_password tool with its schema and handler.server.tool( "change_password", { oldPassword: z.string(), newPassword: z.string(), }, async ({ oldPassword, newPassword }) => { return new Promise((resolve, reject) => { const cognitoUser = userPool.getCurrentUser(); if (!cognitoUser) { resolve({ content: [ { type: "text" as const, text: "No user currently signed in", } ] }); return; } cognitoUser.getSession((err: Error | null, _session: CognitoUserSession) => { if (err) { reject({ content: [ { type: "text" as const, text: `Error getting session: ${err.message}`, } ] }); return; } cognitoUser.changePassword(oldPassword, newPassword, (err, result) => { if (err) { reject({ content: [ { type: "text" as const, text: `Failed to change password: ${err.message}`, }, { type: "text" as const, text: `Error code: ${(err as any).code || 'Unknown'}`, }, { type: "text" as const, text: `Time: ${new Date().toISOString()}`, } ] }); return; } resolve({ content: [ { type: "text" as const, text: "Password changed successfully", }, { type: "text" as const, text: `Username: ${cognitoUser.getUsername()}`, }, { type: "text" as const, text: `Result: ${result}`, }, { type: "text" as const, text: `Time: ${new Date().toISOString()}`, } ] }); }); }); }); } )