Skip to main content
Glama

add_image_caption

Add captions to images in Word documents by specifying image index, text, and type (Figure, Table, or Equation) for better document organization and accessibility.

Instructions

Add a caption to an image in the document.

Args: filepath: Path to the document image_index: Index of the image (0-based) caption_text: Caption text caption_type: Type of caption (Figure, Table, Equation)

Returns: Dictionary with status

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filepathYes
image_indexYes
caption_textYes
caption_typeNoFigure

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The implementation of the add_image_caption tool, which adds a caption to an image in a Word document.
    def add_image_caption(
        filepath: str,
        image_index: int,
        caption_text: str,
        caption_type: str = "Figure",
    ) -> dict[str, Any]:
        """
        Add a caption to an image in the document.
    
        Args:
            filepath: Path to the document
            image_index: Index of the image (0-based)
            caption_text: Caption text
            caption_type: Type of caption (Figure, Table, Equation)
    
        Returns:
            Dictionary with status
        """
        logger.info("Adding image caption", extra={"tool": "add_image_caption", "filepath": filepath})
    
        try:
            doc = safe_open_document(filepath)
    
            # Find image location (simplified - assumes last paragraph with image)
            # In a production system, would need more robust image tracking
            if len(doc.paragraphs) > 0:
                # Add caption paragraph after last paragraph
                caption_paragraph = doc.add_paragraph()
                caption_run = caption_paragraph.add_run(f"{caption_type}: {caption_text}")
                caption_run.italic = True
                caption_paragraph.style = "Caption"
    
                safe_save_document(doc, filepath)
                logger.info("Caption added successfully", extra={"filepath": filepath})
    
                return {
                    "status": "success",
                    "filepath": filepath,
                    "caption": caption_text,
                    "message": "Caption added successfully",
                }
            else:
                raise DocumentError("Document has no paragraphs", filepath)
        except DocxMcpError as e:
            logger.warning(e.message, extra={"tool": "add_image_caption", "error_code": e.error_code})
            return {"status": "error", "error": e.message, "error_code": e.error_code}
        except Exception as e:
  • The registration of the add_image_caption tool using the @app.tool() decorator.
    @app.tool()
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 a caption but does not clarify whether this modifies the document in place, requires specific permissions, handles errors (e.g., invalid filepath or image index), or has side effects like overwriting existing captions. The mention of a return 'Dictionary with status' hints at some feedback but lacks detail on success/failure indicators.

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 and front-loaded with the core purpose in the first sentence. The 'Args' and 'Returns' sections organize information efficiently, avoiding redundancy. However, the 'Returns' section is vague ('Dictionary with status'), which slightly reduces clarity, but overall, the text is concise with minimal waste.

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 tool's moderate complexity (4 parameters, no annotations, but with an output schema), the description is partially complete. It covers the basic action and parameters but lacks behavioral details (e.g., error handling, side effects) and usage guidelines. The presence of an output schema means the description does not need to explain return values in detail, but it still falls short in providing full context for safe and effective use.

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?

Schema description coverage is 0%, meaning parameters are undocumented in the schema. The description compensates by listing each parameter with brief explanations (e.g., 'Path to the document' for filepath), adding basic semantics. However, it does not provide deeper context such as file format expectations, valid ranges for image_index, or examples for caption_type beyond the default 'Figure'. This partial compensation justifies a baseline score of 3.

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 tool's purpose: 'Add a caption to an image in the document.' It specifies the verb ('Add'), resource ('caption'), and target ('image in the document'), making the action unambiguous. However, it does not explicitly differentiate from sibling tools like 'insert_image' or 'extract_images', which is why it scores a 4 instead of a 5.

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., document must exist), exclusions, or comparisons to sibling tools like 'insert_image' (which might add images without captions) or 'list_images' (which could help identify image indices). This lack of context leaves the agent to infer usage scenarios.

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/Andrew82106/LLM_Docx_Agent_MCP'

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