read_docx
Extract text content and metadata from Word documents to access and analyze document information.
Instructions
Read and extract text content from a Word document.
Args: filepath: Path to the document to read
Returns: Dictionary with document text and metadata
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filepath | Yes |
Implementation Reference
- src/docx_mcp/server.py:103-132 (handler)The read_docx tool handler, which extracts text and document information.
@app.tool() def read_docx(filepath: str) -> dict[str, Any]: """ Read and extract text content from a Word document. Args: filepath: Path to the document to read Returns: Dictionary with document text and metadata """ logger.info("Reading document", extra={"tool": "read_docx", "filepath": filepath}) try: text = extract_all_text(filepath) doc_info = get_document_info(filepath) return { "status": "success", "filepath": filepath, "content": text, "info": doc_info, } except DocxMcpError as e: logger.warning(e.message, extra={"tool": "read_docx", "error_code": e.error_code}) return {"status": "error", "error": e.message, "error_code": e.error_code} except Exception as e: logger.error(f"Unexpected error reading document: {str(e)}") return {"status": "error", "error": str(e)}