sign_in
Authenticate users by verifying their username and password credentials with AWS Cognito to enable secure access to applications.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| username | Yes | ||
| password | Yes |
Implementation Reference
- index.ts:227-277 (handler)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'}`, } ] }); }, }); }); }
- index.ts:223-226 (schema)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'}`, } ] }); }, }); }); } )