change_password
Change your AWS Cognito user password by providing your current and new passwords for authentication security updates.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| oldPassword | Yes | ||
| newPassword | Yes |
Implementation Reference
- index.ts:464-542 (registration)Registers the change_password tool with McpServer, defining input schema and inline handler function that uses AWS Cognito to change the current user's password."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()}`, } ] }); }); }); }); } )
- index.ts:469-541 (handler)The core handler logic for the change_password tool. It retrieves the current Cognito user, verifies the session, and invokes changePassword with old and new passwords, handling success and error responses.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:466-468 (schema)Zod schema defining input parameters for the change_password tool: oldPassword and newPassword as strings.oldPassword: z.string(), newPassword: z.string(), },