Skip to main content
Glama

create_workbook

Generate new Excel workbooks using a specified filepath. Enables efficient workbook creation and supports Excel file manipulation tasks.

Instructions

Create new Excel workbook.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filepathYes

Implementation Reference

  • MCP tool handler decorated with @mcp.tool(). Resolves the full file path using get_excel_path, imports and calls the workbook creation implementation, handles errors, and returns success or error message.
    @mcp.tool()
    def create_workbook(filepath: str) -> str:
        """Create new Excel workbook."""
        try:
            full_path = get_excel_path(filepath)
            from excel_mcp.workbook import create_workbook as create_workbook_impl
            create_workbook_impl(full_path)
            return f"Created workbook at {full_path}"
        except WorkbookError as e:
            return f"Error: {str(e)}"
        except Exception as e:
            logger.error(f"Error creating workbook: {e}")
            raise
  • Core implementation function that creates a new openpyxl Workbook instance, optionally renames the default sheet, ensures directory exists, saves the file, and returns a dictionary with message, active sheet, and workbook object.
    def create_workbook(filepath: str, sheet_name: str = "Sheet1") -> dict[str, Any]:
        """Create a new Excel workbook with optional custom sheet name"""
        try:
            wb = Workbook()
            # Rename default sheet
            if "Sheet" in wb.sheetnames:
                sheet = wb["Sheet"]
                sheet.title = sheet_name
            else:
                wb.create_sheet(sheet_name)
    
            path = Path(filepath)
            path.parent.mkdir(parents=True, exist_ok=True)
            wb.save(str(path))
            return {
                "message": f"Created workbook: {filepath}",
                "active_sheet": sheet_name,
                "workbook": wb
            }
        except Exception as e:
            logger.error(f"Failed to create workbook: {e}")
            raise WorkbookError(f"Failed to create workbook: {e!s}")

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