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
            ],
        )
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions retrieving comments and replacing MoreComments objects, but doesn't cover important aspects like authentication requirements, rate limits, error conditions, pagination, or what happens when submission_id is invalid. The behavioral context is incomplete.

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 well-structured with clear sections for Args and Returns. It's appropriately sized with no redundant information. Every sentence serves a purpose, though it could be slightly more front-loaded with the core purpose.

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

Completeness3/5

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

For a retrieval tool with 2 parameters, 0% schema coverage, no annotations, and no output schema, the description provides adequate basic information but lacks depth. It explains what the tool does and its parameters but doesn't cover behavioral aspects, error handling, or relationship to sibling tools, leaving gaps in contextual understanding.

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

Parameters4/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 both parameters: 'submission_id' identifies the target submission, and 'replace_more' controls whether MoreComments objects are replaced with actual comments. This adds meaningful context beyond the bare schema.

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 verb 'Retrieve' and resource 'comments from a specific submission', making the purpose unambiguous. However, it doesn't differentiate from sibling tools like 'get_comment_by_id' or explain how this differs from general comment retrieval methods.

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 like 'get_comment_by_id' or 'search_posts'. It mentions retrieving comments from a specific submission but doesn't clarify use cases, prerequisites, or exclusions.

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

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

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