Skip to main content
Glama

get_workbook_metadata

Extract metadata from Excel workbooks, including sheet details and optional range information, using this tool to analyze and manage workbook structures efficiently.

Instructions

Get metadata about workbook including sheets, ranges, etc.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filepathYes
include_rangesNo

Implementation Reference

  • MCP tool handler function for get_workbook_metadata. Decorated with @mcp.tool() for registration and execution. Wraps get_workbook_info helper.
    @mcp.tool() def get_workbook_metadata( filepath: str, include_ranges: bool = False ) -> str: """Get metadata about workbook including sheets, ranges, etc.""" try: full_path = get_excel_path(filepath) result = get_workbook_info(full_path, include_ranges=include_ranges) return str(result) except WorkbookError as e: return f"Error: {str(e)}" except Exception as e: logger.error(f"Error getting workbook metadata: {e}") raise
  • Core helper function that loads the workbook using openpyxl and extracts metadata: filename, sheets list, file size, modification time, and optional used ranges per sheet.
    def get_workbook_info(filepath: str, include_ranges: bool = False) -> dict[str, Any]: """Get metadata about workbook including sheets, ranges, etc.""" try: path = Path(filepath) if not path.exists(): raise WorkbookError(f"File not found: {filepath}") wb = load_workbook(filepath, read_only=False) info = { "filename": path.name, "sheets": wb.sheetnames, "size": path.stat().st_size, "modified": path.stat().st_mtime } if include_ranges: # Add used ranges for each sheet ranges = {} for sheet_name in wb.sheetnames: ws = wb[sheet_name] if ws.max_row > 0 and ws.max_column > 0: ranges[sheet_name] = f"A1:{get_column_letter(ws.max_column)}{ws.max_row}" info["used_ranges"] = ranges wb.close() return info except WorkbookError as e: logger.error(str(e)) raise except Exception as e: logger.error(f"Failed to get workbook info: {e}") raise WorkbookError(str(e))

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