Skip to main content
Glama
gitCarrot

AWS Cognito MCP Server

by gitCarrot

change_password

Change your AWS Cognito user password by providing your current and new passwords for authentication security updates.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
oldPasswordYes
newPasswordYes

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()}`,
                                }
                            ]
                        });
                    });
                });
            });
        }
    )
  • 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()}`,
                            }
                        ]
                    });
                });
            });
        });
    }
  • Zod schema defining input parameters for the change_password tool: oldPassword and newPassword as strings.
        oldPassword: z.string(),
        newPassword: z.string(),
    },

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/gitCarrot/mcp-server-aws-cognito'

If you have feedback or need assistance with the MCP directory API, please join our Discord server