File size: 2,755 Bytes
a27d846
 
 
 
 
 
 
b150712
a27d846
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b150712
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a499d04
 
 
b150712
 
a499d04
 
 
a27d846
 
 
 
 
 
 
 
a499d04
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
"""
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 = "<your-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()