Skip to main content
Glama

FLUX Image Generator MCP Server

by frankdeno

quickImage

Generate images from text prompts using default settings for quick and efficient visual creation. Ideal for users needing instant image outputs without custom configurations.

Instructions

Quickly generate an image based on a text prompt with default settings

Input Schema

NameRequiredDescriptionDefault
customPathNoCustom path to save the generated image
promptYesText description of the image to generate

Input Schema (JSON Schema)

{ "properties": { "customPath": { "description": "Custom path to save the generated image", "type": "string" }, "prompt": { "description": "Text description of the image to generate", "type": "string" } }, "required": [ "prompt" ], "type": "object" }

Implementation Reference

  • Executes the quickImage tool: validates the input prompt, calls generateImage service with default settings (1024x1024, save enabled), formats response with image URL and local path.
    case "quickImage": { // Validate parameters if (typeof args.prompt !== 'string') { throw new Error("Invalid prompt: must be a string"); } // Simple version with just a prompt const result = await generateImage(args.prompt, { saveImage: true, filename: `flux_quick_${Date.now()}.png`, customPath: typeof args.customPath === 'string' ? args.customPath : undefined }); // Return a plain text response with the image URL and save location let textContent = `Image generated\nLink: ${result.image_url}`; // Add information about where the image was saved if (result.local_path) { textContent += `\nImage saved to: ${result.local_path}`; } return { content: [ { type: "text", text: textContent } ], isError: false, }; }
  • Defines the input/output schema and metadata for the quickImage tool.
    export const QUICK_IMAGE_TOOL: Tool = { name: "quickImage", description: "Quickly generate an image based on a text prompt with default settings", inputSchema: { type: "object", properties: { prompt: { type: "string", description: "Text description of the image to generate" }, customPath: { type: "string", description: "Custom path to save the generated image" } }, required: ["prompt"] } };
  • src/index.ts:48-54 (registration)
    Registers the quickImage tool (via QUICK_IMAGE_TOOL) in the list of available tools.
    server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [ GENERATE_IMAGE_TOOL, QUICK_IMAGE_TOOL, BATCH_GENERATE_IMAGES_TOOL ], }));
  • Core helper function implementing image generation via Black Forest Lab API, including polling for results and optional local download/save. Used by quickImage handler.
    export async function generateImage( prompt: string, options: ImageGenerationOptions = {} ): Promise<ImageGenerationResult> { const apiKey = process.env.BFL_API_KEY; if (!apiKey) { throw new Error('API key is required. Set BFL_API_KEY environment variable.'); } // Build the request payload const payload = { prompt, width: options.width || 1024, height: options.height || 1024, prompt_upsampling: options.promptUpsampling || false, safety_tolerance: options.safetyTolerance || 3, ...(options.seed !== undefined && { seed: options.seed }) }; let pollingUrl; try { // Make the initial API request console.error(`[INFO] Sending request to FLUX API for prompt: "${prompt}"`); const response = await axios.post(BFL_API_ENDPOINT, payload, { headers: { 'Content-Type': 'application/json', 'X-Key': apiKey } }); // Check if we need to poll for results if (response.data.polling_url) { pollingUrl = response.data.polling_url; console.error(`[INFO] Got polling URL: ${pollingUrl}`); } else if (response.data.image_url) { // If we got an image URL directly, no need to poll console.error(`[INFO] Got image URL directly: ${response.data.image_url}`); const result: ImageGenerationResult = { image_url: response.data.image_url, local_path: null }; // Save the image locally if requested if (options.saveImage) { try { const filename = options.filename || `flux_${Date.now()}.png`; const savePath = await downloadImage( result.image_url, filename, options.outputDir || process.env.OUTPUT_DIR || './output', options.customPath ); result.local_path = savePath; } catch (downloadError: any) { console.error(`[ERROR] Error saving image: ${downloadError.message}`); // Continue with the operation even if download fails } } return result; } else { throw new Error('Invalid response from Black Forest Lab API: No polling URL or image URL'); } } catch (error: any) { const errorMsg = error.response?.data?.message || error.message || 'Unknown error'; console.error(`[ERROR] Error calling Black Forest Lab API: ${errorMsg}`); throw new Error(`Failed to generate image: ${errorMsg}`); } // If we have a polling URL, poll for the result try { const maxPollingAttempts = options.maxPollingAttempts || 30; const pollingInterval = options.pollingInterval || 2000; const pollResult = await pollForResults( pollingUrl, apiKey, maxPollingAttempts, pollingInterval ); // Check if we have a direct image_url or need to extract it from result.sample if (!pollResult.image_url && pollResult.result && pollResult.result.sample) { pollResult.image_url = pollResult.result.sample; } if (!pollResult.image_url) { throw new Error('No image URL in completed result'); } const result: ImageGenerationResult = { image_url: pollResult.image_url, local_path: null }; // Save the image locally if requested if (options.saveImage) { try { const filename = options.filename || `flux_${Date.now()}.png`; const savePath = await downloadImage( result.image_url, filename, options.outputDir || process.env.OUTPUT_DIR || './output', options.customPath ); result.local_path = savePath; } catch (downloadError: any) { console.error(`[ERROR] Error saving image: ${downloadError.message}`); // Continue with the operation even if download fails } } return result; } catch (error: any) { console.error(`[ERROR] Error in polling process: ${error.message}`); throw new Error(`Failed to generate image: ${error.message}`); } }

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/frankdeno/flux-image-generator-mcp'

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