who_am_i
Retrieve detailed user information for the authenticated Reddit account, including karma, account status, and metadata, to analyze profile and activity data effectively.
Instructions
Get information about the currently authenticated user.
Returns:
Dictionary containing structured user information with the following structure:
{
'id': str, # Full user ID (e.g., 't2_abc123')
'name': str, # Username
'created_utc': float, # Account creation timestamp
'comment_karma': int, # Comment karma
'link_karma': int, # Post/link karma
'total_karma': int, # Total karma (comments + posts)
'awardee_karma': int, # Karma from awards received
'awarder_karma': int, # Karma from awards given
'has_verified_email': bool, # Whether email is verified
'is_employee': bool, # Whether user is a Reddit employee
'is_friend': bool, # Whether user is a friend
'is_gold': bool, # Whether user has Reddit Premium
'is_mod': bool, # Whether user is a moderator
'is_suspended': bool, # Whether account is suspended
'verified': bool, # Whether account is verified
'has_subscribed': bool, # Whether user has subscribed to Premium
'snoovatar_img': str, # URL to snoovatar image
'icon_img': str, # URL to user's icon
'pref_show_snoovatar': bool, # Whether to show snoovatar
'snoovatar_size': Optional[List[int]], # Snoovatar dimensions
'subreddit': Optional[Dict], # User's profile subreddit info
'metadata': {
'fetched_at': float, # Timestamp when data was fetched
'is_authenticated': bool, # Whether user is authenticated
'is_moderator': bool, # Whether user is a moderator
'has_verified_email': bool, # Whether email is verified
'has_mail': bool, # Whether user has unread messages
'has_mod_mail': bool, # Whether user has mod mail
'has_subscribed': bool, # Whether user has subscribed to Premium
'in_chat': bool, # Whether user is in chat
'in_redesign_beta': bool, # Whether user is in redesign beta
'new_modmail_exists': bool, # Whether user has new modmail
'pref_no_profanity': bool, # Whether to filter profanity
'suspension_expiration_utc': Optional[float], # When suspension ends if suspended
}
}
Raises:
ValueError: If user authentication is not available
RuntimeError: For other errors during the operation
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- server.py:1417-1559 (handler)The handler function for the 'who_am_i' tool, decorated with @mcp.tool() and @require_write_access. It retrieves detailed information about the currently authenticated Reddit user using the PRAW Reddit client instance from RedditClientManager, constructs a structured dictionary with user stats, karma, preferences, and metadata, and handles authentication checks and errors.@require_write_access def who_am_i() -> Dict[str, Any]: """Get information about the currently authenticated user. Returns: Dictionary containing structured user information with the following structure: { 'id': str, # Full user ID (e.g., 't2_abc123') 'name': str, # Username 'created_utc': float, # Account creation timestamp 'comment_karma': int, # Comment karma 'link_karma': int, # Post/link karma 'total_karma': int, # Total karma (comments + posts) 'awardee_karma': int, # Karma from awards received 'awarder_karma': int, # Karma from awards given 'has_verified_email': bool, # Whether email is verified 'is_employee': bool, # Whether user is a Reddit employee 'is_friend': bool, # Whether user is a friend 'is_gold': bool, # Whether user has Reddit Premium 'is_mod': bool, # Whether user is a moderator 'is_suspended': bool, # Whether account is suspended 'verified': bool, # Whether account is verified 'has_subscribed': bool, # Whether user has subscribed to Premium 'snoovatar_img': str, # URL to snoovatar image 'icon_img': str, # URL to user's icon 'pref_show_snoovatar': bool, # Whether to show snoovatar 'snoovatar_size': Optional[List[int]], # Snoovatar dimensions 'subreddit': Optional[Dict], # User's profile subreddit info 'metadata': { 'fetched_at': float, # Timestamp when data was fetched 'is_authenticated': bool, # Whether user is authenticated 'is_moderator': bool, # Whether user is a moderator 'has_verified_email': bool, # Whether email is verified 'has_mail': bool, # Whether user has unread messages 'has_mod_mail': bool, # Whether user has mod mail 'has_subscribed': bool, # Whether user has subscribed to Premium 'in_chat': bool, # Whether user is in chat 'in_redesign_beta': bool, # Whether user is in redesign beta 'new_modmail_exists': bool, # Whether user has new modmail 'pref_no_profanity': bool, # Whether to filter profanity 'suspension_expiration_utc': Optional[float], # When suspension ends if suspended } } Raises: ValueError: If user authentication is not available RuntimeError: For other errors during the operation """ manager = RedditClientManager() if not manager.client: raise RuntimeError("Reddit client not initialized") try: logger.info("Getting information about the current authenticated user") # Check if user is authenticated if not manager.check_user_auth(): raise ValueError( "User authentication required. Please provide valid credentials." ) # Get the current user current_user = manager.client.user.me() if not current_user: raise ValueError("Failed to retrieve current user information") username = getattr(current_user, "name", "unknown") logger.info(f"Retrieved information for user: {username}") # Get user preferences and other attributes with safe defaults prefs = getattr(current_user, "prefs", {}) or {} subreddit = getattr(current_user, "subreddit", {}) or {} # Build the user info dictionary user_info = { "id": getattr(current_user, "id", ""), "name": username, "created_utc": getattr(current_user, "created_utc", 0), "comment_karma": getattr(current_user, "comment_karma", 0), "link_karma": getattr(current_user, "link_karma", 0), "total_karma": getattr(current_user, "total_karma", 0), "awardee_karma": getattr(current_user, "awardee_karma", 0), "awarder_karma": getattr(current_user, "awarder_karma", 0), "has_verified_email": getattr(current_user, "has_verified_email", False), "is_employee": getattr(current_user, "is_employee", False), "is_friend": getattr(current_user, "is_friend", False), "is_gold": getattr(current_user, "is_gold", False), "is_mod": getattr(current_user, "is_mod", False), "is_suspended": getattr(current_user, "is_suspended", False), "verified": getattr(current_user, "verified", False), "has_subscribed": getattr(current_user, "has_subscribed", False), "snoovatar_img": getattr(current_user, "snoovatar_img", ""), "icon_img": getattr(current_user, "icon_img", ""), "pref_show_snoovatar": prefs.get("show_snoovatar", False), "snoovatar_size": getattr(current_user, "snoovatar_size", None), "subreddit": { "display_name": subreddit.get("display_name", ""), "name": subreddit.get("display_name_prefixed", ""), "public_description": subreddit.get("public_description", ""), "subscribers": subreddit.get("subscribers", 0), "created_utc": subreddit.get("created_utc", 0), "over18": subreddit.get("over18", False), "suggested_comment_sort": subreddit.get( "suggested_comment_sort", "best" ), "title": subreddit.get("title", ""), "url": subreddit.get("url", ""), } if subreddit else None, "metadata": { "fetched_at": time.time(), "is_authenticated": True, "is_moderator": getattr(current_user, "is_mod", False), "has_verified_email": getattr( current_user, "has_verified_email", False ), "has_mail": getattr(current_user, "has_mail", False), "has_mod_mail": getattr(current_user, "has_mod_mail", False), "has_subscribed": getattr(current_user, "has_subscribed", False), "in_chat": getattr(current_user, "in_chat", False), "in_redesign_beta": prefs.get("in_redesign_beta", False), "new_modmail_exists": getattr( current_user, "new_modmail_exists", False ), "pref_no_profanity": prefs.get("no_profanity", True), "suspension_expiration_utc": getattr( current_user, "suspension_expiration_utc", None ), }, } return user_info except Exception as e: logger.error(f"Error in who_am_i: {e}") if "401" in str(e) or "unauthorized" in str(e).lower(): raise ValueError( "Authentication failed. Please check your credentials." ) from e if isinstance(e, (ValueError, RuntimeError)): raise raise RuntimeError(f"Failed to retrieve user information: {e}") from e