get_document_text
Extract all text from a Word document using a standardized MCP server tool. Input the filename to retrieve content efficiently for editing or analysis.
Instructions
Extract all text from a Word document.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filename | Yes |
Implementation Reference
- word_document_server/main.py:109-112 (registration)FastMCP tool registration for get_document_text, providing synchronous wrapper that delegates to the async implementation in document_tools.@mcp.tool() def get_document_text(filename: str): """Extract all text from a Word document.""" return document_tools.get_document_text(filename)
- Core asynchronous handler implementation for get_document_text tool, which normalizes filename and calls the text extraction utility.async def get_document_text(filename: str) -> str: """Extract all text from a Word document. Args: filename: Path to the Word document """ filename = ensure_docx_extension(filename) return extract_document_text(filename)
- Supporting utility that performs the actual text extraction from paragraphs and tables in the Word document.def extract_document_text(doc_path: str) -> str: """Extract all text from a Word document.""" import os if not os.path.exists(doc_path): return f"Document {doc_path} does not exist" try: doc = Document(doc_path) text = [] for paragraph in doc.paragraphs: text.append(paragraph.text) for table in doc.tables: for row in table.rows: for cell in row.cells: for paragraph in cell.paragraphs: text.append(paragraph.text) return "\n".join(text) except Exception as e: return f"Failed to extract text: {str(e)}"