Skip to main content
Glama

control

Generate controlled AI images using structural inputs like canny, depth, or pose to guide image creation, based on text prompts and control image paths.

Instructions

Generate an image using structural control

Input Schema

NameRequiredDescriptionDefault
guidanceNoGuidance scale
imageYesInput control image path
outputNoOutput filename
promptYesText prompt for generation
stepsNoNumber of inference steps
typeYesType of control to use

Input Schema (JSON Schema)

{ "properties": { "guidance": { "description": "Guidance scale", "type": "number" }, "image": { "description": "Input control image path", "type": "string" }, "output": { "description": "Output filename", "type": "string" }, "prompt": { "description": "Text prompt for generation", "type": "string" }, "steps": { "default": 50, "description": "Number of inference steps", "type": "number" }, "type": { "description": "Type of control to use", "enum": [ "canny", "depth", "pose" ], "type": "string" } }, "required": [ "type", "image", "prompt" ], "type": "object" }

Implementation Reference

  • The main handler function for the 'control' MCP tool. Validates input arguments using helper methods and constructs command-line arguments to spawn the Python CLI implementation via runPythonCommand.
    case 'control': { const args = request.params.arguments as ControlArgs; // Validate required fields const type = this.validateRequiredString(args.type, 'type') as ControlType; const image = this.validateRequiredString(args.image, 'image'); const prompt = this.validateRequiredString(args.prompt, 'prompt'); // Validate optional numeric fields const steps = this.validateNumber(args.steps, 'steps', 1, 100); const guidance = this.validateNumber(args.guidance, 'guidance', 0, 100); const cmdArgs = ['control']; cmdArgs.push('--type', type); cmdArgs.push('--image', image); cmdArgs.push('--prompt', prompt); if (steps) cmdArgs.push('--steps', steps.toString()); if (guidance !== undefined) cmdArgs.push('--guidance', guidance.toString()); if (args.output) cmdArgs.push('--output', args.output); const output = await this.runPythonCommand(cmdArgs); return { content: [{ type: 'text', text: output }], }; }
  • src/index.ts:250-285 (registration)
    Registration of the 'control' tool in the MCP ListTools response, providing the tool name, description, and JSON schema for input validation.
    { name: 'control', description: 'Generate an image using structural control', inputSchema: { type: 'object', properties: { type: { type: 'string', description: 'Type of control to use', enum: ['canny', 'depth', 'pose'], }, image: { type: 'string', description: 'Input control image path', }, prompt: { type: 'string', description: 'Text prompt for generation', }, steps: { type: 'number', description: 'Number of inference steps', default: 50, }, guidance: { type: 'number', description: 'Guidance scale', }, output: { type: 'string', description: 'Output filename', }, }, required: ['type', 'image', 'prompt'], }, },
  • TypeScript interface defining the structure of arguments expected by the 'control' tool handler, used for type checking.
    export interface ControlArgs { type: ControlType; image: string; prompt: string; steps?: number; guidance?: number; output?: string; }
  • Type definition for the control type enum, used in ControlArgs and input schema.
    export type ControlType = 'canny' | 'depth' | 'pose';
  • Helper method used by all tool handlers, including 'control', to execute the Python CLI implementation by spawning a child process.
    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