Skip to main content
Glama

img2img

Transform images using AI by providing a reference image and text prompt to generate customized visuals. Features adjustable parameters like strength, width, and height for precise control over output.

Instructions

Generate an image using another image as reference

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
heightNoOutput image height
imageYesInput image path
modelNoModel to use for generationflux.1.1-pro
nameYesName for the generation
outputNoOutput filenameoutputs/generated.jpg
promptYesText prompt for generation
strengthNoGeneration strength
widthNoOutput image width

Implementation Reference

  • The main handler function for the 'img2img' MCP tool. It validates the input arguments using helper methods, constructs the command-line arguments for the Python CLI, executes the command via runPythonCommand, and returns the output.
    case 'img2img': { const args = request.params.arguments as Img2ImgArgs; // Validate required fields const image = this.validateRequiredString(args.image, 'image'); const prompt = this.validateRequiredString(args.prompt, 'prompt'); const name = this.validateRequiredString(args.name, 'name'); // Validate optional numeric fields const strength = this.validateNumber(args.strength, 'strength', 0, 1); const width = this.validateNumber(args.width, 'width', 256, 2048); const height = this.validateNumber(args.height, 'height', 256, 2048); const cmdArgs = ['img2img']; cmdArgs.push('--image', image); cmdArgs.push('--prompt', prompt); cmdArgs.push('--name', name); if (args.model) cmdArgs.push('--model', args.model); if (strength !== undefined) cmdArgs.push('--strength', strength.toString()); if (width) cmdArgs.push('--width', width.toString()); if (height) cmdArgs.push('--height', height.toString()); if (args.output) cmdArgs.push('--output', args.output); const output = await this.runPythonCommand(cmdArgs); return { content: [{ type: 'text', text: output }], }; }
  • src/index.ts:169-214 (registration)
    Registration of the 'img2img' tool in the MCP ListTools response, defining its name, description, and JSON schema for input validation.
    { name: 'img2img', description: 'Generate an image using another image as reference', inputSchema: { type: 'object', properties: { image: { type: 'string', description: 'Input image path', }, prompt: { type: 'string', description: 'Text prompt for generation', }, model: { type: 'string', description: 'Model to use for generation', enum: ['flux.1.1-pro', 'flux.1-pro', 'flux.1-dev', 'flux.1.1-ultra'], default: 'flux.1.1-pro', }, strength: { type: 'number', description: 'Generation strength', default: 0.85, }, width: { type: 'number', description: 'Output image width', }, height: { type: 'number', description: 'Output image height', }, output: { type: 'string', description: 'Output filename', default: 'outputs/generated.jpg', }, name: { type: 'string', description: 'Name for the generation', }, }, required: ['image', 'prompt', 'name'], }, },
  • TypeScript interface Img2ImgArgs defining the structure of arguments for the img2img tool, used for type-checking in the handler.
    * Arguments for the img2img tool */ export interface Img2ImgArgs { image: string; prompt: string; name: string; model?: FluxModel; strength?: number; width?: number; height?: number; output?: string; }
  • Helper method runPythonCommand that spawns the Python fluxcli.py process with the constructed arguments and captures its output, used by all tool handlers including img2img.
    private async runPythonCommand(args: string[]): Promise<string> { return new Promise((resolve, reject) => { // Validate arguments if (!args || args.length === 0) { reject(new Error('No command arguments provided')); return; } // Use python from virtual environment if available const pythonPath = process.env.VIRTUAL_ENV ? `${process.env.VIRTUAL_ENV}/bin/python` : 'python3'; const childProcess = spawn(pythonPath, ['fluxcli.py', ...args], { cwd: this.fluxPath, env: process.env, // Pass through all environment variables }); let output = ''; let errorOutput = ''; childProcess.stdout?.on('data', (data) => { output += data.toString(); }); childProcess.stderr?.on('data', (data) => { errorOutput += data.toString(); }); childProcess.on('error', (error) => { reject(new Error(`Failed to spawn Python process: ${error.message}`)); }); childProcess.on('close', (code) => { if (code === 0) { resolve(output); } else { reject(new Error(`Flux command failed (exit code ${code}): ${errorOutput}`)); } }); }); }

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/jmanhype/mcp-flux-studio'

If you have feedback or need assistance with the MCP directory API, please join our Discord server