get_merged_cells
Retrieve all merged cell ranges from an Excel worksheet. Provide the file path and sheet name to get the merged cells.
Instructions
Get merged cells in a worksheet.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filepath | Yes | ||
| sheet_name | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/excel_mcp/server.py:570-585 (handler)The MCP tool handler function 'get_merged_cells' - decorated with @mcp.tool, it takes filepath and sheet_name, calls get_merged_ranges(), and returns the result as a string.
@mcp.tool( annotations=ToolAnnotations( title="Get Merged Cells", readOnlyHint=True, ), ) def get_merged_cells(filepath: str, sheet_name: str) -> str: """Get merged cells in a worksheet.""" try: full_path = get_excel_path(filepath) return str(get_merged_ranges(full_path, sheet_name)) except (ValidationError, SheetError) as e: return f"Error: {str(e)}" except Exception as e: logger.error(f"Error getting merged cells: {e}") raise - src/excel_mcp/sheet.py:246-259 (helper)The helper function 'get_merged_ranges' - loads the workbook, validates the sheet exists, and returns a list of merged cell range strings from worksheet.merged_cells.ranges.
def get_merged_ranges(filepath: str, sheet_name: str) -> list[str]: """Get merged cells in a worksheet.""" try: wb = load_workbook(filepath) if sheet_name not in wb.sheetnames: raise SheetError(f"Sheet '{sheet_name}' not found") worksheet = wb[sheet_name] return [str(merged_range) for merged_range in worksheet.merged_cells.ranges] except SheetError as e: logger.error(str(e)) raise except Exception as e: logger.error(f"Failed to get merged cells: {e}") raise SheetError(str(e)) - src/excel_mcp/server.py:570-575 (registration)Tool registration via @mcp.tool decorator with annotations including title 'Get Merged Cells' and readOnlyHint=True.
@mcp.tool( annotations=ToolAnnotations( title="Get Merged Cells", readOnlyHint=True, ), ) - src/excel_mcp/server.py:576-576 (schema)Function signature defines input schema: filepath: str and sheet_name: str; return type is str.
def get_merged_cells(filepath: str, sheet_name: str) -> str: