Skip to main content
Glama

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
NameRequiredDescriptionDefault
filepathYes

Implementation Reference

  • 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)}")

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/Andrew82106/LLM_Docx_Agent_MCP'

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