Skip to main content
Glama
GongRzhe

Office Word MCP Server

set_table_cell_shading

Apply shading or fill color to a specific cell in a Microsoft Word table to highlight important data or improve document readability.

Instructions

Apply shading/filling to a specific table cell.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filenameYes
table_indexYes
row_indexYes
col_indexYes
fill_colorYes
patternNoclear

Implementation Reference

  • The primary asynchronous handler for the set_table_cell_shading tool. Handles input validation, document loading/saving, index validation, and delegates the actual shading to the core tables helper.
    async def set_table_cell_shading(filename: str, table_index: int, row_index: int, 
                                    col_index: int, fill_color: str, pattern: str = "clear") -> str:
        """Apply shading/filling to a specific table cell.
        
        Args:
            filename: Path to the Word document
            table_index: Index of the table (0-based)
            row_index: Row index of the cell (0-based)
            col_index: Column index of the cell (0-based)
            fill_color: Background color (hex string like "FF0000" or "red")
            pattern: Shading pattern ("clear", "solid", "pct10", "pct20", etc.)
        """
        filename = ensure_docx_extension(filename)
        
        # Ensure numeric parameters are the correct type
        try:
            table_index = int(table_index)
            row_index = int(row_index)
            col_index = int(col_index)
        except (ValueError, TypeError):
            return "Invalid parameter: table_index, row_index, and col_index must be integers"
        
        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]
            
            # Validate row and column indices
            if row_index < 0 or row_index >= len(table.rows):
                return f"Invalid row index. Table has {len(table.rows)} rows (0-{len(table.rows)-1})."
            
            if col_index < 0 or col_index >= len(table.rows[row_index].cells):
                return f"Invalid column index. Row has {len(table.rows[row_index].cells)} cells (0-{len(table.rows[row_index].cells)-1})."
            
            # Apply cell shading
            success = set_cell_shading_by_position(table, row_index, col_index, fill_color, pattern)
            
            if success:
                doc.save(filename)
                return f"Cell shading applied successfully to table {table_index}, row {row_index}, column {col_index}."
            else:
                return f"Failed to apply cell shading."
        except Exception as e:
            return f"Failed to apply cell shading: {str(e)}"
  • Registers the tool with the FastMCP server using the @mcp.tool() decorator. Provides a synchronous wrapper function that calls the async handler from format_tools.
    @mcp.tool()
    def set_table_cell_shading(filename: str, table_index: int, row_index: int, 
                              col_index: int, fill_color: str, pattern: str = "clear"):
        """Apply shading/filling to a specific table cell."""
        return format_tools.set_table_cell_shading(filename, table_index, row_index, col_index, fill_color, pattern)
  • Core utility function that locates the specific table cell by row and column indices and applies shading by calling the lower-level set_cell_shading function on the cell.
    def set_cell_shading_by_position(table, row_index, col_index, fill_color, pattern="clear"):
        """
        Apply shading to a specific cell by row/column position.
        
        Args:
            table: The table containing the cell
            row_index: Row index (0-based)
            col_index: Column index (0-based)
            fill_color: Background color (hex string)
            pattern: Shading pattern
            
        Returns:
            True if successful, False otherwise
        """
        try:
            if (0 <= row_index < len(table.rows) and 
                0 <= col_index < len(table.rows[row_index].cells)):
                cell = table.rows[row_index].cells[col_index]
                return set_cell_shading(cell, fill_color=fill_color, pattern=pattern)
            else:
                return False
        except Exception as e:
            print(f"Error setting cell shading by position: {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 the full burden of behavioral disclosure. 'Apply shading/filling' implies a mutation operation that modifies document content, but the description doesn't disclose whether this requires specific permissions, whether changes are reversible, what happens if the cell doesn't exist, or what the response looks like. For a mutation tool with zero annotation coverage, this is inadequate behavioral 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 extremely concise at just 6 words, with zero wasted language. It's front-loaded with the core action and target. Every word earns its place, making it easy to parse quickly. This is an example of excellent conciseness, though it may be too brief for complete understanding.

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 a mutation tool with 6 parameters, 0% schema coverage, no annotations, and no output schema, the description is insufficiently complete. It doesn't explain what happens when the tool executes, what errors might occur, what the return value is, or how to interpret the parameters. For a tool that modifies document content, this level of documentation is inadequate for safe and effective use.

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?

With 0% schema description coverage for all 6 parameters, the description provides no information about what any parameter means or how to use them. The description mentions 'shading/filling' which hints at 'fill_color' and possibly 'pattern', but doesn't explain what values are acceptable, what 'table_index' refers to, or how indices work. The description fails to compensate for the complete lack of schema documentation.

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 shading/filling') and target ('to a specific table cell'), which is a specific verb+resource combination. It distinguishes itself from sibling tools like 'format_table_cell_text' or 'highlight_table_header' by focusing specifically on cell shading rather than text formatting or header highlighting. However, it doesn't explicitly mention how it differs from other table formatting tools like 'format_table' or 'apply_table_alternating_rows'.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., document must exist, table must exist), when not to use it, or what alternatives exist for similar functionality. Given the many sibling tools for document manipulation, this lack of contextual guidance is a significant gap.

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