Skip to main content
Glama

get_comments_by_submission

Extract and analyze comments from a Reddit submission using the submission ID, optionally replacing MoreComments with detailed replies for comprehensive insights.

Instructions

Retrieve comments from a specific submission.

Args:
    submission_id: ID of the submission to get comments from
    replace_more: Whether to replace MoreComments objects with actual comments

Returns:
    List of comments with their replies

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
replace_moreNo
submission_idYes

Implementation Reference

  • The main handler function implementing the tool logic to fetch comments from a Reddit submission, process them recursively, and return structured data.
    @validate_call(validate_return=True)
    def get_comments_by_submission(
        submission_id: str, replace_more: bool = True
    ) -> List[CommentResult]:
        """
        Retrieve comments from a specific submission.
    
        Args:
            submission_id: ID of the submission to get comments from
            replace_more: Whether to replace MoreComments objects with actual comments
    
        Returns:
            List of comments with their replies
        """
        client = RedditClient.get_instance()
        submission = client.reddit.submission(submission_id)
        if replace_more:
            submission.comments.replace_more()
        return [
            result
            for comment in submission.comments.list()
            if (result := comment_to_model(comment)) is not None
        ]
  • Pydantic BaseModel defining the schema for comment data, including nested replies, used for validation and typing.
    class CommentResult(BaseModel):
        """Reddit comment details"""
    
        id: str = Field(description="Unique identifier of the comment")
        body: str = Field(description="Text content of the comment")
        author: str | None = Field(description="Username of the author, or None if deleted")
        created_utc: str = Field(description="UTC timestamp when comment was created")
        is_submitter: bool = Field(
            description="Whether the comment author is the submission author"
        )
        score: int = Field(description="Number of upvotes minus downvotes")
        replies: List["CommentResult"] = Field(
            description="List of reply comments", default_factory=list
        )
    
    
    CommentResult.model_rebuild()  # Required for self-referential models
  • Registry list exporting the get_comments_by_submission tool function for use by the MCP server.
    # Registry of all available tools
    tools = [
        get_submission,
        get_subreddit,
        get_comments_by_submission,
        get_comment_by_id,
        search_posts,
        search_subreddits,
    ]
  • MCP server code that iterates over the tools list and registers each tool with the FastMCP server instance.
    for tool in tools:
        logger.info(f"Registering tool: {tool.__name__}")
        mcp.tool()(tool)
  • Recursive helper utility to convert PRAW Reddit comment objects into CommentResult models, handling nested replies and skipping placeholders.
    def comment_to_model(comment) -> CommentResult:
        """Convert PRAW comment object to CommentResult model."""
        # Skip MoreComments objects
        if isinstance(comment, MoreComments):
            return None
    
        return CommentResult(
            id=comment.id,
            body=comment.body,
            author=None if comment.author is None else comment.author.name,
            created_utc=format_utc_timestamp(comment.created_utc),
            is_submitter=comment.is_submitter,
            score=comment.score,
            replies=[
                result
                for reply in comment.replies
                if (result := comment_to_model(reply)) is not None
            ],
        )

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

A3.8/5.0
Behavior3/5

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

Without annotations, the description bears full burden. It correctly suggests a read-only operation ('Retrieve comments') and indicates the return type ('list of comments with their replies'). However, it does not disclose specific behaviors such as how depth of replies is handled, whether there are rate limits, or the effect of replace_more beyond a brief sentence.

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

Conciseness4/5

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

The description is concise with separate Args and Returns sections, making it easy to scan. The first sentence immediately conveys the tool's core function. However, it could be more front-loaded by placing the core purpose before the argument list.

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?

For a tool with 2 parameters and a simple read operation, the description covers essential aspects: purpose, parameter meanings, and return type. It lacks details on pagination, ordering, or limitations of the comment list, but the moderate complexity justifies a score of 4 rather than 5.

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?

Schema description coverage is 0%, so the description must compensate. It clearly explains each parameter: submission_id as 'ID of the submission' and replace_more as 'Whether to replace MoreComments objects with actual comments'. This adds meaningful context beyond the schema, which only provides type and default.

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

Purpose5/5

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

The description explicitly states 'Retrieve comments from a specific submission', clearly identifying the verb (retrieve) and resource (comments from a submission). This distinguishes it from sibling tools like get_comment_by_id (single comment) and get_submission (submission details).

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?

No guidance is provided on when to use this tool versus its siblings (e.g., get_comment_by_id for a single comment, search_posts for broader search). The description also lacks advice on when to set replace_more to true vs false, leaving the agent to infer usage from the parameter name alone.

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

Deploy Server

Other Tools

Related Tools