Skip to main content
Glama
daekeun-ml

PowerPoint Translator

by daekeun-ml

post_process_powerpoint

Optimize PowerPoint presentations by adjusting text boxes; enable text wrapping and auto-fit for content exceeding specified length thresholds. Streamline formatting for improved readability.

Instructions

Apply post-processing to a PowerPoint presentation to optimize text boxes.

This function enables text wrapping and shrink text on overflow for text boxes that contain text longer than the specified threshold.

Args: input_file: Path to the input PowerPoint file (.pptx) output_file: Path to save the processed file (optional, auto-generated if not provided) text_threshold: Text length threshold for enabling auto-fit (overrides .env setting) enable_autofit: Enable text auto-fitting (default: True)

Returns: Success message with post-processing details

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
enable_autofitNo
input_fileYes
output_fileNo
text_thresholdNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler function for the 'post_process_powerpoint' tool, decorated with @mcp.tool() for registration. It validates the input PowerPoint file, applies configuration overrides, instantiates PowerPointPostProcessor, and calls process_presentation to perform the text auto-fitting.
    @mcp.tool()
    def post_process_powerpoint(
        input_file: str,
        output_file: Optional[str] = None,
        text_threshold: Optional[int] = None,
        enable_autofit: bool = True
    ) -> str:
        """
        Apply post-processing to a PowerPoint presentation to optimize text boxes.
        
        This function enables text wrapping and shrink text on overflow for text boxes
        that contain text longer than the specified threshold.
        
        Args:
            input_file: Path to the input PowerPoint file (.pptx)
            output_file: Path to save the processed file (optional, auto-generated if not provided)
            text_threshold: Text length threshold for enabling auto-fit (overrides .env setting)
            enable_autofit: Enable text auto-fitting (default: True)
        
        Returns:
            Success message with post-processing details
        """
        try:
            # Validate input file using helper function
            input_path, error_msg = validate_input_path(input_file)
            if error_msg:
                return error_msg
            
            # Create configuration
            config = Config()
            if text_threshold is not None:
                config.set('TEXT_LENGTH_THRESHOLD', str(text_threshold))
            if not enable_autofit:
                config.set('ENABLE_TEXT_AUTOFIT', 'false')
            
            # Generate output filename if not provided
            if not output_file:
                output_file = str(input_path)  # Overwrite the original file
            
            # Apply post-processing
            logger.info(f"Starting post-processing: {input_path}")
            verbose = config.get_bool('DEBUG', False)
            post_processor = PowerPointPostProcessor(config, verbose=verbose)
            final_output = post_processor.process_presentation(str(input_path), output_file)
            
            threshold = config.get_int('TEXT_LENGTH_THRESHOLD', 10)
            autofit_enabled = config.get_bool('ENABLE_TEXT_AUTOFIT', True)
            
            return f"""✅ PowerPoint post-processing completed successfully!
    
    📁 Input file: {input_path}
    📁 Output file: {final_output}
    🔧 Text auto-fitting: {'✅ Enabled' if autofit_enabled else '❌ Disabled'}
    📏 Text length threshold: {threshold} characters
    📝 Processing applied to text boxes longer than {threshold} characters
    
    💡 Post-processing features applied:
    • Text wrapping in shape enabled
    • Shrink text on overflow enabled
    • Text box margins optimized
    • Formatting preservation maintained"""
            
        except Exception as e:
            logger.error(f"Post-processing failed: {str(e)}")
            return f"❌ Post-processing failed: {str(e)}"
  • Core helper method in PowerPointPostProcessor class that implements the post-processing logic: loads the PPTX, iterates over slides and shapes, applies text wrapping and shrink-on-overflow for text boxes exceeding the length threshold.
    def process_presentation(self, input_file: str, output_file: Optional[str] = None) -> str:
        """
        Process a PowerPoint presentation to enable text auto-fitting.
        
        Args:
            input_file: Path to the input PowerPoint file
            output_file: Path to save the processed file (optional)
            
        Returns:
            Path to the processed file
        """
        if not os.path.exists(input_file):
            raise FileNotFoundError(f"Input file not found: {input_file}")
            
        # Use input file as output file if not provided (overwrite original)
        if not output_file:
            output_file = input_file
        
        print(f"Processing PowerPoint file: {input_file}")
        print(f"Text length threshold: {self.text_threshold} characters")
        print(f"Auto-fit enabled: {self.enable_autofit}")
        
        # Load presentation
        presentation = Presentation(input_file)
        
        total_processed = 0
        total_slides = len(presentation.slides)
        
        # Process each slide
        for slide_idx, slide in enumerate(presentation.slides, 1):
            if self.verbose:
                print(f"Processing slide {slide_idx}/{total_slides}...")
            processed_count = self._process_slide(slide)
            total_processed += processed_count
            
            if processed_count > 0 and self.verbose:
                print(f"  → Processed {processed_count} text boxes")
        
        # Save the processed presentation
        presentation.save(output_file)
        
        if self.verbose:
            print(f"\nPost-processing completed!")
            print(f"Total text boxes processed: {total_processed}")
            print(f"Output saved to: {output_file}")
        
        return output_file
  • Helper method _process_slide that iterates over slide shapes, checks if they need processing via _should_process_shape, and applies autofit via _apply_text_autofit.
    def _process_slide(self, slide) -> int:
        """
        Process a single slide to enable text auto-fitting for qualifying text boxes.
        
        Args:
            slide: PowerPoint slide object
            
        Returns:
            Number of text boxes processed
        """
        processed_count = 0
        
        for shape in slide.shapes:
            if self._should_process_shape(shape):
                self._apply_text_autofit(shape)
                processed_count += 1
                
        return processed_count
Behavior2/5

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

With no annotations provided, the description carries full burden. It mentions the tool 'enables text wrapping and shrink text on overflow' which describes behavior, but lacks details on permissions needed, whether the original file is modified or a new file is created, error conditions, or rate limits. For a mutation tool with zero annotation coverage, this is insufficient.

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

Conciseness4/5

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

The description is well-structured with a purpose statement, parameter explanations, and return value note. Each sentence adds value, though the parameter explanations could be slightly more concise. It's appropriately sized for a 4-parameter tool.

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

Completeness4/5

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

Given the tool's moderate complexity (4 parameters, mutation operation) and no annotations, the description does well by explaining all parameters and noting the return is a success message. With an output schema present, it doesn't need to detail return values. However, it could better address behavioral aspects like file handling or error cases.

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

Parameters4/5

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

Schema description coverage is 0%, so the description must compensate. It provides meaningful context for all 4 parameters: input_file specifies format (.pptx), output_file explains auto-generation, text_threshold clarifies it overrides .env settings, and enable_autofit notes its default. This adds substantial value beyond the bare schema.

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 ('Apply post-processing'), target resource ('PowerPoint presentation'), and purpose ('to optimize text boxes'). It distinguishes this tool from siblings like get_slide_info or translate_powerpoint by focusing on text box optimization rather than retrieval or translation.

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

Usage Guidelines3/5

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

The description implies usage for text box optimization when text exceeds a threshold, but doesn't explicitly state when to use this tool versus alternatives like translate_powerpoint or when not to use it (e.g., for non-text elements). No prerequisites or exclusions are mentioned.

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

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/daekeun-ml/ppt-translator'

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