get_collection
Fetch detailed information about a specific Product Hunt collection using its ID or slug. Retrieve data including name, description, follower count, and posts.
Instructions
Retrieve detailed information about a specific collection by ID or slug.
Parameters:
- id (str, optional): The collection's unique ID.
- slug (str, optional): The collection's slug (e.g., "best-productivity-apps").
At least one of `id` or `slug` must be provided.
Returns:
- success (bool)
- data (dict): If successful, contains collection 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 collection is not found.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | No | ||
| slug | No |
Implementation Reference
- The get_collection tool handler function, including decorators for registration (@mcp.tool()), authentication (@require_token), error handling (@handle_errors), and input validation (@validate_with_schema). This is the core implementation that executes the GraphQL query for a collection.@mcp.tool() @require_token @handle_errors @validate_with_schema(COLLECTION_SCHEMA) def get_collection(id: str = None, slug: str = None) -> Dict[str, Any]: """ Retrieve detailed information about a specific collection by ID or slug. Parameters: - id (str, optional): The collection's unique ID. - slug (str, optional): The collection's slug (e.g., "best-productivity-apps"). At least one of `id` or `slug` must be provided. Returns: - success (bool) - data (dict): If successful, contains collection 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 collection is not found. """ params = {k: v for k, v in {"id": id, "slug": slug}.items() if v is not None} logger.info("collections.get_collection called", extra=params) variables = {} add_id_or_slug(variables, id, slug) # Execute the query and check if collection exists id_or_slug = id or slug collection_data, rate_limits, error = execute_and_check_query( COLLECTION_QUERY, variables, "collection", id_or_slug ) if error: return format_response(False, error=error, rate_limits=rate_limits) return format_response(True, data=collection_data, rate_limits=rate_limits)
- COLLECTION_SCHEMA defines the input validation rules for the get_collection tool, requiring either 'id' or 'slug'.COLLECTION_SCHEMA = { "requires_one_of": [["id", "slug"]], "id": {"type": str}, "slug": {"type": str}, }
- src/product_hunt_mcp/cli.py:37-37 (registration)Invocation of register_collection_tools(mcp), which contains the definition and @mcp.tool() registration of the get_collection handler.register_collection_tools(mcp)