""" Universal MCP Client - Main Application A modular Gradio chatbot that uses HuggingFace Inference Providers to access OpenAI GPT OSS models and can connect to various MCP servers for enhanced functionality. """ import logging import os import socket from config import AppConfig from mcp_client import UniversalMCPClient from ui_components import UIComponents # Set up logging logger = logging.getLogger(__name__) def main(): """Main application entry point""" logger.info("🚀 Starting Universal MCP Client with HuggingFace Inference Providers...") try: # Check for HuggingFace token if not AppConfig.HF_TOKEN: logger.warning("⚠️ No HF_TOKEN found in environment variables") logger.info("💡 Users will need to login manually or set HF_TOKEN") else: logger.info("✅ HF_TOKEN found in environment") # Initialize the MCP client mcp_client = UniversalMCPClient() # Create UI components ui_components = UIComponents(mcp_client) # Create the Gradio interface demo = ui_components.create_interface() # Launch the application # Prefer localhost by default. Allow override via env GRADIO_SERVER_NAME or AppConfig.GRADIO_SERVER_NAME server_name = os.getenv("GRADIO_SERVER_NAME", getattr(AppConfig, "GRADIO_SERVER_NAME", "localhost")) server_port = int(os.getenv("GRADIO_SERVER_PORT", str(getattr(AppConfig, "GRADIO_SERVER_PORT", 7860)))) # Log a friendly URL for quick access if server_name in ("0.0.0.0", "::"): local_url = f"http://localhost:{server_port}" try: host_ip = socket.gethostbyname(socket.gethostname()) except Exception: host_ip = "" lan_url = f"http://{host_ip}:{server_port}" logger.info(f"🔗 Local URL: {local_url}") logger.info(f"🔗 Network URL: {lan_url}") else: logger.info(f"🔗 URL: http://{server_name}:{server_port}") demo.launch( debug=AppConfig.DEBUG_MODE, share=False, # Set to True if you want to create a public link server_name=server_name, # Default to localhost; can be set to 0.0.0.0 if needed server_port=server_port, # Default Gradio port auth=None, # No authentication (handled by HF login) max_threads=40 # Allow multiple concurrent users ) logger.info("✅ Universal MCP Client started successfully!") except Exception as e: logger.error(f"❌ Failed to start application: {e}") raise if __name__ == "__main__": main()