diff --git a/main.py b/main.py index e6ac8a7..7150854 100644 --- a/main.py +++ b/main.py @@ -307,6 +307,30 @@ class FluxEditMCPServer: type="text", text=f"[ERROR] Tool execution error: {str(e)}" )] + + # Add cancellation notification handler + try: + # This handles request cancellations gracefully + @self.server.set_logging_level() + async def handle_set_logging_level(level: types.LoggingLevel): + """Handle logging level changes""" + try: + logger.info(f"Setting logging level to: {level}") + # Update logger level based on MCP level + if level == types.LoggingLevel.DEBUG: + logging.getLogger().setLevel(logging.DEBUG) + elif level == types.LoggingLevel.INFO: + logging.getLogger().setLevel(logging.INFO) + elif level == types.LoggingLevel.WARNING: + logging.getLogger().setLevel(logging.WARNING) + elif level == types.LoggingLevel.ERROR: + logging.getLogger().setLevel(logging.ERROR) + except Exception as e: + logger.error(f"Error setting logging level: {e}", exc_info=True) + + except AttributeError: + # If set_logging_level is not available, skip + logger.info("set_logging_level not available in this MCP version") async def run(self): """Run the MCP server""" @@ -316,7 +340,7 @@ class FluxEditMCPServer: logger.info(f"Input directory: {self.config.input_path}") logger.info(f"Output directory: {self.config.generated_images_path}") - # Run server using stdio with proper initialization + # Run server using stdio async with stdio_server() as (read_stream, write_stream): logger.info("MCP server started with stdio transport") diff --git a/requirements.txt b/requirements.txt index bbbed94..58ec809 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ # FLUX.1 Edit MCP Server Dependencies -# Core MCP Server -mcp==1.2.0 +# Core MCP Server - Updated to latest +mcp==1.13.1 # HTTP Client for FLUX API - using stable version aiohttp==3.9.5 @@ -12,8 +12,8 @@ Pillow==11.0.0 # Environment and Configuration python-dotenv==1.0.1 -# Data Validation -pydantic==2.10.3 +# Data Validation - Updated with MCP +pydantic==2.11.7 # Development and Testing pytest==8.3.4