### ImageMCP Console Output Example Source: https://github.com/avidgamefan/imagemcp/blob/main/QUICK_START.md Example console output when the ImageMCP server starts and loads settings. ```text ====================================== ImageMCP MCP Server ====================================== Listening on: http://localhost:5243 ComfyUI: ws://127.0.0.1:8188 info: Startup[0] ComfyUI settings loaded: ApiEndpoint=ws://127.0.0.1:8188, DefaultTemplate=workflows/default_workflow.json info: Microsoft.Hosting.Lifetime[14] Now listening on: http://localhost:5243 info: Microsoft.Hosting.Lifetime[0] Application started. Press Ctrl+C to shut down. ``` -------------------------------- ### ComfyUI Installation and Setup Source: https://github.com/avidgamefan/imagemcp/blob/main/README.md Clone the ComfyUI repository, install Python dependencies, and download a Stable Diffusion model. Place the model in the 'ComfyUI/models/checkpoints/' directory. ```bash # Clone ComfyUI git clone https://github.com/comfyanonymous/ComfyUI.git cd ComfyUI # Install dependencies (Python 3.10+) pip install -r requirements.txt # Download a model (e.g., Stable Diffusion XL) # Place models in: ComfyUI/models/checkpoints/ # Example: sd_xl_base_1.0_0.9vae.safetensors ``` -------------------------------- ### Start ImageMCP Server Source: https://github.com/avidgamefan/imagemcp/blob/main/README.md Navigate to the ImageMCP directory and run the dotnet command to start the server. ```bash cd ImageMCP dotnet run ``` -------------------------------- ### Start ImageMCP Server on Linux Source: https://github.com/avidgamefan/imagemcp/blob/main/QUICK_START.md Starts the ImageMCP server on a Linux system. ```bash ./start-imagemcp.sh ``` -------------------------------- ### Start ComfyUI Source: https://github.com/avidgamefan/imagemcp/blob/main/QUICK_START.md Starts the ComfyUI application. Ensure this is running before starting ImageMCP. ```bash # Navigate to your ComfyUI directory cd C:\path\to\ComfyUI python main.py ``` -------------------------------- ### Image Generation Command Line Arguments Source: https://github.com/avidgamefan/imagemcp/blob/main/README.md Example of command-line arguments for starting the ImageMCP server with a specific workflow template and ComfyUI endpoint. ```bash dotnet run --template ./workflows/sdxl_basic.json --comfyui-endpoint ws://127.0.0.1:8188 ``` -------------------------------- ### Starting ComfyUI Source: https://github.com/avidgamefan/imagemcp/blob/main/README.md Run the ComfyUI Python script to start the server. The WebSocket API will be available at the specified address. ```bash # From ComfyUI directory python main.py # ComfyUI will start on: http://127.0.0.1:8188 # WebSocket available at: ws://127.0.0.1:8188/ws ``` -------------------------------- ### Start ImageMCP Server with Custom Workflow Source: https://github.com/avidgamefan/imagemcp/blob/main/README.md Use a custom workflow template and specify the ComfyUI endpoint when starting the server. ```bash dotnet run --template ./custom_workflow.json --comfyui-endpoint ws://192.168.1.100:8188 ``` -------------------------------- ### Start ImageMCP Server on Windows Source: https://github.com/avidgamefan/imagemcp/blob/main/QUICK_START.md Starts the ImageMCP server on Windows by double-clicking the batch file or running the executable. ```powershell . # Or from PowerShell: . ``` -------------------------------- ### Image Generation Console Output Example Source: https://github.com/avidgamefan/imagemcp/blob/main/QUICK_START.md Example console output during an AI image generation process initiated via LM Studio. ```text info: ImageGen[0] Template is already in API format, injecting prompts directly info: ImageGen[0] Submitting workflow with prompt: serene mountain landscape at sunset... info: ImageMCP.Services.ComfyUIClient[0] Workflow submitted successfully. Prompt ID: 628d6005-... info: ImageMCP.Services.ComfyUIClient[0] Workflow execution completed: 628d6005-... info: ImageMCP.Services.ComfyUIClient[0] Retrieved 1 images for prompt: 628d6005-... ``` -------------------------------- ### Extract ImageMCP on Linux Source: https://github.com/avidgamefan/imagemcp/blob/main/QUICK_START.md Extracts the ImageMCP server package on Linux and makes the start script executable. ```bash tar -xzf ImageMCP_server_linux.tar.gz cd imagemcp chmod +x start-imagemcp.sh ``` -------------------------------- ### Example Image Generation Output Log Source: https://github.com/avidgamefan/imagemcp/blob/main/README.md This log shows the typical output from ImageMCP when a user requests an image generation. It details the process from prompt submission to image retrieval. ```log info: ImageGen[0] Template is already in API format, injecting prompts directly info: ImageGen[0] Submitting workflow with prompt: serene mountain landscape at sunset with vibrant colors info: ImageMCP.Services.ComfyUIClient[0] Workflow submitted successfully. Prompt ID: 628d6005-8bee-4236-b15b-eefdd39efeb6 info: ImageMCP.Services.ComfyUIClient[0] Workflow execution completed: 628d6005-8bee-4236-b15b-eefdd39efeb6 info: ImageMCP.Services.ComfyUIClient[0] Retrieved 1 images for prompt: 628d6005-8bee-4236-b15b-eefdd39efeb6 ``` -------------------------------- ### Building ImageMCP Source: https://github.com/avidgamefan/imagemcp/blob/main/README.md Clone the ImageMCP repository, restore .NET dependencies, and build the project. Optional tests can be run using 'dotnet test'. ```bash # Clone this repository git clone cd ImageMCP # Restore dependencies donet restore # Build the project donet build # Run tests (optional) donet test ``` -------------------------------- ### Running ImageMCP Server Source: https://github.com/avidgamefan/imagemcp/blob/main/README.md Execute the ImageMCP project using the .NET CLI. Alternatively, use provided batch or shell scripts for Windows and Linux. ```bash dotnet run --project ImageMCP ``` ```bash dotnet run ``` ```powershell start_server.bat ``` ```bash ./start_server.sh ``` -------------------------------- ### Run All ImageMCP Tests Source: https://github.com/avidgamefan/imagemcp/blob/main/README.md Navigate to the ImageMCP.Tests directory and execute the dotnet test command to run all unit tests. ```bash cd ImageMCP.Tests dotnet test ``` -------------------------------- ### Configure LM Studio for ImageMCP Source: https://github.com/avidgamefan/imagemcp/blob/main/QUICK_START.md Configures LM Studio to connect to the ImageMCP server via HTTP. ```json { "mcpServers": { "imagemcp": { "url": "http://localhost:5243/mcp" } } } ``` -------------------------------- ### Run All Tests Source: https://github.com/avidgamefan/imagemcp/blob/main/README.md Execute all tests in the project. This is useful for a comprehensive check of the application's functionality. ```bash dotnet test ``` -------------------------------- ### LM Studio MCP Configuration Source: https://github.com/avidgamefan/imagemcp/blob/main/README.md Configure LM Studio to connect to the ImageMCP server by defining its command and arguments in the MCP configuration. ```json { "mcpServers": { "comfyui": { "command": "dotnet", "args": ["run", "--project", "C:/path/to/ImageMCP"], "env": {} } } } ``` -------------------------------- ### Configure Firewall for ImageMCP (Linux) Source: https://github.com/avidgamefan/imagemcp/blob/main/QUICK_START.md Allows incoming TCP traffic on port 5243 using ufw firewall on Linux. ```bash sudo ufw allow 5243/tcp ``` -------------------------------- ### Configure Custom Default Workflow in appsettings.json Source: https://github.com/avidgamefan/imagemcp/blob/main/QUICK_START.md Update appsettings.json to point to your custom workflow template. Ensure the path is correct relative to the ImageMCP executable. ```json { "ComfyUI": { "DefaultTemplate": "workflows/my_custom_workflow.json" } } ``` -------------------------------- ### Enable Debug Logging in appsettings.json Source: https://github.com/avidgamefan/imagemcp/blob/main/QUICK_START.md Set the logging level to 'Debug' for both default and ImageMCP specific logs. This provides detailed information for troubleshooting. ```json { "Logging": { "LogLevel": { "Default": "Debug", "ImageMCP": "Debug" } } } ``` -------------------------------- ### Configure ImageMCP for Network Access Source: https://github.com/avidgamefan/imagemcp/blob/main/QUICK_START.md Modifies ImageMCP's appsettings.json to listen on all network interfaces. ```json { "MCP": { "HttpPort": 5243, "HttpUrl": "http://0.0.0.0:5243" } } ``` -------------------------------- ### Configure Remote LM Studio for ImageMCP Source: https://github.com/avidgamefan/imagemcp/blob/main/QUICK_START.md Configures LM Studio on a remote machine to connect to ImageMCP using its IP address. ```json { "mcpServers": { "imagemcp": { "url": "http://192.168.1.100:5243/mcp" } } } ``` -------------------------------- ### Landscape Generation Prompt Source: https://github.com/avidgamefan/imagemcp/blob/main/QUICK_START.md Use this prompt for generating detailed landscape images. Includes a negative prompt to exclude unwanted elements. ```text Prompt: "beautiful landscape with mountains, lake, sunset, vibrant colors, detailed" Negative: "text, watermark, low quality, blurry" ``` -------------------------------- ### Configure Firewall for ImageMCP (Windows) Source: https://github.com/avidgamefan/imagemcp/blob/main/QUICK_START.md Adds a Windows Firewall rule to allow incoming TCP traffic on port 5243 for ImageMCP. ```powershell netsh advfirewall firewall add rule name="ImageMCP" dir=in action=allow protocol=TCP localport=5243 ``` -------------------------------- ### Submit Workflow to ComfyUI Source: https://github.com/avidgamefan/imagemcp/blob/main/README.md Constructs a JSON request containing the workflow and a client ID, then posts it to the ComfyUI API. Returns a prompt ID for tracking. ```csharp var requestJson = $$rich_text_literal_start_delimiter$${ "prompt": {{workflowJson}}, "client_id": "{{_clientId}}" }$$rich_text_literal_end_delimiter$$; await httpClient.PostAsync($"{comfyUIEndpoint}/prompt", content); // Returns prompt_id for tracking ``` -------------------------------- ### Run ImageMCP Tests with Coverage Source: https://github.com/avidgamefan/imagemcp/blob/main/README.md Execute dotnet test with the CollectCoverage=true property to run tests and generate code coverage reports. ```bash dotnet test /p:CollectCoverage=true ``` -------------------------------- ### ImageMCP Server Configuration Source: https://github.com/avidgamefan/imagemcp/blob/main/README.md Configure the ComfyUI API endpoint, default workflow template, timeouts, and MCP server details. Ensure the ComfyUI API endpoint matches your running ComfyUI instance. ```json { "ComfyUI": { "ApiEndpoint": "ws://127.0.0.1:8188", "DefaultTemplate": "workflows/default_workflow.json", "TimeoutSeconds": 300, "PollIntervalSeconds": 1 }, "MCP": { "ServerName": "ImageMCP", "ServerVersion": "1.0.0-dev", "HttpPort": 5243, "HttpUrl": "http://localhost:5243" } } ``` -------------------------------- ### Configure Default Workflow Template in appsettings.json Source: https://github.com/avidgamefan/imagemcp/blob/main/QUICK_START.md Set the default workflow template path in your application settings. This file will be used if no specific workflow is provided. ```json { "ComfyUI": { "DefaultTemplate": "workflows/default_workflow.json" } } ``` -------------------------------- ### Troubleshoot Port Conflict (Linux) Source: https://github.com/avidgamefan/imagemcp/blob/main/QUICK_START.md Finds processes using a specific port on Linux. ```bash # Find what's using port 5243 sudo lsof -i :5243 ``` -------------------------------- ### Inject Prompts into API Format Workflows Source: https://github.com/avidgamefan/imagemcp/blob/main/README.md Deserializes an API format workflow and injects positive or negative prompts into the appropriate CLIPTextEncode nodes. Identifies prompts based on keywords. ```csharp // For API format workflows var workflow = JsonSerializer.Deserialize>(workflowJson); foreach (var (nodeId, node) in workflow) { if (node.class_type == "CLIPTextEncode") { node.inputs.text = positivePrompt; // or negativePrompt } } ``` -------------------------------- ### Test ImageMCP Server Health (PowerShell) Source: https://github.com/avidgamefan/imagemcp/blob/main/QUICK_START.md Tests the health of the ImageMCP server using Invoke-WebRequest in PowerShell. ```powershell # Windows PowerShell Invoke-WebRequest http://localhost:5243/health ``` -------------------------------- ### Test ImageMCP Server Health (Linux) Source: https://github.com/avidgamefan/imagemcp/blob/main/QUICK_START.md Tests the health of the ImageMCP server using curl. ```bash curl http://localhost:5243/health ``` -------------------------------- ### Load Workflow Template Source: https://github.com/avidgamefan/imagemcp/blob/main/README.md Reads a workflow template from a file and parses it as JSON. Automatically detects if the workflow is in API format or UI format. ```csharp var workflowJson = await File.ReadAllTextAsync(templatePath); var template = JsonDocument.Parse(workflowJson); // Auto-detect format bool isApiFormat = !template.RootElement.TryGetProperty("nodes", out _); ``` -------------------------------- ### Artistic Style Generation Prompt Source: https://github.com/avidgamefan/imagemcp/blob/main/QUICK_START.md Use this prompt for generating images in artistic styles like oil painting. Includes a negative prompt for quality control. ```text Prompt: "oil painting of a castle, impressionist style, vibrant brushstrokes, masterpiece" Negative: "photo, realistic, modern, low quality" ``` -------------------------------- ### Anime Style Generation Prompt Source: https://github.com/avidgamefan/imagemcp/blob/main/QUICK_START.md Use this prompt for generating anime-style images. Specify anime-focused models and include quality-related negative prompts. ```text Prompt: "anime girl, detailed eyes, colorful hair, masterpiece, best quality" Model: animagineXL or similar anime-focused model Negative: "worst quality, low quality, bad anatomy, 3d, realistic" ``` -------------------------------- ### Save Custom Workflow Template Source: https://github.com/avidgamefan/imagemcp/blob/main/QUICK_START.md Place your custom ComfyUI workflow JSON file in the 'workflows' directory to use it with ImageMCP. ```plaintext workflows/my_custom_workflow.json ``` -------------------------------- ### Force Kill a Process Source: https://github.com/avidgamefan/imagemcp/blob/main/QUICK_START.md Use this command to forcefully terminate a process. Ensure you understand the implications, as it can lead to data loss. ```bash sudo kill -9 ``` -------------------------------- ### Test Coverage Source: https://github.com/avidgamefan/imagemcp/blob/main/README.md Generate test coverage reports using the Coverlet format. This helps in understanding which parts of the code are covered by tests. ```bash dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover ``` -------------------------------- ### Use Absolute Path for Workflow Template Source: https://github.com/avidgamefan/imagemcp/blob/main/QUICK_START.md If relative paths cause issues, configure the absolute path to your workflow template in appsettings.json. ```json { "ComfyUI": { "DefaultTemplate": "C:\\ImageMCP\\workflows\\default_workflow.json" } } ``` -------------------------------- ### Troubleshoot Port Conflict (Windows) Source: https://github.com/avidgamefan/imagemcp/blob/main/QUICK_START.md Finds and terminates processes using a specific port on Windows. ```powershell # Find what's using port 5243 netstat -ano | findstr :5243 # Kill the process ... only if you know it's safe to do so (can lose data) taskkill /PID /F ``` -------------------------------- ### Portrait Generation Prompt Source: https://github.com/avidgamefan/imagemcp/blob/main/QUICK_START.md Use this prompt for generating professional portraits. Includes a negative prompt to avoid common issues. ```text Prompt: "professional portrait of a person, studio lighting, detailed face, high quality" Negative: "distorted features, bad anatomy, low quality" ``` -------------------------------- ### Monitor Workflow Execution via WebSocket Source: https://github.com/avidgamefan/imagemcp/blob/main/README.md Connects to ComfyUI's WebSocket endpoint to monitor the progress of a workflow execution. Returns true upon successful execution completion. ```csharp await webSocket.ConnectAsync($"ws://127.0.0.1:8188/ws?clientId={clientId}"); while (true) { var message = await ReceiveWebSocketMessage(); if (message.type == "executed" && message.data.prompt_id == promptId) { return true; // Execution complete } } ``` -------------------------------- ### Connect to Remote ComfyUI Instance Source: https://github.com/avidgamefan/imagemcp/blob/main/QUICK_START.md Configure the WebSocket API endpoint for a ComfyUI instance running on a different machine or IP address. ```json { "ComfyUI": { "ApiEndpoint": "ws://192.168.1.100:8188" } } ``` -------------------------------- ### Retrieve Generated Images with Retry Logic Source: https://github.com/avidgamefan/imagemcp/blob/main/README.md Waits for history to finalize and then attempts to retrieve generated images from ComfyUI's history API. Retries up to 10 times with a 1-second delay between attempts. ```csharp // Wait 1 second for history to finalize await Task.Delay(1000); // Retry up to 10 times for (int attempt = 0; attempt < 10; attempt++) { var history = await httpClient.GetAsync($"/history/{promptId}"); if (history.ContainsKey(promptId)) { var images = ExtractImages(history[promptId].outputs); return images; // Success! } await Task.Delay(1000); // Wait and retry } ``` -------------------------------- ### Increase ComfyUI Timeout in appsettings.json Source: https://github.com/avidgamefan/imagemcp/blob/main/QUICK_START.md Adjust the maximum execution time for ComfyUI workflows in seconds. Increase this value if workflows are timing out. ```json { "ComfyUI": { "TimeoutSeconds": 600 } } ``` -------------------------------- ### Configure ComfyUI API Endpoint in appsettings.json Source: https://github.com/avidgamefan/imagemcp/blob/main/QUICK_START.md Specify the WebSocket endpoint for ComfyUI in your application settings. This is crucial for ImageMCP to communicate with ComfyUI. ```json { "ApiEndpoint": "ws://127.0.0.1:8188" } ``` -------------------------------- ### Test ComfyUI WebSocket Connection Source: https://github.com/avidgamefan/imagemcp/blob/main/QUICK_START.md Use this JavaScript snippet in your browser's developer console to test if you can connect to the ComfyUI WebSocket endpoint. ```javascript new WebSocket("ws://127.0.0.1:8188/ws") ``` -------------------------------- ### Run Specific Test Category Source: https://github.com/avidgamefan/imagemcp/blob/main/README.md Filter tests to run only those belonging to a specific category, such as 'Unit' or 'Integration'. Integration tests require ComfyUI to be running. ```bash # Unit tests only dotnet test --filter Category=Unit # Integration tests (requires ComfyUI running) dotnet test --filter Category=Integration ``` -------------------------------- ### Change ImageMCP Server Port Source: https://github.com/avidgamefan/imagemcp/blob/main/QUICK_START.md Modify the HTTP port for the ImageMCP server. This is useful if the default port (e.g., 5243) is already in use. ```json { "MCP": { "HttpPort": 8080, "HttpUrl": "http://localhost:8080" } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.