Skip to main content
Glama

write_excel

Export CSV or JSON data to Excel files with customizable sheet names for structured data storage and analysis.

Instructions

Write data to an Excel file.

Args:
    file_path: Path to save the Excel file
    data: Data in CSV or JSON format
    sheet_name: Name of the sheet (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 main handler function for the 'write_excel' tool. Decorated with @mcp.tool(), it reads input data as CSV or JSON into a pandas DataFrame and writes it to the specified file_path in Excel, CSV, TSV, or JSON format based on the extension. Returns success or error message.
    @mcp.tool()
    def write_excel(file_path: str, data: str, sheet_name: Optional[str] = "Sheet1", 
                  format: Optional[str] = "csv") -> str:
        """
        Write data to an Excel file.
        
        Args:
            file_path: Path to save the Excel file
            data: Data in CSV or JSON format
            sheet_name: Name of the sheet (for Excel files)
            format: Format of the input data ('csv' or 'json')
            
        Returns:
            Confirmation message
        """
        try:
            if format.lower() == 'csv':
                df = pd.read_csv(io.StringIO(data))
            elif format.lower() == 'json':
                df = pd.read_json(io.StringIO(data))
            else:
                return f"Unsupported data format: {format}"
            
            _, ext = os.path.splitext(file_path)
            ext = ext.lower()
            
            if ext in ['.xlsx', '.xls', '.xlsm']:
                df.to_excel(file_path, sheet_name=sheet_name, index=False)
            elif ext == '.csv':
                df.to_csv(file_path, index=False)
            elif ext == '.tsv':
                df.to_csv(file_path, sep='\t', index=False)
            elif ext == '.json':
                df.to_json(file_path, orient='records')
            else:
                return f"Unsupported output file extension: {ext}"
            
            return f"Successfully wrote data to {file_path}"
        except Exception as e:
            return f"Error writing data: {str(e)}"
  • The @mcp.tool() decorator registers the write_excel 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 the full burden of behavioral disclosure. It states the tool writes data but doesn't mention file overwriting behavior, permissions needed, error handling, or performance characteristics. The return value is vaguely described as 'Confirmation message' without details.

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 efficiently structured with a clear purpose statement followed by organized parameter and return sections. Every sentence earns its place, with no redundant or verbose language. The information is front-loaded and easy to parse.

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?

For a write operation with 4 parameters, no annotations, and no output schema, the description provides adequate basic information but lacks depth. It covers what the tool does and parameter meanings but misses behavioral details like file overwriting, error cases, or format specifics that would help an agent use it correctly.

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

Parameters4/5

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

The description adds significant value beyond the input schema, which has 0% description coverage. It explains all 4 parameters with brief but meaningful context: 'file_path' as the save location, 'data' as CSV/JSON content, 'sheet_name' for Excel organization, and 'format' specifying input type. This compensates well for the schema's lack of descriptions.

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 verb 'Write' and resource 'data to an Excel file', making the purpose immediately understandable. However, it doesn't explicitly differentiate this tool from sibling tools like 'update_excel' or 'export_chart', which might have overlapping functionality.

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 like 'update_excel' or 'export_chart'. It doesn't mention prerequisites, use cases, or exclusions, leaving the agent to guess based on tool names 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

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