Skip to main content
Glama
GongRzhe

Office Word MCP Server

apply_table_alternating_rows

Apply alternating row colors to Word document tables to improve readability and visual distinction between rows.

Instructions

Apply alternating row colors to a table for better readability.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filenameYes
table_indexYes
color1NoFFFFFF
color2NoF2F2F2

Implementation Reference

  • MCP tool registration and handler function. Thin wrapper that delegates execution to format_tools.apply_table_alternating_rows.
    @mcp.tool()
    def apply_table_alternating_rows(filename: str, table_index: int, 
                                   color1: str = "FFFFFF", color2: str = "F2F2F2"):
        """Apply alternating row colors to a table for better readability."""
        return format_tools.apply_table_alternating_rows(filename, table_index, color1, color2)
  • Primary helper function implementing the tool logic: validates input, loads Word document using python-docx, retrieves specified table, calls core shading function, saves the modified document.
    async def apply_table_alternating_rows(filename: str, table_index: int, 
                                         color1: str = "FFFFFF", color2: str = "F2F2F2") -> str:
        """Apply alternating row colors to a table for better readability.
        
        Args:
            filename: Path to the Word document
            table_index: Index of the table (0-based)
            color1: Color for odd rows (hex string, default white)
            color2: Color for even rows (hex string, default light gray)
        """
        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"
        
        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 alternating row shading
            success = apply_alternating_row_shading(table, color1, color2)
            
            if success:
                doc.save(filename)
                return f"Alternating row shading applied successfully to table {table_index}."
            else:
                return f"Failed to apply alternating row shading."
        except Exception as e:
            return f"Failed to apply alternating row shading: {str(e)}"
  • Core utility function that implements the alternating row shading: loops through each row, selects alternating color, applies set_cell_shading to every cell in the row.
    def apply_alternating_row_shading(table, color1="FFFFFF", color2="F2F2F2"):
        """
        Apply alternating row colors for better readability.
        
        Args:
            table: The table to format
            color1: Color for odd rows (hex string)
            color2: Color for even rows (hex string)
            
        Returns:
            True if successful, False otherwise
        """
        try:
            for i, row in enumerate(table.rows):
                fill_color = color1 if i % 2 == 0 else color2
                for cell in row.cells:
                    set_cell_shading(cell, fill_color=fill_color)
            return True
        except Exception as e:
            print(f"Error applying alternating row shading: {e}")
            return False
Behavior2/5

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

With no annotations provided, the description carries full burden but offers minimal behavioral insight. It states the tool applies colors but doesn't disclose whether this modifies the document permanently, requires specific permissions, affects existing formatting, or provides any confirmation of success. For a mutation tool with zero annotation coverage, this is inadequate.

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?

Single sentence that is front-loaded with the core action and purpose, with zero redundant words. Every part of the description earns its place by conveying essential information efficiently.

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?

For a mutation tool with 4 parameters (2 required), 0% schema coverage, no annotations, and no output schema, the description is insufficient. It doesn't cover parameter meanings, behavioral implications, success indicators, or error conditions, leaving significant gaps for agent understanding.

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 description must compensate but adds no parameter information. It doesn't explain what 'filename' refers to (e.g., document path), how 'table_index' works (zero-based?), or that 'color1' and 'color2' are hex codes with defaults. This leaves all 4 parameters semantically unclear.

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 ('apply alternating row colors') and the resource ('to a table'), with the benefit 'for better readability' providing useful context. It distinguishes this from general table formatting tools like 'format_table' by specifying the specific visual enhancement.

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 explicit guidance on when to use this tool versus alternatives like 'highlight_table_header' or 'set_table_cell_shading' for other table styling. The description implies usage for readability improvement but doesn't specify prerequisites (e.g., requires an existing table) or exclusions.

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