Skip to main content
Glama

copy_worksheet

Duplicate a worksheet within an Excel workbook by specifying source and target sheet names, enabling efficient data organization and management.

Instructions

Copy worksheet within workbook.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filepathYes
source_sheetYes
target_sheetYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • MCP tool handler for 'copy_worksheet'. Registers the tool via @mcp.tool() decorator and delegates to copy_sheet helper function from sheet.py. Defines input parameters: filepath, source_sheet, target_sheet.
    @mcp.tool()
    def copy_worksheet(
        filepath: str,
        source_sheet: str,
        target_sheet: str
    ) -> str:
        """Copy worksheet within workbook."""
        try:
            full_path = get_excel_path(filepath)
            result = copy_sheet(full_path, source_sheet, target_sheet)
            return result["message"]
        except (ValidationError, SheetError) as e:
            return f"Error: {str(e)}"
        except Exception as e:
            logger.error(f"Error copying worksheet: {e}")
            raise
  • Core helper function implementing the worksheet copy logic using openpyxl's Workbook.copy_worksheet() method. Performs validation and saves the workbook.
    def copy_sheet(filepath: str, source_sheet: str, target_sheet: str) -> Dict[str, Any]:
        """Copy a worksheet within the same workbook."""
        try:
            wb = load_workbook(filepath)
            if source_sheet not in wb.sheetnames:
                raise SheetError(f"Source sheet '{source_sheet}' not found")
                
            if target_sheet in wb.sheetnames:
                raise SheetError(f"Target sheet '{target_sheet}' already exists")
                
            source = wb[source_sheet]
            target = wb.copy_worksheet(source)
            target.title = target_sheet
            
            wb.save(filepath)
            return {"message": f"Sheet '{source_sheet}' copied to '{target_sheet}'"}
        except SheetError as e:
            logger.error(str(e))
            raise
        except Exception as e:
            logger.error(f"Failed to copy sheet: {e}")
            raise SheetError(str(e))
  • The @mcp.tool() decorator registers the copy_worksheet function as an MCP tool.
    @mcp.tool()
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 offers minimal behavioral insight. 'Copy' implies a read-and-write operation, but it doesn't disclose whether this requires file permissions, if it overwrites existing sheets, what happens on errors, or the output format. For a mutation tool with zero annotation coverage, this leaves critical behavioral traits unspecified.

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 zero wasted words. It's front-loaded with the core action and resource, making it easy to parse quickly. Every word earns its place by conveying essential information without redundancy.

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

Completeness3/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 (3 parameters, mutation operation) and the presence of an output schema (which likely handles return values), the description is minimally adequate. However, with no annotations and low schema coverage, it should provide more context on usage, behavioral traits, and parameter details to be fully complete for safe agent operation.

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 details. The description mentions 'worksheet within workbook', which hints at the 'source_sheet' and 'target_sheet' parameters but doesn't explain 'filepath' or provide any syntax/format guidance. It adds marginal value over the bare schema, compensating slightly but not fully for the coverage gap.

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 ('copy') and resource ('worksheet within workbook'), making the purpose immediately understandable. It distinguishes from siblings like 'rename_worksheet' or 'create_worksheet' by focusing on duplication rather than creation or renaming. However, it doesn't explicitly differentiate from 'copy_range', which might cause confusion 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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., existing workbook/sheet), exclusions, or compare with siblings like 'copy_range' (for partial data) or 'create_worksheet' (for new sheets). Without this context, the agent must infer usage from the name alone.

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