Skip to main content
Glama
Ichigo3766

PowerPoint MCP Server

by Ichigo3766

generate-and-save-image

Create and save custom PNG images using FLUX model prompts on the PowerPoint MCP Server. Specify a description and filename to generate and store images for presentations.

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
file_nameYesFilename of the image. Include the extension of .png
promptYesDescription of the image to generate in the form of a prompt.

Implementation Reference

  • Dispatch handler in the main tool caller that validates arguments, sanitizes the output path, and delegates image generation to VisionManager.
    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)}"
                )
            ]
  • Core implementation that generates image using Stable Diffusion WebUI API (FLUX model via SD), decodes base64 response, and saves as PNG to the specified path.
    async def generate_and_save_image(self, prompt: str, output_path: str) -> str:
        """Generate an image using Stable Diffusion API and save it to the specified path."""
        headers = {'Content-Type': 'application/json'}
        auth = None
        if self.auth_user and self.auth_pass:
            auth = (self.auth_user, self.auth_pass)
    
        payload = {
            "prompt": prompt,
            "negative_prompt": "",
            "steps": 4,
            "width": 1024,
            "height": 1024,
            "cfg_scale": 1,
            "sampler_name": "Euler",
            "seed": -1,
            "n_iter": 1,
            "scheduler": "Simple"
        }
    
        try:
            # Generate the image
            response = requests.post(
                f"{self.sd_url}/sdapi/v1/txt2img",
                headers=headers,
                auth=auth,
                json=payload,
                timeout=3600
            )
            response.raise_for_status()
            
            if not response.json().get('images'):
                raise ValueError("No images generated")
            
            # Get the first image
            image_data = response.json()['images'][0]
            if ',' in image_data:
                image_data = image_data.split(',')[1]
            
            # Convert base64 to image
            image_bytes = base64.b64decode(image_data)
            image = Image.open(BytesIO(image_bytes))
    
            # 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 directory for image: {str(e)}")
    
            # Save the image
            image.save(output_path)
            
        except requests.RequestException as e:
            raise ValueError(f"Failed to generate image: {str(e)}")
        except (IOError, OSError) as e:
            raise ValueError(f"Failed to save image to {output_path}: {str(e)}")
    
        return output_path
  • Tool registration in 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"],
        },
    ),
  • Utility function to sanitize the output file path to prevent directory traversal.
    def sanitize_path(base_path: str, file_name: str) -> str:
        """
        Ensure that the resulting path doesn't escape outside the base directory
        Returns a safe, normalized path
        """
    
        joined_path = os.path.join(base_path, file_name)
        normalized_path = os.path.normpath(joined_path)
    
        if not normalized_path.startswith(base_path):
            raise ValueError(f"Invalid path. Attempted to access location outside allowed directory.")
    
        return normalized_path

Tool Definition Quality

Score is being calculated. Check back soon.

Install Server

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/Ichigo3766/powerpoint-mcp'

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