Skip to main content
Glama
GongRzhe

Office Word MCP Server

set_table_alignment_all

Align text horizontally and vertically in all cells of a Word document table to improve readability and formatting consistency.

Instructions

Set text alignment for all cells in a table.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filenameYes
table_indexYes
horizontalNoleft
verticalNotop

Implementation Reference

  • Registers the MCP tool 'set_table_alignment_all' with FastMCP and delegates execution to the format_tools implementation.
    @mcp.tool()
    def set_table_alignment_all(filename: str, table_index: int, 
                              horizontal: str = "left", vertical: str = "top"):
        """Set text alignment for all cells in a table."""
        return format_tools.set_table_alignment_all(filename, table_index, horizontal, vertical)
  • Executes the tool logic: validates inputs, loads the Word document using python-docx, retrieves the specified table, calls the core set_table_alignment helper, and saves the modified document.
    async def set_table_alignment_all(filename: str, table_index: int, 
                                    horizontal: str = "left", vertical: str = "top") -> str:
        """Set text alignment for all cells in a table.
        
        Args:
            filename: Path to the Word document
            table_index: Index of the table (0-based)
            horizontal: Horizontal alignment ("left", "center", "right", "justify")
            vertical: Vertical alignment ("top", "center", "bottom")
        """
        filename = ensure_docx_extension(filename)
        
        # Ensure numeric parameters are the correct type
        try:
            table_index = int(table_index)
        except (ValueError, TypeError):
            return "Invalid parameter: table_index must be an integer"
        
        # Validate alignment parameters
        valid_horizontal = ["left", "center", "right", "justify"]
        valid_vertical = ["top", "center", "bottom"]
        
        if horizontal.lower() not in valid_horizontal:
            return f"Invalid horizontal alignment. Valid options: {', '.join(valid_horizontal)}"
        
        if vertical.lower() not in valid_vertical:
            return f"Invalid vertical alignment. Valid options: {', '.join(valid_vertical)}"
        
        if not os.path.exists(filename):
            return f"Document {filename} does not exist"
        
        # Check if file is writeable
        is_writeable, error_message = check_file_writeable(filename)
        if not is_writeable:
            return f"Cannot modify document: {error_message}. Consider creating a copy first."
        
        try:
            doc = Document(filename)
            
            # Validate table index
            if table_index < 0 or table_index >= len(doc.tables):
                return f"Invalid table index. Document has {len(doc.tables)} tables (0-{len(doc.tables)-1})."
            
            table = doc.tables[table_index]
            
            # Apply table alignment
            success = set_table_alignment(table, horizontal, vertical)
            
            if success:
                doc.save(filename)
                return f"Table alignment set successfully for table {table_index} to {horizontal}/{vertical} for all cells."
            else:
                return f"Failed to set table alignment."
        except Exception as e:
            return f"Failed to set table alignment: {str(e)}"
  • Low-level helper that applies the specified horizontal and vertical alignment to every cell in the table by calling set_cell_alignment on each.
    def set_table_alignment(table, horizontal="left", vertical="top"):
        """
        Set text alignment for all cells in a table.
        
        Args:
            table: The table to format
            horizontal: Horizontal alignment ("left", "center", "right", "justify")
            vertical: Vertical alignment ("top", "center", "bottom")
            
        Returns:
            True if successful, False otherwise
        """
        try:
            for row in table.rows:
                for cell in row.cells:
                    set_cell_alignment(cell, horizontal, vertical)
            return True
        except Exception as e:
            print(f"Error setting table alignment: {e}")
            return False
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It states the action ('Set') but doesn't disclose behavioral traits such as whether this is a mutation, what permissions are required, if changes are reversible, or how errors are handled. For a tool with 4 parameters and no annotations, this is a significant gap in transparency.

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, clear sentence with zero waste—it directly states the tool's purpose without unnecessary words. It's appropriately sized and front-loaded, making it easy to parse quickly.

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?

Given the complexity (4 parameters, no annotations, no output schema), the description is incomplete. It lacks details on parameter usage, behavioral context, and output expectations, making it inadequate for an agent to use the tool effectively without additional inference or trial-and-error.

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?

Schema description coverage is 0%, so the schema provides no parameter details. The description adds no information about parameters like 'filename', 'table_index', 'horizontal', or 'vertical', failing to compensate for the coverage gap. It doesn't explain what these parameters mean or how they should be used.

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 ('Set text alignment') and target ('for all cells in a table'), which is specific and actionable. It distinguishes from sibling tools like 'set_table_cell_alignment' by specifying 'all cells' versus individual cells. However, it doesn't explicitly mention the resource (e.g., document or file) beyond the implied context from parameters.

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?

No guidance is provided on when to use this tool versus alternatives like 'set_table_cell_alignment' or 'format_table'. The description implies bulk alignment but doesn't specify scenarios, prerequisites, or exclusions, leaving the agent to infer usage from the name alone.

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