Skip to main content
Glama

delete_table_tool

Remove specified tables from Google Sheets while preserving other content. Deletes table structure and data permanently from spreadsheets.

Instructions

Delete tables from Google Sheets.

This tool removes specified tables from a sheet while preserving other content.
The table structure and data will be permanently deleted.

Args:
    spreadsheet_name: Name of the spreadsheet
    sheet_name: Name of the sheet containing the tables
    table_names: List of table names to delete

Returns:
    JSON string with success status and deletion details

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
spreadsheet_nameYesThe name of the Google Spreadsheet
sheet_nameYesThe name of the sheet containing the tables
table_namesYesList of table names to delete (e.g., ['Project Tracker', 'Customer Data', 'Sales Report'])

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The core handler function that validates inputs, retrieves spreadsheet/sheet/table IDs using helper utilities, constructs deleteTable requests, executes batchUpdate on the Sheets API, and returns formatted JSON response.
    def delete_table_handler(
        drive_service,
        sheets_service,
        spreadsheet_name: str,
        sheet_name: str,
        table_names: List[str]
    ) -> str:
        """
        Delete tables from Google Sheets.
        
        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 tables
            table_names: List of table names to delete
        
        Returns:
            str: Success message with deletion details
        """
        try:
            # Validate inputs
            if not table_names or len(table_names) == 0:
                return compact_json_response({
                    "success": False,
                    "message": "At least one table name is required."
                })
            
            # Validate table names
            validated_table_names = []
            invalid_table_names = []
            
            for table_name in table_names:
                if not table_name or table_name.strip() == "":
                    invalid_table_names.append({"name": table_name, "error": "Table name cannot be empty"})
                    continue
                
                validated_name = table_name.strip()
                validated_table_names.append(validated_name)
            
            if invalid_table_names:
                error_messages = [f"'{item['name']}': {item['error']}" for item in invalid_table_names]
                return compact_json_response({
                    "success": False,
                    "message": f"Invalid table names: {'; '.join(error_messages)}",
                    "invalid_table_names": invalid_table_names
                })
            
            if not validated_table_names:
                return compact_json_response({
                    "success": False,
                    "message": "No valid table names provided after validation."
                })
            
            # Check for duplicate table names in the list
            seen_names = set()
            duplicate_names = []
            for table_name in validated_table_names:
                if table_name in seen_names:
                    duplicate_names.append(table_name)
                else:
                    seen_names.add(table_name)
            
            if duplicate_names:
                return compact_json_response({
                    "success": False,
                    "message": f"Duplicate table names in list: {', '.join(duplicate_names)}"
                })
            
            # 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 IDs
            table_ids = get_table_ids_by_names(sheets_service, spreadsheet_id, sheet_name, validated_table_names)
            
            # Filter out tables that don't exist
            existing_table_ids = []
            existing_table_names = []
            non_existent_tables = []
            
            for table_name in validated_table_names:
                table_id = table_ids.get(table_name)
                if table_id is not None:
                    existing_table_ids.append(table_id)
                    existing_table_names.append(table_name)
                else:
                    non_existent_tables.append(table_name)
            
            if not existing_table_ids:
                return compact_json_response({
                    "success": False,
                    "message": "No valid tables found to delete."
                })
            
            # Create delete requests
            delete_requests = []
            for table_id in existing_table_ids:
                delete_requests.append({
                    "deleteTable": {
                        "tableId": table_id
                    }
                })
            
            # Execute batch delete
            response = sheets_service.spreadsheets().batchUpdate(
                spreadsheetId=spreadsheet_id,
                body={"requests": delete_requests}
            ).execute()
            
            # Extract response information
            replies = response.get("replies", [])
            deleted_count = len(replies)
            
            response_data = {
                "success": True,
                "spreadsheet_name": spreadsheet_name,
                "sheet_name": sheet_name,
                "deleted_table_names": existing_table_names,
                "tables_deleted": deleted_count,
                "message": f"Successfully deleted {deleted_count} table(s) from '{sheet_name}'"
            }
            
            # Add information about non-existent tables
            if non_existent_tables:
                response_data["non_existent_tables"] = non_existent_tables
                response_data["message"] += f" (Skipped {len(non_existent_tables)} non-existent table(s))"
            
            return compact_json_response(response_data)
            
        except HttpError as error:
            return compact_json_response({
                "success": False,
                "message": f"Google Sheets API error: {str(error)}"
            })
        except Exception as e:
            return compact_json_response({
                "success": False,
                "message": f"Error deleting tables: {str(e)}"
            }) 
  • MCP tool registration with @mcp.tool() decorator, input schema definition using Pydantic Field descriptions, tool docstring, and thin wrapper that initializes services and delegates to the handler function.
    @mcp.tool()
    def delete_table_tool(
        spreadsheet_name: str = Field(..., description="The name of the Google Spreadsheet"),
        sheet_name: str = Field(..., description="The name of the sheet containing the tables"),
        table_names: List[str] = Field(..., description="List of table names to delete (e.g., ['Project Tracker', 'Customer Data', 'Sales Report'])")
    ) -> str:
        """
        Delete tables from Google Sheets.
        
        This tool removes specified tables from a sheet while preserving other content.
        The table structure and data will be permanently deleted.
        
        Args:
            spreadsheet_name: Name of the spreadsheet
            sheet_name: Name of the sheet containing the tables
            table_names: List of table names to delete
        
        Returns:
            JSON string with success status and deletion details
        """
        sheets_service, drive_service = _get_google_services()
        return delete_table_handler(drive_service, sheets_service, spreadsheet_name, sheet_name, table_names)
Behavior4/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. It effectively communicates that this is a destructive operation ('permanently deleted'), specifies what gets removed ('table structure and data'), and clarifies side effects ('preserving other content'). It doesn't mention permissions, rate limits, or error handling, but provides solid core behavioral context.

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 appropriately sized. It front-loads the core purpose in the first sentence, adds important behavioral context in the next two sentences, and efficiently documents parameters and returns in separate sections. Every sentence earns its place with no redundancy or fluff.

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?

For a destructive mutation tool with no annotations but with output schema (implied by 'Returns' statement), the description provides good coverage. It clearly explains the destructive nature, scope of deletion, and preservation behavior. The main gap is lack of explicit guidance on when to use versus sibling alternatives, but overall it's reasonably complete for the tool's complexity.

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 three parameters thoroughly. The description adds minimal value beyond the schema, listing parameters in the Args section but not providing additional context about format, constraints, or examples beyond what's in the schema descriptions. Baseline 3 is appropriate when schema does the heavy lifting.

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 tool's purpose with specific verb ('Delete'), resource ('tables from Google Sheets'), and scope ('removes specified tables from a sheet while preserving other content'). It distinguishes from sibling tools like delete_sheets_tool (which deletes entire sheets) and delete_table_records_tool (which deletes records within tables).

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 context through 'removes specified tables from a sheet while preserving other content,' suggesting this is for targeted table deletion rather than broader sheet operations. However, it lacks explicit guidance on when to use this versus alternatives like delete_sheets_tool or delete_table_records_tool, and doesn't mention 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