get_viewer
Retrieve information about the currently authenticated user, including user details and authentication status.
Instructions
Retrieve information about the currently authenticated user.
Parameters:
- None
Returns:
- success (bool)
- data (dict): If successful, contains user details.
- error (dict, optional)
- rate_limits (dict)
Notes:
- Returns an error if the token is invalid or expired.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- The handler function for the 'get_viewer' tool. It is decorated with @mcp.tool() for registration, requires a token, handles errors, executes a GraphQL query to fetch viewer data, and formats the response.@require_token @handle_errors def get_viewer() -> Dict[str, Any]: """ Retrieve information about the currently authenticated user. Parameters: - None Returns: - success (bool) - data (dict): If successful, contains user details. - error (dict, optional) - rate_limits (dict) Notes: - Returns an error if the token is invalid or expired. """ logger.info("users.get_viewer called") result, rate_limits, error = execute_graphql_query(VIEWER_QUERY) if error: return format_response(False, error=error, rate_limits=rate_limits) # Check if viewer info exists viewer_exists = check_data_exists(result["data"], "viewer") if not viewer_exists: return format_response( False, error={ "code": "AUTHENTICATION_ERROR", "message": "Unable to get viewer information. Token may be invalid or expired.", }, rate_limits=rate_limits, ) # Extract viewer data viewer_data = result["data"]["viewer"] # Check if the user field exists for nested viewer structure if "user" in viewer_data and viewer_data["user"] is not None: viewer_data = viewer_data["user"] return format_response(True, data=viewer_data, rate_limits=rate_limits)
- src/product_hunt_mcp/cli.py:39-39 (registration)The call to register_user_tools(mcp) in the main CLI entry point, which defines and registers the get_viewer tool among other user tools.register_user_tools(mcp)