Skip to main content
Glama

write_excel

Convert and save CSV or JSON data into an Excel file, specifying the file path, sheet name, and format. Ideal for organizing and exporting structured data into spreadsheets.

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
dataYes
file_pathYes
formatNocsv
sheet_nameNoSheet1

Implementation Reference

  • The handler function for the 'write_excel' tool. Decorated with @mcp.tool() for registration in the FastMCP server. Parses input data as CSV or JSON into a Pandas DataFrame and writes it to the specified file in Excel (.xlsx, .xls, .xlsm), CSV, TSV, or JSON format.
    @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 in the FastMCP server instance.
    @mcp.tool()

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

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