Skip to main content
Glama

add_picture

Insert images into Microsoft Word documents by specifying the filename, image path, and optional width. Facilitates enhanced document customization and visual content integration within the Office Word MCP Server.

Instructions

Add an image to a Word document.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filenameYes
image_pathYes
widthNo

Implementation Reference

  • The core handler function that implements the logic to add a picture to a Word document: validates inputs, checks file permissions, loads document, inserts image with optional width scaling, saves changes, and provides detailed error handling.
    async def add_picture(filename: str, image_path: str, width: Optional[float] = None) -> str:
        """Add an image to a Word document.
        
        Args:
            filename: Path to the Word document
            image_path: Path to the image file
            width: Optional width in inches (proportional scaling)
        """
        filename = ensure_docx_extension(filename)
        
        # Validate document existence
        if not os.path.exists(filename):
            return f"Document {filename} does not exist"
        
        # Get absolute paths for better diagnostics
        abs_filename = os.path.abspath(filename)
        abs_image_path = os.path.abspath(image_path)
        
        # Validate image existence with improved error message
        if not os.path.exists(abs_image_path):
            return f"Image file not found: {abs_image_path}"
        
        # Check image file size
        try:
            image_size = os.path.getsize(abs_image_path) / 1024  # Size in KB
            if image_size <= 0:
                return f"Image file appears to be empty: {abs_image_path} (0 KB)"
        except Exception as size_error:
            return f"Error checking image file: {str(size_error)}"
        
        # Check if file is writeable
        is_writeable, error_message = check_file_writeable(abs_filename)
        if not is_writeable:
            return f"Cannot modify document: {error_message}. Consider creating a copy first or creating a new document."
        
        try:
            doc = Document(abs_filename)
            # Additional diagnostic info
            diagnostic = f"Attempting to add image ({abs_image_path}, {image_size:.2f} KB) to document ({abs_filename})"
            
            try:
                if width:
                    doc.add_picture(abs_image_path, width=Inches(width))
                else:
                    doc.add_picture(abs_image_path)
                doc.save(abs_filename)
                return f"Picture {image_path} added to {filename}"
            except Exception as inner_error:
                # More detailed error for the specific operation
                error_type = type(inner_error).__name__
                error_msg = str(inner_error)
                return f"Failed to add picture: {error_type} - {error_msg or 'No error details available'}\nDiagnostic info: {diagnostic}"
        except Exception as outer_error:
            # Fallback error handling
            error_type = type(outer_error).__name__
            error_msg = str(outer_error)
            return f"Document processing error: {error_type} - {error_msg or 'No error details available'}"
  • MCP tool registration using FastMCP @mcp.tool() decorator. Defines the tool interface with parameters and docstring (serving as schema), and delegates execution to the implementation in content_tools.add_picture.
    @mcp.tool()
    async def add_picture(filename: str, image_path: str, width: Optional[float] = None):
        """Add an image to a Word document."""
        return await content_tools.add_picture(filename, image_path, width)
  • Imports the add_picture function from content_tools.py, making it available for use in the main server registration.
    from word_document_server.tools.content_tools import (
        add_heading, add_paragraph, add_table, add_picture,
        add_page_break, add_table_of_contents, delete_paragraph,
        search_and_replace
    )
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool adds an image but does not describe how it behaves: whether it modifies an existing document or creates a new one, what happens if the image path is invalid, if there are size limits, or what the output looks like. This is inadequate for a mutation tool with zero annotation coverage.

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 a single, efficient sentence that gets straight to the point with no wasted words. It is appropriately sized and front-loaded, making it easy to parse quickly.

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

Completeness2/5

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

Given the tool's complexity (a mutation operation with 3 parameters), lack of annotations, and no output schema, the description is incomplete. It fails to explain key aspects like behavioral traits, parameter usage, or expected outcomes, leaving the agent with insufficient information to use the tool effectively.

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

Parameters2/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 by explaining parameters, but it adds no meaning beyond the schema. It does not clarify what 'filename' refers to (e.g., the Word document name), what format 'image_path' expects, or how 'width' affects the image. With 3 parameters and low coverage, this is a significant gap.

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

Purpose4/5

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

The description clearly states the action ('Add') and target resource ('an image to a Word document'), making the purpose immediately understandable. However, it does not differentiate this tool from its siblings (e.g., add_paragraph, add_table), which all modify Word documents in various ways, so it lacks sibling differentiation.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It does not mention prerequisites (e.g., needing an existing document), exclusions, or comparisons to other tools like add_paragraph or add_table, leaving the agent to infer usage from context alone.

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/franlealp1/mcp-word'

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