Skip to main content
Glama
jaipandya

product-hunt-mcp

by jaipandya

get_user

Retrieve user information from Product Hunt by ID or username, with options to fetch their posts for comprehensive profile analysis.

Instructions

    Retrieve user information by ID or username, with optional retrieval of their posts.

    Parameters:
    - id (str, optional): The user's unique ID.
    - username (str, optional): The user's username.
    - posts_type (str, optional): Type of posts to retrieve. Valid values: MADE (default), VOTED.
    - posts_count (int, optional): Number of posts to return (default: 10, max: 20).
    - posts_after (str, optional): Pagination cursor for next page of posts.

    At least one of `id` or `username` must be provided.

    Returns:
    - success (bool)
    - data (dict): If successful, contains user details and optionally their posts.
    - error (dict, optional)
    - rate_limits (dict)

    Notes:
    - Returns an error if neither `id` nor `username` is provided, or if the user is not found.
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idNo
usernameNo
posts_typeNo
posts_countNo
posts_afterNo

Implementation Reference

  • Core handler function for 'get_user' tool. Decorated for registration, auth, error handling, and schema validation. Fetches user by ID/username, optionally posts, via GraphQL.
    @mcp.tool()
    @require_token
    @handle_errors
    @validate_with_schema(USER_SCHEMA)
    def get_user(
        id: str = None,
        username: str = None,
        posts_type: str = None,
        posts_count: int = None,
        posts_after: str = None,
    ) -> Dict[str, Any]:
        """
        Retrieve user information by ID or username, with optional retrieval of their posts.
    
        Parameters:
        - id (str, optional): The user's unique ID.
        - username (str, optional): The user's username.
        - posts_type (str, optional): Type of posts to retrieve. Valid values: MADE (default), VOTED.
        - posts_count (int, optional): Number of posts to return (default: 10, max: 20).
        - posts_after (str, optional): Pagination cursor for next page of posts.
    
        At least one of `id` or `username` must be provided.
    
        Returns:
        - success (bool)
        - data (dict): If successful, contains user details and optionally their posts.
        - error (dict, optional)
        - rate_limits (dict)
    
        Notes:
        - Returns an error if neither `id` nor `username` is provided, or if the user is not found.
        """
        params = {
            k: v
            for k, v in {
                "id": id,
                "username": username,
                "posts_type": posts_type,
                "posts_count": posts_count,
                "posts_after": posts_after,
            }.items()
            if v is not None
        }
        logger.info("users.get_user called", extra=params)
    
        # Determine if posts are being requested
        requesting_posts = posts_type is not None or posts_count is not None
    
        # Apply sensible defaults if posts are being requested
        if requesting_posts:
            posts_type = posts_type or "MADE"
            posts_count = posts_count or 10
        else:
            posts_type = None
            posts_count = None
    
        # Set up common variables
        variables = {}
        if id:
            variables["id"] = id
        if username:
            variables["username"] = username
    
        # Normalize posts_type
        posts_type = posts_type.upper() if posts_type else None
    
        # Case 1: Basic user info (no posts requested)
        if not requesting_posts:
            result, rate_limits, error = execute_graphql_query(USER_QUERY, variables)
            if error:
                return format_response(False, error=error, rate_limits=rate_limits)
            if not check_data_exists(result["data"], "user"):
                id_or_username = id or username
                return format_response(
                    False,
                    error={
                        "code": "NOT_FOUND",
                        "message": f"User with ID/username '{id_or_username}' not found",
                    },
                    rate_limits=rate_limits,
                )
            return format_response(True, data=result["data"]["user"], rate_limits=rate_limits)
    
        # Case 2 & 3: Posts requested (made or voted)
        # Set up pagination
        pagination = apply_pagination_defaults(posts_count, posts_after)
        variables.update(pagination)
    
        # Choose query based on posts_type
        if posts_type == "MADE":
            query = USER_POSTS_QUERY
        elif posts_type == "VOTED":
            query = USER_VOTED_POSTS_QUERY
        else:
            return format_response(
                False,
                error={
                    "code": "INVALID_PARAMETER",
                    "message": f"Invalid posts_type: {posts_type}. Valid values are MADE, VOTED.",
                },
            )
    
        # Execute the appropriate query
        result, rate_limits, error = execute_graphql_query(query, variables)
        if error:
            return format_response(False, error=error, rate_limits=rate_limits)
        if not check_data_exists(result["data"], "user"):
            id_or_username = id or username
            return format_response(
                False,
                error={
                    "code": "NOT_FOUND",
                    "message": f"User with ID/username '{id_or_username}' not found",
                },
                rate_limits=rate_limits,
            )
        user_data = result["data"]["user"]
        # Format response based on the query type
        if posts_type == "MADE" and check_data_exists(user_data, "madePosts"):
            posts_data = user_data["madePosts"]
            response_data = {
                "id": user_data["id"],
                "posts": posts_data
            }
            return format_response(True, data=response_data, rate_limits=rate_limits)
        elif posts_type == "VOTED" and check_data_exists(user_data, "votedPosts"):
            posts_data = user_data["votedPosts"]
            response_data = {
                "id": user_data["id"],
                "posts": posts_data
            }
            return format_response(True, data=response_data, rate_limits=rate_limits)
        # If we get here, the posts field wasn't in the response, just return what we have
        return format_response(True, data=user_data, rate_limits=rate_limits)
  • Input validation schema for the get_user tool parameters.
    USER_SCHEMA = {
        "requires_one_of": [["id", "username"]],
        "id": {"type": str},
        "username": {"type": str},
        "posts_type": {"type": str, "valid_values": ["MADE", "VOTED"]},
        "posts_count": {"type": int, "min_value": 1, "max_value": 20},
        "posts_after": {"type": str},
    }
  • Registers the user tools, including get_user, with the MCP server instance in the main CLI entry point.
    register_user_tools(mcp)

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