Skip to main content
Glama

get_comment_by_id

Retrieve detailed information and replies for a specific Reddit comment using its unique ID, enabling focused analysis or response generation.

Instructions

Retrieve a specific comment by ID. Args: comment_id: ID of the comment to retrieve Returns: Comment details with any replies

Input Schema

NameRequiredDescriptionDefault
comment_idYes

Input Schema (JSON Schema)

{ "properties": { "comment_id": { "title": "Comment Id", "type": "string" } }, "required": [ "comment_id" ], "title": "get_comment_by_idArguments", "type": "object" }

Implementation Reference

  • The handler function that retrieves a specific Reddit comment by its ID using the RedditClient and converts it to a CommentResult model.
    @validate_call(validate_return=True) def get_comment_by_id(comment_id: str) -> CommentResult: """ Retrieve a specific comment by ID. Args: comment_id: ID of the comment to retrieve Returns: Comment details with any replies """ client = RedditClient.get_instance() return comment_to_model(client.reddit.comment(comment_id))
  • Pydantic BaseModel defining the output schema for the comment data, including nested replies.
    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
  • Registers the get_comment_by_id function in the tools list for MCP tool discovery.
    tools = [ get_submission, get_subreddit, get_comments_by_submission, get_comment_by_id, search_posts, search_subreddits, ]
  • Recursive helper function to convert PRAW comment objects (including replies) to the CommentResult Pydantic model.
    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 ], )

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