Skip to main content
Glama

get_paragraph_text_from_document

Extract text from a specified paragraph in a Word document by providing the filename and paragraph index for precise content retrieval and management.

Instructions

Get text from a specific paragraph in a Word document.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filenameYes
paragraph_indexYes

Implementation Reference

  • Primary handler function implementing the tool logic: validates inputs, ensures file extension, loads via helper, serializes to JSON.
    async def get_paragraph_text_from_document(filename: str, paragraph_index: int) -> str:
        """Get text from a specific paragraph in a Word document.
        
        Args:
            filename: Path to the Word document
            paragraph_index: Index of the paragraph to retrieve (0-based)
        """
        filename = ensure_docx_extension(filename)
        
        if not os.path.exists(filename):
            return f"Document {filename} does not exist"
        
    
        if paragraph_index < 0:
            return "Invalid parameter: paragraph_index must be a non-negative integer"
        
        try:
            result = get_paragraph_text(filename, paragraph_index)
            return json.dumps(result, indent=2)
        except Exception as e:
            return f"Failed to get paragraph text: {str(e)}"
  • Tool registration using FastMCP @mcp.tool() decorator. Defines the tool endpoint with type hints and docstring for schema, delegates to implementation.
    async def get_paragraph_text_from_document(filename: str, paragraph_index: int):
        """Get text from a specific paragraph in a Word document."""
        return await extended_document_tools.get_paragraph_text_from_document(filename, paragraph_index)
  • Supporting utility that loads the Document object using python-docx, extracts paragraph by index, includes metadata like style and heading status, returns structured dict.
    def get_paragraph_text(doc_path: str, paragraph_index: int) -> Dict[str, Any]:
        """
        Get text from a specific paragraph in a Word document.
        
        Args:
            doc_path: Path to the Word document
            paragraph_index: Index of the paragraph to extract (0-based)
        
        Returns:
            Dictionary with paragraph text and metadata
        """
        import os
        if not os.path.exists(doc_path):
            return {"error": f"Document {doc_path} does not exist"}
        
        try:
            doc = Document(doc_path)
            
            # Check if paragraph index is valid
            if paragraph_index < 0 or paragraph_index >= len(doc.paragraphs):
                return {"error": f"Invalid paragraph index: {paragraph_index}. Document has {len(doc.paragraphs)} paragraphs."}
            
            paragraph = doc.paragraphs[paragraph_index]
            
            return {
                "index": paragraph_index,
                "text": paragraph.text,
                "style": paragraph.style.name if paragraph.style else "Normal",
                "is_heading": paragraph.style.name.startswith("Heading") if paragraph.style else False
            }
        except Exception as e:
            return {"error": f"Failed to get paragraph text: {str(e)}"}
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool reads text but doesn't clarify if it's read-only, what happens with invalid inputs (e.g., out-of-range paragraph indices), error handling, or output format (e.g., plain text vs. structured data). This leaves critical behavioral traits unspecified for a tool with parameters.

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 that front-loads the core functionality without unnecessary words. Every part of the sentence directly contributes to understanding the tool's purpose, making it highly efficient and well-structured.

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 has 2 parameters with 0% schema coverage, no annotations, and no output schema, the description is incomplete. It fails to address parameter semantics, behavioral expectations like error handling, or output details, leaving significant gaps for an AI agent to invoke it correctly in a document processing context.

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 for undocumented parameters. It mentions 'a specific paragraph' and 'Word document', hinting at 'paragraph_index' and 'filename', but provides no details on paragraph indexing (0-based vs. 1-based), filename requirements (path, extension), or supported document formats. This adds minimal semantic value beyond the schema's basic structure.

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 ('Get text') and target resource ('from a specific paragraph in a Word document'), making the tool's purpose immediately understandable. It distinguishes itself from sibling tools like 'get_document_text' (which retrieves all text) and 'find_text_in_document' (which searches content). However, it doesn't specify if it retrieves plain text or formatted text, leaving some ambiguity.

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 doesn't mention sibling tools like 'get_document_text' for full document extraction or 'find_text_in_document' for content-based searches, nor does it specify prerequisites such as document accessibility or paragraph indexing conventions.

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