search_topics
Find topics on Product Hunt by name, filter by user following, and sort results with pagination support.
Instructions
Search for topics by name or filter by user following, with optional sorting and pagination.
Parameters:
- query (str, optional): Search term to find topics by name.
- followed_by_user_id (str, optional): Only topics followed by this user ID.
- order (str, optional): Sorting order. Valid values: FOLLOWERS_COUNT (default), NAME, NEWEST.
- count (int, optional): Number of topics to return (default: 10, max: 20).
- after (str, optional): Pagination cursor for next page.
Returns:
- success (bool)
- data (dict): If successful, contains:
- topics (list): List of topic objects (id, name, etc.)
- pagination (dict): { end_cursor, has_next_page }
- error (dict, optional)
- rate_limits (dict)
Notes:
- If no topics match, `topics` will be an empty list.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | No | ||
| followed_by_user_id | No | ||
| order | No | FOLLOWERS_COUNT | |
| count | No | ||
| after | No |
Implementation Reference
- The core handler function for the 'search_topics' tool. It validates input, logs the call, constructs GraphQL variables, executes the TOPICS_QUERY, and formats the response with topics list and pagination.@mcp.tool() @require_token @handle_errors @validate_with_schema(TOPICS_SCHEMA) def search_topics( query: str = None, followed_by_user_id: str = None, order: str = "FOLLOWERS_COUNT", count: int = 10, after: str = None, ) -> Dict[str, Any]: """ Search for topics by name or filter by user following, with optional sorting and pagination. Parameters: - query (str, optional): Search term to find topics by name. - followed_by_user_id (str, optional): Only topics followed by this user ID. - order (str, optional): Sorting order. Valid values: FOLLOWERS_COUNT (default), NAME, NEWEST. - count (int, optional): Number of topics to return (default: 10, max: 20). - after (str, optional): Pagination cursor for next page. Returns: - success (bool) - data (dict): If successful, contains: - topics (list): List of topic objects (id, name, etc.) - pagination (dict): { end_cursor, has_next_page } - error (dict, optional) - rate_limits (dict) Notes: - If no topics match, `topics` will be an empty list. """ params = { k: v for k, v in { "query": query, "followed_by_user_id": followed_by_user_id, "order": order, "count": count, "after": after, }.items() if v is not None } logger.info("topics.search_topics called", extra=params) # Apply pagination defaults variables = apply_pagination_defaults(count, after) # Add order parameter variables["order"] = order # Add optional filters if query: variables["query"] = query if followed_by_user_id: variables["followedByUserId"] = followed_by_user_id result, rate_limits, error = execute_graphql_query(TOPICS_QUERY, variables) if error: return format_response(False, error=error, rate_limits=rate_limits) # Extract topics topics_data = result["data"]["topics"] return format_response( True, data={ "topics": topics_data["edges"], "pagination": extract_pagination(topics_data["pageInfo"]), }, rate_limits=rate_limits, )
- Validation schema used for input parameters of the search_topics tool, defining types and constraints for query, followed_by_user_id, order, count, and after.TOPICS_SCHEMA = { "query": {"type": str}, "followed_by_user_id": {"type": str}, "order": {"type": str, "valid_values": ["FOLLOWERS_COUNT", "NEWEST", "NAME"]}, "count": {"type": int, "min_value": 1, "max_value": 20}, "after": {"type": str}, }
- src/product_hunt_mcp/cli.py:38-38 (registration)Invocation of register_topic_tools(mcp) in the main CLI entry point, which defines and registers the search_topics tool among others.register_topic_tools(mcp)
- src/product_hunt_mcp/tools/topics.py:24-27 (registration)The registration function that contains the definition of the search_topics tool with @mcp.tool() decorator.def register_topic_tools(mcp): """Register topic-related tools with the MCP server.""" @mcp.tool()