Skip to main content
Glama

generate-and-save-image

Generate custom images using FLUX AI and save them as PNG files for use in PowerPoint presentations. Provide a text prompt and filename to create visual content.

Instructions

Generates an image using a FLUX model and save the image to the specified path. The tool will return a PNG file path. It should be used when the user asks to generate or create an image or a picture.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptYesDescription of the image to generate in the form of a prompt.
file_nameYesFilename of the image. Include the extension of .png

Implementation Reference

  • Registration of the 'generate-and-save-image' tool in the @server.list_tools() handler, including name, description, and input schema definition.
    types.Tool(
        name="generate-and-save-image",
        description="Generates an image using a FLUX model and save the image to the specified path. The tool "
                    "will return a PNG file path. It should be used when the user asks to generate or create an "
                    "image or a picture.",
        inputSchema={
            "type": "object",
            "properties": {
                "prompt": {
                    "type": "string",
                    "description": "Description of the image to generate in the form of a prompt.",
                },
                "file_name": {
                    "type": "string",
                    "description": "Filename of the image. Include the extension of .png",
                },
            },
            "required": ["prompt", "file_name"],
        },
    ),
  • Dispatch handler logic within @server.call_tool(): validates arguments, sanitizes file path, invokes VisionManager, and returns success/error text content.
    elif name == "generate-and-save-image":
        prompt = arguments.get("prompt")
        file_name = arguments.get("file_name")
        try:
            safe_file_path = sanitize_path(folder_path, file_name)
        except ValueError as e:
            raise ValueError(f"Invalid file path: {str(e)}")
    
        if not all([prompt, file_name]):
            raise ValueError("Missing required arguments")
    
        try:
            saved_path = await vision_manager.generate_and_save_image(prompt, str(safe_file_path))
            return [
                types.TextContent(
                    type="text",
                    text=f"Successfully generated and saved image to: {saved_path}"
                )
            ]
        except Exception as e:
            return [
                types.TextContent(
                    type="text",
                    text=f"Failed to generate image: {str(e)}"
                )
            ]
  • Primary tool execution logic in VisionManager class: generates image using FLUX model via Together AI, downloads with requests, opens with PIL, and saves to disk.
    async def generate_and_save_image(self, prompt: str, output_path: str) -> str:
        """Generate an image using Together AI/Flux Model and save it to the specified path."""
    
        api_key = os.environ.get('TOGETHER_API_KEY')
        if not api_key:
            raise ValueError("TOGETHER_API_KEY environment variable not set.")
    
        client = Together(api_key=api_key)
    
        try:
            # Generate the image
            response = client.images.generate(
                prompt=prompt,
                width=1024,
                height=1024,
                steps=4,
                model="black-forest-labs/FLUX.1-schnell-Free",
                n=1,
            )
        except Exception as e:
            raise ValueError(f"Failed to generate image: {str(e)}")
    
        image_url = response.data[0].url
    
        # Download the image
        try:
            response = requests.get(image_url)
            if response.status_code != 200:
                raise ValueError(f"Failed to download generated image: HTTP {response.status_code}")
        except requests.RequestException as e:
            raise ValueError(f"Network error downloading image: {str(e)}")
    
        # Save the image
        try:
            image = Image.open(BytesIO(response.content))
            # Ensure the save directory exists
            try:
                os.makedirs(os.path.dirname(output_path), exist_ok=True)
            except OSError as e:
                raise ValueError(f"Failed to create a directory for image: str({e})")
            # Save the image
            image.save(output_path)
        except (IOError, OSError) as e:
            raise ValueError(f"Failed to save image to {output_path}: {str(e)}")
    
        return output_path
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions that the tool saves the image to a specified path and returns a PNG file path, which is useful. However, it lacks critical details such as potential rate limits, authentication requirements, file size constraints, or error handling, leaving significant gaps in understanding the tool's behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is front-loaded with the core functionality in the first sentence and uses a second sentence to provide usage guidelines. Both sentences are essential and contribute directly to understanding the tool, with no wasted words or redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of an image generation tool with no annotations and no output schema, the description is incomplete. It covers the basic purpose and usage but lacks details on behavioral aspects like performance, limitations, or error cases. The absence of an output schema means the description should ideally explain return values more thoroughly, which it does not.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, so the schema already documents both parameters (prompt and file_name) adequately. The description does not add any additional meaning or context beyond what the schema provides, such as examples or constraints, resulting in a baseline score of 3.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Generates an image using a FLUX model and save the image to the specified path') and distinguishes it from sibling tools focused on presentation slides. It identifies the resource (image) and the technology (FLUX model), making the purpose unambiguous.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context for when to use the tool ('when the user asks to generate or create an image or a picture'), which is helpful for an AI agent. However, it does not explicitly state when NOT to use it or mention alternatives, such as other image generation tools or methods, which prevents a perfect score.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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/supercurses/powerpoint'

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