Skip to main content
Glama
GongRzhe

Office Word MCP Server

format_table_cell_text

Apply text formatting to specific table cells in Word documents, including bold, italic, underline, color, font size, and font name adjustments.

Instructions

Format text within a specific table cell.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filenameYes
table_indexYes
row_indexYes
col_indexYes
text_contentNo
boldNo
italicNo
underlineNo
colorNo
font_sizeNo
font_nameNo

Implementation Reference

  • Registration of the MCP tool 'format_table_cell_text' using @mcp.tool() decorator. This thin wrapper delegates to the async handler in format_tools.py.
    def format_table_cell_text(filename: str, table_index: int, row_index: int, col_index: int,
                               text_content: str = None, bold: bool = None, italic: bool = None,
                               underline: bool = None, color: str = None, font_size: int = None,
                               font_name: str = None):
        """Format text within a specific table cell."""
        return format_tools.format_table_cell_text(filename, table_index, row_index, col_index,
                                                   text_content, bold, italic, underline, color, font_size, font_name)
  • Core handler function executing the tool logic: input validation, document loading/saving, table/cell access, delegation to low-level helper.
    async def format_table_cell_text(filename: str, table_index: int, row_index: int, col_index: int,
                                     text_content: Optional[str] = None, bold: Optional[bool] = None, italic: Optional[bool] = None,
                                     underline: Optional[bool] = None, color: Optional[str] = None, font_size: Optional[int] = None,
                                     font_name: Optional[str] = None) -> str:
        """Format text within a specific table cell.
        
        Args:
            filename: Path to the Word document
            table_index: Index of the table (0-based)
            row_index: Row index (0-based)
            col_index: Column index (0-based)
            text_content: Optional new text content for the cell
            bold: Set text bold (True/False)
            italic: Set text italic (True/False)
            underline: Set text underlined (True/False)
            color: Text color (hex string like "FF0000" or color name like "red")
            font_size: Font size in points
            font_name: Font name/family
        """
        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)
            if font_size is not None:
                font_size = int(font_size)
        except (ValueError, TypeError):
            return "Invalid parameter: table_index, row_index, col_index must be integers, font_size must be 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]
            
            # 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 text formatting
            success = format_cell_text_by_position(table, row_index, col_index, text_content, 
                                                  bold, italic, underline, color, font_size, font_name)
            
            if success:
                doc.save(filename)
                format_desc = []
                if text_content is not None:
                    format_desc.append(f"content='{text_content[:30]}{'...' if len(text_content) > 30 else ''}'")
                if bold is not None:
                    format_desc.append(f"bold={bold}")
                if italic is not None:
                    format_desc.append(f"italic={italic}")
                if underline is not None:
                    format_desc.append(f"underline={underline}")
                if color is not None:
                    format_desc.append(f"color={color}")
                if font_size is not None:
                    format_desc.append(f"size={font_size}pt")
                if font_name is not None:
                    format_desc.append(f"font={font_name}")
                
                format_str = ", ".join(format_desc) if format_desc else "no changes"
                return f"Cell text formatted successfully in table {table_index}, cell ({row_index},{col_index}): {format_str}."
            else:
                return f"Failed to format cell text. Check that indices are valid."
        except Exception as e:
            return f"Failed to format cell text: {str(e)}"
  • Supporting utility that retrieves the specific table cell by position and delegates formatting to format_cell_text.
    def format_cell_text_by_position(table, row_index, col_index, text_content=None, 
                                     bold=None, italic=None, underline=None, color=None, 
                                     font_size=None, font_name=None):
        """
        Format text in a specific table cell by position.
        
        Args:
            table: The table containing the cell
            row_index: Row index (0-based)
            col_index: Column index (0-based)
            text_content: Optional new text content for the cell
            bold: Set text bold (True/False)
            italic: Set text italic (True/False)
            underline: Set text underlined (True/False)
            color: Text color (hex string or color name)
            font_size: Font size in points
            font_name: Font name/family
            
        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 format_cell_text(cell, text_content, bold, italic, underline, 
                                       color, font_size, font_name)
            else:
                return False
        except Exception as e:
            print(f"Error formatting cell text by position: {e}")
            return False
Behavior1/5

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

No annotations are provided, so the description carries full burden. It doesn't disclose any behavioral traits such as whether this is a mutation (likely), what permissions are needed, if changes are reversible, or how errors are handled. For a tool with 11 parameters and no annotations, this is a significant gap.

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 and appropriately sized for its content, though the brevity contributes to underspecification rather than conciseness alone.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness1/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity (11 parameters, no annotations, no output schema), the description is completely inadequate. It doesn't explain the tool's behavior, parameter usage, or expected outcomes, leaving critical gaps for an AI agent to understand and invoke it correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/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 meaning beyond the tool name—it doesn't explain what parameters like 'filename', 'table_index', or formatting options do, failing to compensate for the lack of schema documentation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Format text within a specific table cell' clearly states the action (format) and target (text in a table cell), but it's vague about what formatting options are available. It doesn't differentiate from sibling tools like 'format_text' or 'format_table', leaving ambiguity about scope.

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 'format_text' or 'format_table'. The description implies a specific context (table cells), but it doesn't mention prerequisites, exclusions, or comparisons to sibling tools, leaving usage unclear.

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