Skip to main content
Glama

apply_paragraph_style

Apply named paragraph styles like Heading 1 or Normal to specific paragraphs in Word documents to maintain consistent formatting and document structure.

Instructions

Apply a named paragraph style to a paragraph.

Args: filepath: Path to the document paragraph_index: Index of the paragraph (0-based) style_name: Name of the style to apply (e.g., "Heading 1", "Normal")

Returns: Dictionary with status

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filepathYes
paragraph_indexYes
style_nameYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler for the apply_paragraph_style tool, responsible for modifying the style of a specific paragraph in a DOCX document using the python-docx library.
    @app.tool()
    def apply_paragraph_style(filepath: str, paragraph_index: int, style_name: str) -> dict[str, Any]:
        """
        Apply a named paragraph style to a paragraph.
    
        Args:
            filepath: Path to the document
            paragraph_index: Index of the paragraph (0-based)
            style_name: Name of the style to apply (e.g., "Heading 1", "Normal")
    
        Returns:
            Dictionary with status
        """
        logger.info(
            "Applying paragraph style",
            extra={"tool": "apply_paragraph_style", "filepath": filepath},
        )
    
        try:
            doc = safe_open_document(filepath)
    
            if paragraph_index < 0 or paragraph_index >= len(doc.paragraphs):
                raise InvalidParameterError("paragraph_index", "Index out of range")
    
            paragraph = doc.paragraphs[paragraph_index]
            paragraph.style = style_name
    
            safe_save_document(doc, filepath)
            logger.info(f"Applied style {style_name} to paragraph", extra={"filepath": filepath})
    
            return {
                "status": "success",
                "filepath": filepath,
                "paragraph_index": paragraph_index,
                "style_applied": style_name,
            }
        except DocxMcpError as e:
            logger.warning(
                e.message,
                extra={"tool": "apply_paragraph_style", "error_code": e.error_code},
            )
            return {"status": "error", "error": e.message, "error_code": e.error_code}
        except Exception as e:
            logger.error(f"Unexpected error applying paragraph style: {str(e)}")
            return {"status": "error", "error": str(e)}
Behavior2/5

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

With no annotations provided, the description carries full burden but offers minimal behavioral insight. It states the action is 'Apply' (implying mutation) and mentions a return 'Dictionary with status', but lacks details on permissions needed, error conditions (e.g., invalid filepath or style), side effects, or rate limits. This is inadequate for a mutation tool without annotation support.

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 appropriately sized and front-loaded with the core purpose in the first sentence. The Args and Returns sections are structured for clarity, though the Returns section is vague ('Dictionary with status'). There's minimal fluff, but the formatting could be slightly more integrated (e.g., merging description with parameter details).

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 3 parameters with 0% schema coverage, no annotations, and an output schema (implied by 'Returns'), the description is moderately complete. It covers the basic operation and parameters but lacks behavioral context (e.g., error handling) and detailed output explanation. The output schema existence reduces the need to describe return values, but overall completeness is just adequate for a simple mutation tool.

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%, so the description must compensate but only partially does. It lists parameters in the Args section with brief examples (e.g., 'Heading 1', 'Normal'), adding some meaning beyond the bare schema. However, it doesn't explain parameter constraints (e.g., valid style names, paragraph index range) or interactions, leaving gaps in understanding.

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 ('Apply') and target ('a named paragraph style to a paragraph'), making the purpose evident. It distinguishes from siblings like 'apply_bullet_list' or 'apply_numbered_list' by focusing on paragraph styles rather than list formatting. However, it doesn't explicitly contrast with all siblings (e.g., 'set_list_level'), leaving minor room for improvement.

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?

No explicit guidance on when to use this tool versus alternatives is provided. The description mentions what it does but doesn't specify prerequisites (e.g., document must exist), when not to use it (e.g., for non-paragraph elements), or direct alternatives among siblings like 'list_styles' for style discovery. Usage is implied through parameter context only.

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