Skip to main content
Glama

generate

Transform text prompts into images using advanced AI models. Specify aspect ratios, dimensions, and output filenames for customized visual outputs with MCP Flux Studio.

Instructions

Generate an image from a text prompt

Input Schema

NameRequiredDescriptionDefault
aspect_ratioNoAspect ratio of the output image
heightNoImage height (ignored if aspect-ratio is set)
modelNoModel to use for generationflux.1.1-pro
outputNoOutput filenamegenerated.jpg
promptYesText prompt for image generation
widthNoImage width (ignored if aspect-ratio is set)

Input Schema (JSON Schema)

{ "properties": { "aspect_ratio": { "description": "Aspect ratio of the output image", "enum": [ "1:1", "4:3", "3:4", "16:9", "9:16" ], "type": "string" }, "height": { "description": "Image height (ignored if aspect-ratio is set)", "type": "number" }, "model": { "default": "flux.1.1-pro", "description": "Model to use for generation", "enum": [ "flux.1.1-pro", "flux.1-pro", "flux.1-dev", "flux.1.1-ultra" ], "type": "string" }, "output": { "default": "generated.jpg", "description": "Output filename", "type": "string" }, "prompt": { "description": "Text prompt for image generation", "type": "string" }, "width": { "description": "Image width (ignored if aspect-ratio is set)", "type": "number" } }, "required": [ "prompt" ], "type": "object" }

Implementation Reference

  • Handler function for the MCP 'generate' tool: validates input arguments, constructs command-line arguments for the Flux CLI, executes the CLI via runPythonCommand, and returns the output as text content.
    case 'generate': { const args = request.params.arguments as GenerateArgs; // Validate required fields const prompt = this.validateRequiredString(args.prompt, 'prompt'); // Validate optional numeric fields const width = this.validateNumber(args.width, 'width', 256, 2048); const height = this.validateNumber(args.height, 'height', 256, 2048); const cmdArgs = ['generate']; cmdArgs.push('--prompt', prompt); if (args.model) cmdArgs.push('--model', args.model); if (args.aspect_ratio) cmdArgs.push('--aspect-ratio', args.aspect_ratio); 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:131-168 (registration)
    Registration of the 'generate' tool in the MCP ListTools response, including its name, description, and detailed input schema.
    { name: 'generate', description: 'Generate an image from a text prompt', inputSchema: { type: 'object', properties: { prompt: { type: 'string', description: 'Text prompt for image 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', }, aspect_ratio: { type: 'string', description: 'Aspect ratio of the output image', enum: ['1:1', '4:3', '3:4', '16:9', '9:16'], }, width: { type: 'number', description: 'Image width (ignored if aspect-ratio is set)', }, height: { type: 'number', description: 'Image height (ignored if aspect-ratio is set)', }, output: { type: 'string', description: 'Output filename', default: 'generated.jpg', }, }, required: ['prompt'], }, },
  • TypeScript interface defining the input arguments (schema) for the 'generate' tool.
    export interface GenerateArgs { prompt: string; model?: FluxModel; aspect_ratio?: AspectRatio; width?: number; height?: number; output?: string; }
  • Core helper function that executes the Flux CLI (fluxcli.py) by spawning a Python child process with the provided arguments and returns the stdout output.
    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}`)); } }); }); }
  • Helper function for validating required string parameters in tool inputs, used for 'prompt' in generate.
    private validateRequiredString(value: unknown, fieldName: string): string { if (typeof value !== 'string' || value.trim() === '') { throw new McpError( ErrorCode.InvalidParams, `${fieldName} is required and must be a non-empty string` ); } return value; }

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