Skip to main content
Glama
jaipandya

product-hunt-mcp

by jaipandya

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
NameRequiredDescriptionDefault
afterNo
countNo
orderNo
post_idNo
slugNo

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}, }
  • @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(
  • Call to register_comment_tools(mcp) which registers the comment tools including get_post_comments.
    register_comment_tools(mcp)

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/jaipandya/producthunt-mcp-server'

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