Skip to main content
Glama
gitCarrot

AWS Cognito MCP Server

by gitCarrot

getCurrentUser

Retrieve the currently authenticated user's profile and session information from AWS Cognito for identity verification and user context management.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function for the 'getCurrentUser' tool. It fetches the current Cognito user using userPool.getCurrentUser(), retrieves the session and user attributes, and returns the attributes along with session validity, or appropriate error messages if no user is signed in or errors occur.
    async ({ }) => { 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.getUserAttributes((err, attributes) => { if (err) { reject({ content: [ { type: "text" as const, text: `Error getting user attributes: ${err.message}`, } ] }); return; } const attributeItems = attributes || []; resolve({ content: [ { type: "text" as const, text: "User attributes:", }, ...attributeItems.map((attr) => ({ type: "text" as const, text: `${attr.getName()}: ${attr.getValue()}`, })), { type: "text" as const, text: `Session validity: ${_session.isValid() ? 'Valid' : 'Invalid'}`, } ] }); }); }); }); }
  • index.ts:394-461 (registration)
    Registration of the 'getCurrentUser' MCP tool using server.tool(). Input schema is empty object (no parameters). The handler is the inline async function.
    server.tool( "getCurrentUser", { }, async ({ }) => { 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.getUserAttributes((err, attributes) => { if (err) { reject({ content: [ { type: "text" as const, text: `Error getting user attributes: ${err.message}`, } ] }); return; } const attributeItems = attributes || []; resolve({ content: [ { type: "text" as const, text: "User attributes:", }, ...attributeItems.map((attr) => ({ type: "text" as const, text: `${attr.getName()}: ${attr.getValue()}`, })), { type: "text" as const, text: `Session validity: ${_session.isValid() ? 'Valid' : 'Invalid'}`, } ] }); }); }); }); } )
  • Input schema for 'getCurrentUser' tool: empty object, indicating no input parameters required.
    { },

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