get_post_comments
Retrieve comments for Product Hunt posts using ID or slug, with sorting and pagination options to analyze user feedback.
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 |
|---|---|---|---|
| post_id | No | ||
| slug | No | ||
| order | No | ||
| count | No | ||
| after | No |
Implementation Reference
- Handler function that executes the get_post_comments tool logic, fetching comments via GraphQL with pagination and validation.@require_token @handle_errors @validate_with_schema(POST_COMMENTS_SCHEMA) 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, )
- Input validation schema defining parameters and constraints for the get_post_comments tool.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/cli.py:36-36 (registration)Registration point where register_comment_tools is called on the MCP server instance to register the get_post_comments tool among others.register_comment_tools(mcp)
- src/product_hunt_mcp/tools/comments.py:24-27 (registration)The register_comment_tools function that defines and registers both get_comment and get_post_comments tools using @mcp.tool() decorators.def register_comment_tools(mcp): """Register comment-related tools with the MCP server.""" @mcp.tool()