Skip to main content
Glama
gitCarrot

AWS Cognito MCP Server

by gitCarrot

sign_in

Authenticate users by verifying their username and password credentials with AWS Cognito to enable secure access to applications.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
usernameYes
passwordYes

Implementation Reference

  • The handler function for the 'sign_in' tool. It authenticates the user with AWS Cognito using the provided username and password, returns access, ID, and refresh tokens on success, or an error message on failure.
    async ({ username, password }) => {
        const authenticationDetails = new AuthenticationDetails({
            Username: username,
            Password: password,
          });
          const cognitoUser = new CognitoUser({
            Username: username,
            Pool: userPool,
          });
    
        return new Promise((resolve, reject) => {
        cognitoUser.authenticateUser(authenticationDetails, {
        onSuccess: (result) => {
                    resolve({
                        content: [
                            {
                                type: "text" as const,
                                text: "Login successful",
                            },
                            {
                                type: "text" as const,
                                text: `Access Token: ${result.getAccessToken().getJwtToken()}`,
                            },
                            {
                                type: "text" as const,
                                text: `ID Token: ${result.getIdToken().getJwtToken()}`,
                            },
                            {
                                type: "text" as const,
                                text: `Refresh Token: ${result.getRefreshToken().getToken()}`,
                            }
                        ]
                    });
                },
                onFailure: (err) => {
                    reject({
                        content: [
                            {
                                type: "text" as const,
                                text: `Login failed: ${err.message}`,
                            },
                            {
                                type: "text" as const,
                                text: `Error code: ${(err as any).code || 'Unknown'}`,
                            }
                        ]
                    });
                },
            });
        });
    }
  • Zod input schema for the 'sign_in' tool, requiring 'username' and 'password' as strings.
    {
        username: z.string(),
        password: z.string(),
    },
  • index.ts:221-278 (registration)
    Registration of the 'sign_in' tool using server.tool(), specifying the name, input schema, and handler function.
    server.tool(
        "sign_in",
        {
            username: z.string(),
            password: z.string(),
        },
        async ({ username, password }) => {
            const authenticationDetails = new AuthenticationDetails({
                Username: username,
                Password: password,
              });
              const cognitoUser = new CognitoUser({
                Username: username,
                Pool: userPool,
              });
    
            return new Promise((resolve, reject) => {
            cognitoUser.authenticateUser(authenticationDetails, {
            onSuccess: (result) => {
                        resolve({
                            content: [
                                {
                                    type: "text" as const,
                                    text: "Login successful",
                                },
                                {
                                    type: "text" as const,
                                    text: `Access Token: ${result.getAccessToken().getJwtToken()}`,
                                },
                                {
                                    type: "text" as const,
                                    text: `ID Token: ${result.getIdToken().getJwtToken()}`,
                                },
                                {
                                    type: "text" as const,
                                    text: `Refresh Token: ${result.getRefreshToken().getToken()}`,
                                }
                            ]
                        });
                    },
                    onFailure: (err) => {
                        reject({
                            content: [
                                {
                                    type: "text" as const,
                                    text: `Login failed: ${err.message}`,
                                },
                                {
                                    type: "text" as const,
                                    text: `Error code: ${(err as any).code || 'Unknown'}`,
                                }
                            ]
                        });
                    },
                });
            });
        }
    )

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