124 lines
3.6 KiB
Python
124 lines
3.6 KiB
Python
"""Main entry point for FLUX.1 Edit MCP Server"""
|
|
|
|
import asyncio
|
|
import logging
|
|
import sys
|
|
import traceback
|
|
from pathlib import Path
|
|
|
|
# Add src to path for imports
|
|
sys.path.insert(0, str(Path(__file__).parent / 'src'))
|
|
|
|
|
|
def setup_logging():
|
|
"""Setup logging configuration"""
|
|
# Only log to file, not stdout to avoid JSON parsing issues
|
|
logging.basicConfig(
|
|
level=logging.INFO,
|
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
|
handlers=[
|
|
logging.FileHandler('flux1-edit.log', mode='a', encoding='utf-8')
|
|
]
|
|
)
|
|
|
|
# Set specific loggers
|
|
logging.getLogger('aiohttp').setLevel(logging.WARNING)
|
|
logging.getLogger('PIL').setLevel(logging.WARNING)
|
|
|
|
|
|
def check_dependencies():
|
|
"""Check if all required dependencies are available - silently check for MCP compatibility"""
|
|
missing_deps = []
|
|
|
|
try:
|
|
import aiohttp
|
|
# Silent check - no print to avoid JSON parsing issues
|
|
except ImportError as e:
|
|
missing_deps.append(f"aiohttp: {e}")
|
|
|
|
try:
|
|
import httpx
|
|
# Silent check - no print to avoid JSON parsing issues
|
|
except ImportError as e:
|
|
missing_deps.append(f"httpx: {e}")
|
|
|
|
try:
|
|
import mcp
|
|
# Silent check - no print to avoid JSON parsing issues
|
|
except ImportError as e:
|
|
missing_deps.append(f"mcp: {e}")
|
|
|
|
try:
|
|
from PIL import Image
|
|
# Silent check - no print to avoid JSON parsing issues
|
|
except ImportError as e:
|
|
missing_deps.append(f"Pillow: {e}")
|
|
|
|
try:
|
|
import dotenv
|
|
# Silent check - no print to avoid JSON parsing issues
|
|
except ImportError as e:
|
|
missing_deps.append(f"python-dotenv: {e}")
|
|
|
|
try:
|
|
import pydantic
|
|
# Silent check - no print to avoid JSON parsing issues
|
|
except ImportError as e:
|
|
missing_deps.append(f"pydantic: {e}")
|
|
|
|
if missing_deps:
|
|
# Log to file instead of print to avoid JSON parsing issues
|
|
logger = logging.getLogger(__name__)
|
|
logger.error(f"Missing dependencies: {missing_deps}")
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
def check_local_imports():
|
|
"""Check if local modules can be imported - silently check for MCP compatibility"""
|
|
logger = logging.getLogger(__name__)
|
|
|
|
try:
|
|
from src.connector import Config
|
|
# Silent check - no print to avoid JSON parsing issues
|
|
except ImportError as e:
|
|
logger.error(f"Failed to import local Config: {e}")
|
|
return False
|
|
|
|
try:
|
|
from src.server import main
|
|
# Silent check - no print to avoid JSON parsing issues
|
|
return True
|
|
except ImportError as e:
|
|
logger.error(f"Failed to import local server main: {e}", exc_info=True)
|
|
return False
|
|
|
|
|
|
if __name__ == "__main__":
|
|
setup_logging()
|
|
logger = logging.getLogger(__name__)
|
|
|
|
# Check dependencies first - silently for MCP compatibility
|
|
if not check_dependencies():
|
|
logger.error("Dependencies check failed")
|
|
sys.exit(1)
|
|
|
|
# Check local imports - silently for MCP compatibility
|
|
if not check_local_imports():
|
|
logger.error("Local imports check failed")
|
|
sys.exit(1)
|
|
|
|
# Start the MCP server without console output to avoid JSON parsing issues
|
|
try:
|
|
# Import main function after checks
|
|
from src.server import main
|
|
logger.info("Starting FLUX.1 Edit MCP Server...")
|
|
asyncio.run(main())
|
|
except KeyboardInterrupt:
|
|
logger.info("Server stopped by user")
|
|
sys.exit(0)
|
|
except Exception as e:
|
|
logger.error(f"Server error: {e}", exc_info=True)
|
|
sys.exit(1)
|