Skip to main content
Glama
GongRzhe

Office Word MCP Server

get_paragraph_text_from_document

Extract text from a specific paragraph in a Word document by specifying the filename and paragraph index.

Instructions

Get text from a specific paragraph in a Word document.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filenameYes
paragraph_indexYes

Implementation Reference

  • Tool registration using FastMCP @mcp.tool() decorator. This sync wrapper delegates to the async implementation in extended_document_tools.
    @mcp.tool()
    def get_paragraph_text_from_document(filename: str, paragraph_index: int):
        """Get text from a specific paragraph in a Word document."""
        return extended_document_tools.get_paragraph_text_from_document(filename, paragraph_index)
  • Async wrapper function that handles file validation, calls the core get_paragraph_text utility, and returns JSON-formatted result.
    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)}"
  • Core implementation: Loads the DOCX using python-docx, retrieves the specific paragraph, extracts text, style, and heading status, returns as 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 full burden for behavioral disclosure. While 'Get text' implies a read-only operation, it doesn't specify whether this requires document access permissions, how paragraph indexing works (0-based vs 1-based), what happens with invalid indices, or if there are rate limits. The description provides basic intent but lacks important operational details.

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, efficient sentence that directly states the tool's purpose without unnecessary words. It's appropriately sized for a simple retrieval tool and front-loads the core functionality immediately.

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?

For a tool with 2 parameters (0% schema coverage), no annotations, and no output schema, the description is inadequate. It doesn't explain parameter requirements, behavioral constraints, error conditions, or return format. Given the complexity of document processing and the lack of structured documentation elsewhere, the description should provide more operational 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?

With 0% schema description coverage for both parameters, the description provides no information about what 'filename' should contain (path, name, format) or how 'paragraph_index' is interpreted. The description mentions 'specific paragraph' but doesn't clarify indexing semantics or valid ranges, leaving parameters essentially undocumented.

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'), providing a specific verb+resource combination. However, it doesn't explicitly differentiate from sibling tools like 'get_document_text' or 'find_text_in_document', which offer different text extraction approaches.

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 like 'get_document_text' (for full document text) or 'find_text_in_document' (for text search). There's no mention of prerequisites, limitations, or appropriate contexts for paragraph-based extraction versus other text retrieval methods.

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/GongRzhe/Office-Word-MCP-Server'

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