list_styles
Retrieve all paragraph and character styles from a Microsoft Word document to analyze formatting options and maintain consistency.
Instructions
List all paragraph and character styles available in a document.
Args: filepath: Path to the document
Returns: Dictionary with list of styles
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filepath | Yes |
Implementation Reference
- src/docx_mcp/server.py:608-650 (handler)The implementation of the 'list_styles' tool, which is decorated with @app.tool() for MCP registration, and handles the logic for extracting and returning paragraph and character styles from a DOCX file.
@app.tool() def list_styles(filepath: str) -> dict[str, Any]: """ List all paragraph and character styles available in a document. Args: filepath: Path to the document Returns: Dictionary with list of styles """ logger.info("Listing styles", extra={"tool": "list_styles", "filepath": filepath}) try: doc = safe_open_document(filepath) styles = { "paragraph_styles": [], "character_styles": [], } # Get styles from style definitions for style in doc.styles: style_info = { "name": style.name, "type": str(style.type), } if style.type == 1: # Paragraph style styles["paragraph_styles"].append(style_info) elif style.type == 2: # Character style styles["character_styles"].append(style_info) return { "status": "success", "filepath": filepath, "styles": styles, "total_styles": len(list(doc.styles)), } except DocxMcpError as e: logger.warning(e.message, extra={"tool": "list_styles", "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 listing styles: {str(e)}")