get_topic
Retrieve detailed information about a specific topic using its ID or slug. Returns topic data including name, description, follower count, and posts. Requires either topic ID or slug for successful operation.
Instructions
Retrieve detailed information about a specific topic by ID or slug.
Parameters:
- id (str, optional): The topic's unique ID.
- slug (str, optional): The topic's slug (e.g., "artificial-intelligence").
At least one of `id` or `slug` must be provided.
Returns:
- success (bool)
- data (dict): If successful, contains topic details:
- id, name, description, follower_count, posts, etc.
- error (dict, optional)
- rate_limits (dict)
Notes:
- Returns an error if neither `id` nor `slug` is provided, or if the topic is not found.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | No | ||
| slug | No |
Implementation Reference
- The core handler function for the 'get_topic' tool. It validates input, executes a GraphQL query using TOPIC_QUERY to fetch topic details by ID or slug, handles errors, and formats the response.def get_topic(id: str = None, slug: str = None) -> Dict[str, Any]: """ Retrieve detailed information about a specific topic by ID or slug. Parameters: - id (str, optional): The topic's unique ID. - slug (str, optional): The topic's slug (e.g., "artificial-intelligence"). At least one of `id` or `slug` must be provided. Returns: - success (bool) - data (dict): If successful, contains topic details: - id, name, description, follower_count, posts, etc. - error (dict, optional) - rate_limits (dict) Notes: - Returns an error if neither `id` nor `slug` is provided, or if the topic is not found. """ params = {k: v for k, v in {"id": id, "slug": slug}.items() if v is not None} logger.info("topics.get_topic called", extra=params) variables = {} add_id_or_slug(variables, id, slug) # Execute the query and check if topic exists id_or_slug = id or slug topic_data, rate_limits, error = execute_and_check_query( TOPIC_QUERY, variables, "topic", id_or_slug ) if error: return format_response(False, error=error, rate_limits=rate_limits) return format_response(True, data=topic_data, rate_limits=rate_limits)
- Input validation schema for the get_topic tool, ensuring at least one of 'id' or 'slug' is provided, both as strings.TOPIC_SCHEMA = {"requires_one_of": [["id", "slug"]], "id": {"type": str}, "slug": {"type": str}}
- src/product_hunt_mcp/tools/topics.py:27-30 (registration)Registration of the get_topic tool using the @mcp.tool() decorator, along with additional decorators for authentication, error handling, and schema validation.@mcp.tool() @require_token @handle_errors @validate_with_schema(TOPIC_SCHEMA)
- src/product_hunt_mcp/cli.py:38-38 (registration)Invocation of register_topic_tools(mcp) in the main CLI entry point, which registers the get_topic tool among others.register_topic_tools(mcp)