check_server_status
Verify the Product Hunt MCP server's operational status and authentication, returning server readiness, user details, and rate limit information.
Instructions
Check the status of the Product Hunt MCP server and authentication.
Returns:
- status (str): "Ready", "Not initialized", "Token invalid", or "Error".
- authenticated (bool, optional): True if authenticated, False otherwise.
- user (dict, optional): User details if authenticated.
- rate_limits (dict, optional): API rate limit information.
- message (str, optional): Additional status or error message.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- The handler function that implements the check_server_status tool. It verifies the authentication token, executes a GraphQL viewer query to check API connectivity, handles errors, and returns a status dictionary with details like status, authenticated flag, user info, and rate limits.def check_server_status() -> Dict[str, Any]: """ Check the status of the Product Hunt MCP server and authentication. Returns: - status (str): "Ready", "Not initialized", "Token invalid", or "Error". - authenticated (bool, optional): True if authenticated, False otherwise. - user (dict, optional): User details if authenticated. - rate_limits (dict, optional): API rate limit information. - message (str, optional): Additional status or error message. """ logger.info("server.check_server_status called") # 1. Check if token exists token_error = check_token() # Uses relative import from ..utils.token if token_error: # Use format_response for consistency, but keep specific status/message response = format_response(False, error=token_error) response["status"] = "Not initialized" response["message"] = token_error["message"] return response # 2. Try a simple query to check if token is valid try: # Uses relative imports from ..api.client and ..api.queries result, rate_limits, error = execute_graphql_query(VIEWER_QUERY) if error: response = format_response(False, error=error, rate_limits=rate_limits) response["status"] = "Error" response["message"] = f"Unable to authenticate with Product Hunt API: {error.get('message', 'Unknown error')}" return response # Check if viewer data is present (indicates successful auth) from ..utils.common import check_data_exists # Local import to avoid circular dependency at module level is_valid = check_data_exists(result.get("data", {}), "viewer") viewer_data = result.get("data", {}).get("viewer") if is_valid else None response = format_response(True, data=viewer_data, rate_limits=rate_limits) response["status"] = "Ready" if is_valid else "Token invalid" response["authenticated"] = is_valid if not is_valid: response["message"] = "Authentication successful, but no viewer data returned." if viewer_data and "user" in viewer_data: # Handle nested user structure if present response["user"] = viewer_data["user"] elif viewer_data: response["user"] = viewer_data # Assume viewer is the user object return response except Exception as e: logger.error(f"Unexpected error in check_server_status: {str(e)}", exc_info=True) response = format_response(False, error={"code": "INTERNAL_ERROR", "message": str(e)}) response["status"] = "Error" response["message"] = f"Unexpected error checking API connection: {str(e)}" return response
- src/product_hunt_mcp/tools/server.py:16-77 (registration)The registration function for server tools, which uses the @mcp.tool() decorator to register the check_server_status handler with the MCP server instance.def register_server_tools(mcp): """Register server-related tools with the MCP server.""" @mcp.tool() # No @handle_errors here as we want to return specific status messages def check_server_status() -> Dict[str, Any]: """ Check the status of the Product Hunt MCP server and authentication. Returns: - status (str): "Ready", "Not initialized", "Token invalid", or "Error". - authenticated (bool, optional): True if authenticated, False otherwise. - user (dict, optional): User details if authenticated. - rate_limits (dict, optional): API rate limit information. - message (str, optional): Additional status or error message. """ logger.info("server.check_server_status called") # 1. Check if token exists token_error = check_token() # Uses relative import from ..utils.token if token_error: # Use format_response for consistency, but keep specific status/message response = format_response(False, error=token_error) response["status"] = "Not initialized" response["message"] = token_error["message"] return response # 2. Try a simple query to check if token is valid try: # Uses relative imports from ..api.client and ..api.queries result, rate_limits, error = execute_graphql_query(VIEWER_QUERY) if error: response = format_response(False, error=error, rate_limits=rate_limits) response["status"] = "Error" response["message"] = f"Unable to authenticate with Product Hunt API: {error.get('message', 'Unknown error')}" return response # Check if viewer data is present (indicates successful auth) from ..utils.common import check_data_exists # Local import to avoid circular dependency at module level is_valid = check_data_exists(result.get("data", {}), "viewer") viewer_data = result.get("data", {}).get("viewer") if is_valid else None response = format_response(True, data=viewer_data, rate_limits=rate_limits) response["status"] = "Ready" if is_valid else "Token invalid" response["authenticated"] = is_valid if not is_valid: response["message"] = "Authentication successful, but no viewer data returned." if viewer_data and "user" in viewer_data: # Handle nested user structure if present response["user"] = viewer_data["user"] elif viewer_data: response["user"] = viewer_data # Assume viewer is the user object return response except Exception as e: logger.error(f"Unexpected error in check_server_status: {str(e)}", exc_info=True) response = format_response(False, error={"code": "INTERNAL_ERROR", "message": str(e)}) response["status"] = "Error" response["message"] = f"Unexpected error checking API connection: {str(e)}" return response
- src/product_hunt_mcp/cli.py:34-34 (registration)Invocation of the server tools registration in the main CLI entrypoint, adding the check_server_status tool to the FastMCP server.register_server_tools(mcp)
- Docstring defining the expected input (none) and output schema/format of the check_server_status tool.""" Check the status of the Product Hunt MCP server and authentication. Returns: - status (str): "Ready", "Not initialized", "Token invalid", or "Error". - authenticated (bool, optional): True if authenticated, False otherwise. - user (dict, optional): User details if authenticated. - rate_limits (dict, optional): API rate limit information. - message (str, optional): Additional status or error message. """