sign_in
Authenticate users with username and password credentials to access AWS Cognito protected applications and services.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| password | Yes | ||
| username | Yes |
Implementation Reference
- index.ts:227-277 (handler)The handler function for the 'sign_in' tool. It authenticates the user using AWS Cognito by creating AuthenticationDetails and a CognitoUser instance, then calls authenticateUser. On success, it returns login success message with access, ID, and refresh tokens. On failure, it rejects with error message and code.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)Input schema for the 'sign_in' tool defined using Zod, 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'}`, } ] }); }, }); }); } )