get_post_comments
Retrieve comments for a specific post using its ID or slug, with options for sorting by date or votes and pagination. Max 20 comments per request.
Instructions
Retrieve comments for a specific post by post ID or slug, with optional sorting and pagination.
Parameters:
- post_id (str, optional): The post's unique ID.
- slug (str, optional): The post's slug.
- order (str, optional): Sorting order. Valid values: NEWEST (default), OLDEST, VOTES.
- count (int, optional): Number of comments to return (default: 10, max: 20).
- after (str, optional): Pagination cursor for next page.
Returns:
- success (bool)
- data (dict): If successful, contains:
- comments (list): List of comment objects (id, content, etc.)
- pagination (dict): { end_cursor, has_next_page }
- error (dict, optional)
- rate_limits (dict)
Notes:
- Returns an error if the post is not found.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| after | No | ||
| count | No | ||
| order | No | ||
| post_id | No | ||
| slug | No |
Implementation Reference
- The main implementation of the get_post_comments tool, which retrieves paginated comments for a Product Hunt post using GraphQL query COMMENTS_QUERY, handles pagination, ordering, and validation.def get_post_comments( post_id: str = None, slug: str = None, order: str = None, count: int = None, after: str = None, ) -> Dict[str, Any]: """ Retrieve comments for a specific post by post ID or slug, with optional sorting and pagination. Parameters: - post_id (str, optional): The post's unique ID. - slug (str, optional): The post's slug. - order (str, optional): Sorting order. Valid values: NEWEST (default), OLDEST, VOTES. - count (int, optional): Number of comments to return (default: 10, max: 20). - after (str, optional): Pagination cursor for next page. Returns: - success (bool) - data (dict): If successful, contains: - comments (list): List of comment objects (id, content, etc.) - pagination (dict): { end_cursor, has_next_page } - error (dict, optional) - rate_limits (dict) Notes: - Returns an error if the post is not found. """ params = { k: v for k, v in { "post_id": post_id, "slug": slug, "order": order, "count": count, "after": after, }.items() if v is not None } logger.info("comments.get_post_comments called", extra=params) variables = {} # Prepare variables if post_id: variables["id"] = post_id if slug: variables["slug"] = slug # Apply pagination defaults pagination_vars = apply_pagination_defaults(count, after) variables.update(pagination_vars) # Apply order if order: variables["order"] = order result, rate_limits, error = execute_graphql_query(COMMENTS_QUERY, variables) if error: return format_response(False, error=error, rate_limits=rate_limits) # Check if post exists based on comments data post_exists = check_data_exists(result["data"], "post") if not post_exists: id_or_slug = post_id or slug return format_response( False, error={ "code": "NOT_FOUND", "message": f"Post with ID/slug '{id_or_slug}' not found", }, rate_limits=rate_limits, ) # Extract comments comments_data = result["data"]["post"]["comments"] return format_response( True, data={ "comments": comments_data["edges"], "pagination": extract_pagination(comments_data["pageInfo"]), }, rate_limits=rate_limits, )
- POST_COMMENTS_SCHEMA defining validation rules for input parameters: requires post_id or slug, order (NEWEST/OLDEST/TOP), count (1-20), after cursor.POST_COMMENTS_SCHEMA = { "requires_one_of": [["post_id", "slug"]], "post_id": {"type": str}, "slug": {"type": str}, "order": {"type": str, "valid_values": ["NEWEST", "OLDEST", "TOP"]}, "count": {"type": int, "min_value": 1, "max_value": 20}, "after": {"type": str}, }
- src/product_hunt_mcp/tools/comments.py:60-64 (registration)@mcp.tool() decorator and other decorators registering the get_post_comments function as an MCP tool.@mcp.tool() @require_token @handle_errors @validate_with_schema(POST_COMMENTS_SCHEMA) def get_post_comments(
- src/product_hunt_mcp/cli.py:36-36 (registration)Call to register_comment_tools(mcp) which registers the comment tools including get_post_comments.register_comment_tools(mcp)