Skip to main content
Glama
Arindam200

Reddit MCP Server

get_user_comments

Retrieve a Reddit user's comment history with customizable sorting, time filtering, and result limits for analysis or review.

Instructions

Get a user's comment history.

Args:
    username: The username of the Reddit user (with or without 'u/' prefix)
    sort: Sort order for comments - one of: "new", "hot", "top", "controversial"
    time_filter: Time period to filter comments (e.g. "hour", "day", "week", "month", "year", "all")
    limit: Number of comments to return (1-100)

Returns:
    Dictionary containing structured comment history with the following structure:
    {
        'username': str,  # The username
        'sort': str,  # Sort method used
        'time_filter': str,  # Time filter used
        'comments': [  # List of comments
            {
                'id': str,  # Comment ID
                'body': str,  # Comment text content
                'author': str,  # Author's username
                'subreddit': str,  # Subreddit where comment was posted
                'score': int,  # Comment score (upvotes - downvotes)
                'created_utc': float,  # Comment creation timestamp
                'permalink': str,  # Relative URL to the comment
                'link_title': str,  # Title of the post being commented on
                'link_id': str,  # ID of the post
                'parent_id': str,  # ID of parent comment or post
                'is_submitter': bool,  # Whether commenter is the post author
                'stickied': bool,  # Whether comment is stickied
                'distinguished': Optional[str],  # Distinguishing type (e.g., 'moderator')
                'edited': bool,  # Whether comment has been edited
                'gilded': int,  # Number of times gilded
                'controversiality': int,  # Controversy score
                'depth': int,  # Comment depth in thread (0 for top-level)
            },
            ...
        ],
        'metadata': {
            'fetched_at': float,  # Timestamp when data was fetched
            'comment_count': int,  # Number of comments returned
        }
    }

Raises:
    ValueError: If username is invalid, sort method is invalid, or time_filter is invalid
    RuntimeError: For other errors during the operation

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
usernameYes
sortNonew
time_filterNoall
limitNo

