Skip to main content
Glama

delete_worksheet

Remove a specified worksheet from an Excel workbook. Input filepath and sheet name to delete the desired sheet, streamlining workbook organization and management.

Instructions

Delete worksheet from workbook.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filepathYes
sheet_nameYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • MCP tool handler function for 'delete_worksheet' that validates input, resolves file path, calls the delete_sheet helper, and returns the result message or error.
    @mcp.tool()
    def delete_worksheet(
        filepath: str,
        sheet_name: str
    ) -> str:
        """Delete worksheet from workbook."""
        try:
            full_path = get_excel_path(filepath)
            result = delete_sheet(full_path, sheet_name)
            return result["message"]
        except (ValidationError, SheetError) as e:
            return f"Error: {str(e)}"
        except Exception as e:
            logger.error(f"Error deleting worksheet: {e}")
            raise
  • Core helper function implementing worksheet deletion using openpyxl: loads workbook, validates sheet existence and that it's not the last sheet, deletes the sheet, saves the file, and returns a success message.
    def delete_sheet(filepath: str, sheet_name: str) -> Dict[str, Any]:
        """Delete a worksheet from the workbook."""
        try:
            wb = load_workbook(filepath)
            if sheet_name not in wb.sheetnames:
                raise SheetError(f"Sheet '{sheet_name}' not found")
                
            if len(wb.sheetnames) == 1:
                raise SheetError("Cannot delete the only sheet in workbook")
                
            del wb[sheet_name]
            wb.save(filepath)
            return {"message": f"Sheet '{sheet_name}' deleted"}
        except SheetError as e:
            logger.error(str(e))
            raise
        except Exception as e:
            logger.error(f"Failed to delete sheet: {e}")
            raise SheetError(str(e))
  • The @mcp.tool() decorator registers the delete_worksheet function as an MCP tool.
    @mcp.tool()
    def delete_worksheet(
        filepath: str,
        sheet_name: str
    ) -> str:
        """Delete worksheet from workbook."""
        try:
            full_path = get_excel_path(filepath)
            result = delete_sheet(full_path, sheet_name)
            return result["message"]
        except (ValidationError, SheetError) as e:
            return f"Error: {str(e)}"
        except Exception as e:
            logger.error(f"Error deleting worksheet: {e}")
            raise
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 only states the basic action. It doesn't disclose critical behavioral traits: whether deletion is permanent or reversible, permission requirements, error conditions (e.g., if worksheet doesn't exist), or side effects on other workbook elements. For a destructive operation, 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 extremely concise—a single sentence with no wasted words. It's front-loaded with the core action, making it easy to parse quickly, though this brevity contributes to gaps in other dimensions.

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 the tool's destructive nature, no annotations, and 0% schema coverage, the description is incomplete. It doesn't explain parameters, behavioral implications, or usage context. The presence of an output schema helps with return values, but overall, the description lacks necessary details for safe and effective use.

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 0%, so the schema provides no parameter descriptions. The tool description doesn't mention parameters at all, failing to compensate for the coverage gap. However, with only 2 parameters and an output schema present, the baseline is slightly higher than minimal, but the description adds no value beyond the schema's structure.

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 ('Delete') and the resource ('worksheet from workbook'), which is specific and unambiguous. However, it doesn't differentiate from sibling tools like 'delete_range' or 'delete_sheet_columns', which also perform deletion operations on spreadsheet elements.

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., workbook must exist), exclusions, or compare it to similar tools like 'delete_range' or 'delete_sheet_rows', leaving the agent to infer usage context.

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

Related 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/haris-musa/excel-mcp-server'

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