Skip to main content
Glama

update_excel

Modify existing Excel files by adding new CSV or JSON data to specified sheets, enabling data updates without manual spreadsheet editing.

Instructions

Update an existing Excel file with new data.

Args:
    file_path: Path to the Excel file to update
    data: New data in CSV or JSON format
    sheet_name: Name of the sheet to update (for Excel files)
    format: Format of the input data ('csv' or 'json')
    
Returns:
    Confirmation message

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes
dataYes
sheet_nameNoSheet1
formatNocsv

Implementation Reference

  • The handler function for the 'update_excel' tool. Decorated with @mcp.tool() for automatic registration in FastMCP. Parses input data (CSV/JSON), handles multiple file formats (.xlsx, .csv, etc.), preserves other sheets in Excel files while updating the specified sheet, and returns success/error messages.
    @mcp.tool()
    def update_excel(file_path: str, data: str, sheet_name: Optional[str] = "Sheet1",
                   format: Optional[str] = "csv") -> str:
        """
        Update an existing Excel file with new data.
        
        Args:
            file_path: Path to the Excel file to update
            data: New data in CSV or JSON format
            sheet_name: Name of the sheet to update (for Excel files)
            format: Format of the input data ('csv' or 'json')
            
        Returns:
            Confirmation message
        """
        try:
            # Check if file exists
            if not os.path.exists(file_path):
                return f"File not found: {file_path}"
            
            # Load new data
            if format.lower() == 'csv':
                new_df = pd.read_csv(io.StringIO(data))
            elif format.lower() == 'json':
                new_df = pd.read_json(io.StringIO(data))
            else:
                return f"Unsupported data format: {format}"
            
            # Get file extension
            _, ext = os.path.splitext(file_path)
            ext = ext.lower()
            
            # Read existing file
            if ext in ['.xlsx', '.xls', '.xlsm']:
                # For Excel files, we need to read all sheets
                excel_file = pd.ExcelFile(file_path)
                with pd.ExcelWriter(file_path) as writer:
                    # Copy all existing sheets
                    for sheet in excel_file.sheet_names:
                        if sheet != sheet_name:
                            df = pd.read_excel(excel_file, sheet_name=sheet)
                            df.to_excel(writer, sheet_name=sheet, index=False)
                    
                    # Write new data to specified sheet
                    new_df.to_excel(writer, sheet_name=sheet_name, index=False)
            elif ext == '.csv':
                new_df.to_csv(file_path, index=False)
            elif ext == '.tsv':
                new_df.to_csv(file_path, sep='\t', index=False)
            elif ext == '.json':
                new_df.to_json(file_path, orient='records')
            else:
                return f"Unsupported file extension: {ext}"
            
            return f"Successfully updated {file_path}"
        except Exception as e:
            return f"Error updating file: {str(e)}"
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. While 'update' implies a mutation, it doesn't specify whether this overwrites existing data, appends to it, or modifies in place. It also lacks details on permissions, error handling, or what 'Confirmation message' entails, leaving significant gaps in understanding the tool's behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/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 parameter details. It uses bullet points for clarity and avoids unnecessary fluff. However, the 'Returns' section is vague ('Confirmation message'), which slightly reduces efficiency, but overall it's concise and organized.

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 complexity (4 parameters, mutation operation) and lack of annotations or output schema, the description is incomplete. It doesn't explain the update behavior (e.g., overwrite vs. append), error conditions, or what the return value contains. For a tool with no structured support, this leaves too many unknowns for 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?

The description lists all four parameters with brief explanations, but the input schema has 0% description coverage, meaning parameters are undocumented in the schema. The description adds basic semantics (e.g., 'Path to the Excel file to update'), but it doesn't fully compensate for the schema gap—details like data format specifics or sheet name constraints are missing, keeping it at a baseline level.

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 tool's purpose: 'Update an existing Excel file with new data.' It specifies the verb ('update') and resource ('Excel file'), making it easy to understand what the tool does. However, it doesn't explicitly differentiate from sibling tools like 'write_excel' or 'filter_excel', which prevents a perfect score.

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. With siblings like 'write_excel' and 'filter_excel' available, there's no indication of whether this tool is for appending data, overwriting, or modifying specific cells, nor any prerequisites or exclusions mentioned.

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/yzfly/mcp-excel-server'

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