Implementation Reference

  • The core handler function decorated with @mcp.tool(), which implements the logic to retrieve and format a specified user's Reddit comments based on sort order, time filter, and limit. It validates inputs, fetches data using PRAW Reddit API, structures the response with comment details, and includes metadata.
    @mcp.tool()
    def get_user_comments(
        username: str,
        sort: str = "new",
        time_filter: str = "all",
        limit: int = 25,
    ) -> Dict[str, Any]:
        """Get a user's comment history.
    
        Args:
            username: The username of the Reddit user (with or without 'u/' prefix)
            sort: Sort order for comments - one of: "new", "hot", "top", "controversial"
            time_filter: Time period to filter comments (e.g. "hour", "day", "week", "month", "year", "all")
            limit: Number of comments to return (1-100)
    
        Returns:
            Dictionary containing structured comment history with the following structure:
            {
                'username': str,  # The username
                'sort': str,  # Sort method used
                'time_filter': str,  # Time filter used
                'comments': [  # List of comments
                    {
                        'id': str,  # Comment ID
                        'body': str,  # Comment text content
                        'author': str,  # Author's username
                        'subreddit': str,  # Subreddit where comment was posted
                        'score': int,  # Comment score (upvotes - downvotes)
                        'created_utc': float,  # Comment creation timestamp
                        'permalink': str,  # Relative URL to the comment
                        'link_title': str,  # Title of the post being commented on
                        'link_id': str,  # ID of the post
                        'parent_id': str,  # ID of parent comment or post
                        'is_submitter': bool,  # Whether commenter is the post author
                        'stickied': bool,  # Whether comment is stickied
                        'distinguished': Optional[str],  # Distinguishing type (e.g., 'moderator')
                        'edited': bool,  # Whether comment has been edited
                        'gilded': int,  # Number of times gilded
                        'controversiality': int,  # Controversy score
                        'depth': int,  # Comment depth in thread (0 for top-level)
                    },
                    ...
                ],
                'metadata': {
                    'fetched_at': float,  # Timestamp when data was fetched
                    'comment_count': int,  # Number of comments returned
                }
            }
    
        Raises:
            ValueError: If username is invalid, sort method is invalid, or time_filter is invalid
            RuntimeError: For other errors during the operation
        """
        manager = RedditClientManager()
        if not manager.client:
            raise RuntimeError("Reddit client not initialized")
    
        # Validate username
        if not username or not isinstance(username, str) or username.startswith((" ", "/")):
            raise ValueError("Invalid username provided")
    
        # Clean username
        clean_username = username[2:] if username.startswith("u/") else username
    
        # Validate sort method
        valid_sort = ["new", "hot", "top", "controversial"]
        if sort not in valid_sort:
            raise ValueError(
                f"Invalid sort method: {sort}. Must be one of: {', '.join(valid_sort)}"
            )
    
        # Validate time_filter
        valid_time_filters = ["hour", "day", "week", "month", "year", "all"]
        if time_filter not in valid_time_filters:
            raise ValueError(
                f"Invalid time_filter: {time_filter}. Must be one of: {', '.join(valid_time_filters)}"
            )
    
        # Clamp limit to valid range
        limit = max(1, min(100, limit))
    
        try:
            logger.info(
                f"Getting {limit} {sort} comments for u/{clean_username} (time_filter={time_filter})"
            )
            user = manager.client.redditor(clean_username)
    
            # Get comments based on sort method
            if sort == "new":
                comments = user.comments.new(limit=limit)
            elif sort == "hot":
                comments = user.comments.hot(limit=limit)
            elif sort == "top":
                comments = user.comments.top(time_filter=time_filter, limit=limit)
            elif sort == "controversial":
                comments = user.comments.controversial(time_filter=time_filter, limit=limit)
    
            # Convert to list and format
            comments_list = list(comments)
            formatted_comments = []
    
            for comment in comments_list:
                comment_data = {
                    "id": comment.id,
                    "body": comment.body,
                    "author": comment.author.name if comment.author else "[deleted]",
                    "subreddit": comment.subreddit.display_name,
                    "score": comment.score,
                    "created_utc": comment.created_utc,
                    "permalink": comment.permalink,
                    "link_title": getattr(comment, "link_title", ""),
                    "link_id": comment.link_id,
                    "parent_id": comment.parent_id,
                    "is_submitter": comment.is_submitter,
                    "stickied": comment.stickied,
                    "distinguished": comment.distinguished,
                    "edited": bool(comment.edited),
                    "gilded": getattr(comment, "gilded", 0),
                    "controversiality": getattr(comment, "controversiality", 0),
                    "depth": getattr(comment, "depth", 0),
                }
                formatted_comments.append(comment_data)
    
            return {
                "username": clean_username,
                "sort": sort,
                "time_filter": time_filter,
                "comments": formatted_comments,
                "metadata": {
                    "fetched_at": time.time(),
                    "comment_count": len(formatted_comments),
                },
            }
    
        except Exception as e:
            logger.error(f"Error getting comments for u/{clean_username}: {e}")
            if "NOT_FOUND" in str(e) or "USER_DOESNT_EXIST" in str(e):
                raise ValueError(f"User u/{clean_username} not found") from e
            raise RuntimeError(f"Failed to get user comments: {e}") from e
  • The docstring of the get_user_comments function defines the input schema (parameters with types and descriptions), output structure (detailed JSON schema), and possible errors, serving as the tool's schema definition.
    """Get a user's comment history.
    
    Args:
        username: The username of the Reddit user (with or without 'u/' prefix)
        sort: Sort order for comments - one of: "new", "hot", "top", "controversial"
        time_filter: Time period to filter comments (e.g. "hour", "day", "week", "month", "year", "all")
        limit: Number of comments to return (1-100)
    
    Returns:
        Dictionary containing structured comment history with the following structure:
        {
            'username': str,  # The username
            'sort': str,  # Sort method used
            'time_filter': str,  # Time filter used
            'comments': [  # List of comments
                {
                    'id': str,  # Comment ID
                    'body': str,  # Comment text content
                    'author': str,  # Author's username
                    'subreddit': str,  # Subreddit where comment was posted
                    'score': int,  # Comment score (upvotes - downvotes)
                    'created_utc': float,  # Comment creation timestamp
                    'permalink': str,  # Relative URL to the comment
                    'link_title': str,  # Title of the post being commented on
                    'link_id': str,  # ID of the post
                    'parent_id': str,  # ID of parent comment or post
                    'is_submitter': bool,  # Whether commenter is the post author
                    'stickied': bool,  # Whether comment is stickied
                    'distinguished': Optional[str],  # Distinguishing type (e.g., 'moderator')
                    'edited': bool,  # Whether comment has been edited
                    'gilded': int,  # Number of times gilded
                    'controversiality': int,  # Controversy score
                    'depth': int,  # Comment depth in thread (0 for top-level)
                },
                ...
            ],
            'metadata': {
                'fetched_at': float,  # Timestamp when data was fetched
                'comment_count': int,  # Number of comments returned
            }
        }
    
    Raises:
        ValueError: If username is invalid, sort method is invalid, or time_filter is invalid
        RuntimeError: For other errors during the operation
    """
  • server.py:419-419 (registration)
    The @mcp.tool() decorator registers the get_user_comments function as an MCP tool with the FastMCP server instance 'mcp'.
    @mcp.tool()
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It adds some context by detailing the return structure and error cases (Raises section), which helps the agent understand output format and potential failures. However, it lacks critical behavioral traits like authentication requirements, rate limits, or data freshness, which are essential for safe invocation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is front-loaded with a clear purpose statement, but it becomes overly verbose by including a full return structure dictionary, which could be summarized or moved to an output schema. The 'Args' and 'Returns' sections are helpful but lengthy, reducing efficiency. Some sentences, like the detailed comment fields, don't earn their place in a tool description meant for agent selection.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity (4 parameters, no annotations, no output schema), the description is mostly complete. It covers parameters thoroughly, explains the return structure in detail, and includes error cases. However, it misses behavioral aspects like authentication or rate limits, and the verbose return details could be optimized, but it's sufficient for the agent to understand the tool's function and outputs.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds significant meaning beyond the input schema, which has 0% description coverage. It explains each parameter's purpose, provides examples (e.g., 'with or without 'u/' prefix' for username), lists valid values for 'sort' and 'time_filter', and specifies the range for 'limit'. This fully compensates for the schema's lack of documentation, making parameters clear and actionable.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Get a user's comment history.' It specifies the verb ('Get') and resource ('user's comment history'), making the function unambiguous. However, it doesn't explicitly differentiate from sibling tools like 'get_user_posts' or 'get_user_info,' which prevents a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools like 'get_user_posts' for posts instead of comments, or 'get_user_info' for general user data. There's no context about prerequisites, such as authentication needs or rate limits, leaving the agent with no usage differentiation.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/Arindam200/reddit-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server