Skip to main content
Glama
gitCarrot

AWS Cognito MCP Server

by gitCarrot

getCurrentUser

Retrieves the currently authenticated user's information from AWS Cognito for authentication verification and user management.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function that executes the 'getCurrentUser' tool. It retrieves the current Cognito user from the user pool, checks if signed in, fetches the session and user attributes asynchronously, and returns a formatted content response with attributes and session validity.
    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 the 'getCurrentUser' tool, which requires no parameters (empty object).
    { },
  • index.ts:394-461 (registration)
    Registration of the 'getCurrentUser' tool using server.tool(), including name, schema, and handler reference.
    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'}`, } ] }); }); }); }); } )

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