Skip to main content
Glama

delete_paragraph

Remove a specific paragraph from a Microsoft Word document by specifying the filename and paragraph index. Streamline document editing and content management with this targeted tool.

Instructions

Delete a paragraph from a document.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filenameYes
paragraph_indexYes

Implementation Reference

  • The primary handler function for the 'delete_paragraph' tool. It loads the Word document, validates the paragraph index, removes the paragraph's underlying XML element using python-docx workaround, saves the document, and returns a status message.
    async def delete_paragraph(filename: str, paragraph_index: int) -> str:
        """Delete a paragraph from a document.
        
        Args:
            filename: Path to the Word document
            paragraph_index: Index of the paragraph to delete (0-based)
        """
        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:
            return f"Cannot modify document: {error_message}. Consider creating a copy first."
        
        try:
            doc = Document(filename)
            
            # Validate paragraph index
            if paragraph_index < 0 or paragraph_index >= len(doc.paragraphs):
                return f"Invalid paragraph index. Document has {len(doc.paragraphs)} paragraphs (0-{len(doc.paragraphs)-1})."
            
            # Delete the paragraph (by removing its content and setting it empty)
            # Note: python-docx doesn't support true paragraph deletion, this is a workaround
            paragraph = doc.paragraphs[paragraph_index]
            p = paragraph._p
            p.getparent().remove(p)
            
            doc.save(filename)
            return f"Paragraph at index {paragraph_index} deleted successfully."
        except Exception as e:
            return f"Failed to delete paragraph: {str(e)}"
  • Registration of content tools including 'delete_paragraph' by importing it from content_tools.py into the tools package __init__.py, making it available for MCP 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?

With no annotations provided, the description carries full burden but only states the basic action without disclosing critical behavioral traits. It does not mention permissions required, whether deletion is permanent or reversible, effects on document structure, error conditions, or any rate limits, which are essential for a destructive operation.

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, direct sentence with zero waste, front-loading the core action and resource efficiently. It is appropriately sized for the tool's apparent simplicity, 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 destructive nature, lack of annotations, no output schema, and low schema coverage, the description is incomplete. It fails to address safety, outcomes, error handling, or integration with sibling tools, leaving significant gaps for an AI agent to operate 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 but adds no meaning beyond the schema. It does not explain what 'filename' refers to (e.g., path, identifier) or how 'paragraph_index' is defined (e.g., zero-based, inclusive of headers), leaving parameters semantically ambiguous despite two required parameters.

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 ('Delete') and target resource ('a paragraph from a document'), making the purpose immediately understandable. However, it does not differentiate from sibling tools like 'delete_table' or 'replace_paragraph_block_below_header', which would require more specificity about scope or method to achieve a perfect score.

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 guidance is provided on when to use this tool versus alternatives such as 'delete_table', 'replace_paragraph_block_below_header', or other editing tools. The description lacks context about prerequisites, document states, or scenarios where deletion is appropriate, leaving usage unclear.

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