Skip to main content
Glama

update_table_title_tool

Change the title of a table in Google Sheets while preserving its structure and data. Specify spreadsheet, sheet, current table name, and new title to update.

Instructions

Update a table title in Google Sheets.

This tool allows you to update the title of an existing table.
The table structure and data remain unchanged.

Args:
    spreadsheet_name: Name of the spreadsheet
    sheet_name: Name of the sheet containing the table
    old_table_name: Current name of the table to update
    new_table_name: New title for the table

Returns:
    JSON string with success status and update details

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
spreadsheet_nameYesThe name of the Google Spreadsheet
sheet_nameYesThe name of the sheet containing the table
old_table_nameYesCurrent name of the table to update
new_table_nameYesNew title for the table

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Core handler function that implements the update table title logic. Validates inputs, checks for duplicates, retrieves IDs, and executes Google Sheets API batchUpdate with updateTable request to change the table name while preserving other properties.
    def update_table_title_handler(
        drive_service,
        sheets_service,
        spreadsheet_name: str,
        sheet_name: str,
        old_table_name: str,
        new_table_name: str
    ) -> str:
        """
        Update a table title in Google Sheets using the Google Sheets API updateTable request.
        
        This function validates inputs, checks for duplicates, and performs the update operation
        while preserving all other table properties (range, columns, data validation, etc.).
        
        Args:
            drive_service: Google Drive service instance
            sheets_service: Google Sheets service instance
            spreadsheet_name: Name of the spreadsheet
            sheet_name: Name of the sheet containing the table
            old_table_name: Current name of the table to update
            new_table_name: New title for the table
        
        Returns:
            JSON string with success status and update details
        """
        try:
            # Validate old table name
            if not old_table_name or old_table_name.strip() == "":
                return compact_json_response({
                    "success": False,
                    "message": "Old table name is required."
                })
            
            validated_old_table_name = old_table_name.strip()
            
            # Validate new table name
            if not new_table_name or new_table_name.strip() == "":
                return compact_json_response({
                    "success": False,
                    "message": "New table title is required."
                })
            
            new_table_validation = validate_table_name(new_table_name)
            if not new_table_validation["valid"]:
                return compact_json_response({
                    "success": False,
                    "message": new_table_validation["error"]
                })
            
            validated_new_table_name = new_table_validation["cleaned_name"]
            
            # Check if old and new names are the same
            if validated_old_table_name == validated_new_table_name:
                return compact_json_response({
                    "success": False,
                    "message": "Old and new table titles are the same."
                })
            
            # Get spreadsheet ID
            spreadsheet_id = get_spreadsheet_id_by_name(drive_service, spreadsheet_name)
            if not spreadsheet_id:
                return compact_json_response({
                    "success": False,
                    "message": f"Spreadsheet '{spreadsheet_name}' not found."
                })
            
            # Get sheet ID
            sheet_ids = get_sheet_ids_by_names(sheets_service, spreadsheet_id, [sheet_name])
            sheet_id = sheet_ids.get(sheet_name)
            if sheet_id is None:
                return compact_json_response({
                    "success": False,
                    "message": f"Sheet '{sheet_name}' not found in spreadsheet '{spreadsheet_name}'."
                })
            
            # Get table ID for the old table name
            table_ids = get_table_ids_by_names(sheets_service, spreadsheet_id, sheet_name, [validated_old_table_name])
            table_id = table_ids.get(validated_old_table_name)
            
            if table_id is None:
                return compact_json_response({
                    "success": False,
                    "message": f"Table '{validated_old_table_name}' not found in sheet '{sheet_name}'."
                })
            
            # Check for duplicate new table name (excluding the table being updated)
            duplicate_check = check_duplicate_table_name(sheets_service, spreadsheet_id, sheet_name, validated_new_table_name)
            if duplicate_check["has_duplicate"]:
                return compact_json_response({
                    "success": False,
                    "message": duplicate_check["error"]
                })
            
            # Create update request
            update_request = {
                "updateTable": {
                    "table": {
                        "tableId": table_id,
                        "name": validated_new_table_name
                    },
                    "fields": "name"
                }
            }
            
            # Execute the update
            try:
                response = sheets_service.spreadsheets().batchUpdate(
                    spreadsheetId=spreadsheet_id,
                    body={"requests": [update_request]}
                ).execute()
                
                # Extract response information
                replies = response.get("replies", [])
                if not replies:
                    return compact_json_response({
                        "success": False,
                        "message": "Failed to update table title - no response from API"
                    })
                
                # Check if the update was successful (the table title was actually changed)
                # Even if updateTable field is not in response, the operation might still be successful
                # We'll consider it successful if we get a reply and no error was thrown
                
                response_data = {
                    "success": True,
                    "spreadsheet_name": spreadsheet_name,
                    "sheet_name": sheet_name,
                    "old_table_name": validated_old_table_name,
                    "new_table_name": validated_new_table_name,
                    "table_id": table_id,
                    "message": f"Successfully updated table '{validated_old_table_name}' title to '{validated_new_table_name}' in '{sheet_name}'"
                }
                
                # Add warning if there was a warning during duplicate check
                if "warning" in duplicate_check:
                    response_data["warning"] = duplicate_check["warning"]
                
                return compact_json_response(response_data)
                
            except HttpError as error:
                error_details = error.error_details if hasattr(error, 'error_details') else str(error)
                return compact_json_response({
                    "success": False,
                    "message": f"Google Sheets API error: {error_details}"
                })
            
        except Exception as e:
            return compact_json_response({
                "success": False,
                "message": f"Unexpected error: {str(e)}"
            })
  • Tool registration using @mcp.tool() decorator. Defines input schema with Pydantic Field descriptions and serves as the entry point that initializes services and delegates to the handler.
    @mcp.tool()
    def update_table_title_tool(
        spreadsheet_name: str = Field(..., description="The name of the Google Spreadsheet"),
        sheet_name: str = Field(..., description="The name of the sheet containing the table"),
        old_table_name: str = Field(..., description="Current name of the table to update"),
        new_table_name: str = Field(..., description="New title for the table")
    ) -> str:
        """
        Update a table title in Google Sheets.
        
        This tool allows you to update the title of an existing table.
        The table structure and data remain unchanged.
        
        Args:
            spreadsheet_name: Name of the spreadsheet
            sheet_name: Name of the sheet containing the table
            old_table_name: Current name of the table to update
            new_table_name: New title for the table
        
        Returns:
            JSON string with success status and update details
        """
        sheets_service, drive_service = _get_google_services()
        return update_table_title_handler(drive_service, sheets_service, spreadsheet_name, sheet_name, old_table_name, new_table_name)
  • Input schema defined inline in the tool function using Pydantic BaseModel Field with descriptions for spreadsheet_name, sheet_name, old_table_name, new_table_name.
    @mcp.tool()
    def update_table_title_tool(
        spreadsheet_name: str = Field(..., description="The name of the Google Spreadsheet"),
        sheet_name: str = Field(..., description="The name of the sheet containing the table"),
        old_table_name: str = Field(..., description="Current name of the table to update"),
        new_table_name: str = Field(..., description="New title for the table")
    ) -> str:
        """
        Update a table title in Google Sheets.
        
        This tool allows you to update the title of an existing table.
        The table structure and data remain unchanged.
        
        Args:
            spreadsheet_name: Name of the spreadsheet
            sheet_name: Name of the sheet containing the table
            old_table_name: Current name of the table to update
            new_table_name: New title for the table
        
        Returns:
            JSON string with success status and update details
        """
        sheets_service, drive_service = _get_google_services()
        return update_table_title_handler(drive_service, sheets_service, spreadsheet_name, sheet_name, old_table_name, new_table_name)
