Skip to main content
Glama

add_paragraph

Insert a paragraph into a Microsoft Word document. Specify the filename, text content, and optional style to enhance document formatting and structure.

Instructions

Add a paragraph to a Word document.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filenameYes
styleNo
textYes

Implementation Reference

  • MCP-registered tool handler for 'add_paragraph'. Loads document via resolver, adds paragraph with optional style application, handles errors, and saves the document.
    async def add_paragraph(filename: str, text: str, style: Optional[str] = None):
        """Add a paragraph to a Word document."""
        try:
            # Use resolver to find the document
            doc, resolved_path = load_document_with_resolver(filename)
            
            # Add the paragraph
            paragraph = doc.add_paragraph(text)
            
            # Apply style if provided
            if style:
                try:
                    paragraph.style = style
                except KeyError:
                    # Style doesn't exist, use normal and report it
                    paragraph.style = doc.styles['Normal']
                    # Save and return with warning
                    save_document_with_resolver(doc, filename, resolved_path)
                    return f"Paragraph added to {filename} with Normal style ('{style}' style not found)"
            
            # Save the document
            save_document_with_resolver(doc, filename, resolved_path)
            return f"Paragraph added to {filename}"
            
        except FileNotFoundError as e:
            return str(e)
        except Exception as e:
            return f"Failed to add paragraph: {str(e)}"
  • Supporting helper function implementing paragraph addition logic with file checks and style handling, used as reference or by other components.
    async def add_paragraph(filename: str, text: str, style: Optional[str] = None) -> str:
        """Add a paragraph to a Word document.
        
        Args:
            filename: Path to the Word document
            text: Paragraph text
            style: Optional paragraph style name
        """
        filename = ensure_docx_extension(filename)
        
        if not os.path.exists(filename):
            return f"Document {filename} does not exist"
        
        # Check if file is writeable
        is_writeable, error_message = check_file_writeable(filename)
        if not is_writeable:
            # Suggest creating a copy
            return f"Cannot modify document: {error_message}. Consider creating a copy first or creating a new document."
        
        try:
            doc = Document(filename)
            paragraph = doc.add_paragraph(text)
            
            if style:
                try:
                    paragraph.style = style
                except KeyError:
                    # Style doesn't exist, use normal and report it
                    paragraph.style = doc.styles['Normal']
                    doc.save(filename)
                    return f"Style '{style}' not found, paragraph added with default style to {filename}"
            
            doc.save(filename)
            return f"Paragraph added to {filename}"
        except Exception as e:
            return f"Failed to add paragraph: {str(e)}"
  • Re-export/registration of the add_paragraph function from content_tools module for convenient import in other parts of the codebase.
    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
    )
  • Type hints and docstring defining the input schema for the MCP tool.
    async def add_paragraph(filename: str, text: str, style: Optional[str] = None):
        """Add a paragraph to a Word document."""
Behavior2/5

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

No annotations are provided, so the description carries full burden. 'Add a paragraph' implies a write/mutation operation, but it doesn't disclose whether this requires document write permissions, whether it modifies the original file or creates a copy, what happens if the file doesn't exist, or how errors are handled. For a mutation tool with zero annotation coverage, this is a significant behavioral information gap.

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, clear sentence with zero wasted words. It's front-loaded with the core action and resource, making it immediately understandable. Every word earns its place, and there's no redundant information or unnecessary elaboration.

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 this is a mutation tool with no annotations, no output schema, 3 parameters with 0% schema description coverage, and multiple sibling tools offering similar functionality, the description is inadequate. It doesn't explain what the tool returns, error conditions, behavioral constraints, or how it differs from other paragraph insertion tools in the server.

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?

With 0% schema description coverage and 3 parameters (filename, style, text), the description adds minimal value beyond the schema. It implies 'text' is the paragraph content but doesn't explain 'style' parameter usage or format, whether 'filename' must include path/extension, or default behaviors. The description doesn't compensate for the complete lack of schema descriptions.

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 ('paragraph to a Word document'), making the purpose immediately understandable. It distinguishes itself from siblings like 'add_heading' or 'add_table' by specifying paragraph addition. However, it doesn't specify whether this adds to the end or at a specific position, leaving some ambiguity compared to more precise alternatives.

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. With siblings like 'insert_line_or_paragraph_near_text' and 'replace_paragraph_block_below_header' that might offer more precise paragraph insertion, there's no indication of when this simpler 'add_paragraph' is preferred. No prerequisites, constraints, or comparison to other paragraph-related tools 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/franlealp1/mcp-word'

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