Skip to main content
Glama
GongRzhe

Office Word MCP Server

highlight_table_header

Apply distinct highlighting to table header rows in Microsoft Word documents to improve readability and visual organization of tabular data.

Instructions

Apply special highlighting to table header row.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filenameYes
table_indexYes
header_colorNo4472C4
text_colorNoFFFFFF

Implementation Reference

  • Registration of the 'highlight_table_header' tool using the @mcp.tool() decorator. This is a thin synchronous wrapper that delegates execution to the async implementation in format_tools.
    @mcp.tool()
    def highlight_table_header(filename: str, table_index: int, 
                             header_color: str = "4472C4", text_color: str = "FFFFFF"):
        """Apply special highlighting to table header row."""
        return format_tools.highlight_table_header(filename, table_index, header_color, text_color)
  • Main handler implementation: loads the Word document using python-docx, validates inputs, applies highlighting via helper function, and saves the modified document.
    async def highlight_table_header(filename: str, table_index: int, 
                                   header_color: str = "4472C4", text_color: str = "FFFFFF") -> str:
        """Apply special highlighting to table header row.
        
        Args:
            filename: Path to the Word document
            table_index: Index of the table (0-based)
            header_color: Background color for header (hex string, default blue)
            text_color: Text color for header (hex string, default white)
        """
        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 header highlighting
            success = highlight_header_row(table, header_color, text_color)
            
            if success:
                doc.save(filename)
                return f"Header highlighting applied successfully to table {table_index}."
            else:
                return f"Failed to apply header highlighting."
        except Exception as e:
            return f"Failed to apply header highlighting: {str(e)}"
  • Core helper function that applies background shading and bold white text formatting to the first row (header) cells of the table using direct XML manipulation and python-docx APIs.
    def highlight_header_row(table, header_color="4472C4", text_color="FFFFFF"):
        """
        Apply special shading to header row.
        
        Args:
            table: The table to format
            header_color: Background color for header (hex string)
            text_color: Text color for header (hex string)
            
        Returns:
            True if successful, False otherwise
        """
        try:
            if table.rows:
                for cell in table.rows[0].cells:
                    # Apply background shading
                    set_cell_shading(cell, fill_color=header_color)
                    
                    # Apply text formatting
                    for paragraph in cell.paragraphs:
                        for run in paragraph.runs:
                            run.bold = True
                            if text_color and text_color != "auto":
                                # Convert hex to RGB
                                try:
                                    text_color = text_color.lstrip('#')
                                    r = int(text_color[0:2], 16)
                                    g = int(text_color[2:4], 16)
                                    b = int(text_color[4:6], 16)
                                    run.font.color.rgb = RGBColor(r, g, b)
                                except:
                                    pass  # Skip if color format is invalid
            return True
        except Exception as e:
            print(f"Error highlighting header row: {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 mentions 'special highlighting' but doesn't clarify what that means operationally (e.g., whether it modifies the document permanently, requires specific permissions, or has side effects). 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?

The description is a single, efficient sentence with no wasted words. It's front-loaded with the core action and target, 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?

For a tool with 4 parameters, 0% schema coverage, no annotations, and no output schema, the description is insufficient. It doesn't explain the mutation behavior, parameter meanings, expected outcomes, or error conditions. Given the complexity and lack of structured data, more context is needed.

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 parameters are undocumented in the schema. The description mentions 'table header row' which hints at 'table_index' but doesn't explain any parameters explicitly. It doesn't clarify what 'filename' refers to, what 'header_color' and 'text_color' values represent (e.g., hex codes), or how 'table_index' works (e.g., zero-based).

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 special highlighting') and target ('table header row'), making the purpose immediately understandable. It doesn't differentiate from siblings like 'format_table' or 'set_table_cell_shading' which could also affect table appearance, but the specific focus on header rows is reasonably clear.

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 about when to use this tool versus alternatives like 'format_table' or 'set_table_cell_shading' which might offer similar functionality. The description doesn't mention prerequisites, constraints, or typical scenarios for applying header highlighting.

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