Behavior3/5

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

With no annotations provided, the description carries the full burden. It discloses that this is a mutation tool ('update') and clarifies that only the title changes, not structure or data. However, it lacks details on permissions, error conditions, or rate limits, leaving behavioral gaps for an agent.

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 well-structured and front-loaded with the core purpose, followed by behavioral context and parameter details. Every sentence earns its place, with no redundant or verbose content, making it efficient for an agent to parse.

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

Completeness4/5

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

Given the tool's moderate complexity (mutation with 4 parameters), no annotations, and the presence of an output schema (which handles return values), the description is mostly complete. It covers purpose, behavior, and parameters, though it could benefit from more contextual details like authentication or error handling.

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

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all four parameters thoroughly. The description lists the parameters in the Args section but adds minimal semantic value beyond what the schema provides, such as clarifying that old_table_name is the 'current name' and new_table_name is the 'new title'.

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

Purpose5/5

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

The description clearly states the specific action ('update the title of an existing table') and resource ('table in Google Sheets'), distinguishing it from sibling tools like update_sheet_titles_tool or update_spreadsheet_title_tool. It explicitly mentions that only the title changes while 'table structure and data remain unchanged', providing precise scope.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for updating table titles in Google Sheets but does not explicitly state when to use this tool versus alternatives like update_sheet_titles_tool or update_spreadsheet_title_tool. It mentions the tool is for 'existing tables' but lacks guidance on prerequisites 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/henilcalagiya/google-sheets-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server