Skip to main content
Glama

get_data_validation_info

Extract and analyze data validation rules from an Excel worksheet to identify cell ranges and applied validation types. Returns results in JSON format for detailed insights.

Instructions

Get all data validation rules in a worksheet.

This tool helps identify which cell ranges have validation rules
and what types of validation are applied.

Args:
    filepath: Path to Excel file
    sheet_name: Name of worksheet
    
Returns:
    JSON string containing all validation rules in the worksheet

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filepathYes
sheet_nameYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function decorated with @mcp.tool(), implementing the core logic to load the workbook, retrieve validation rules using get_all_validation_ranges helper, and return JSON formatted results. This decorator also serves as the tool registration.
    @mcp.tool()
    def get_data_validation_info(
        filepath: str,
        sheet_name: str
    ) -> str:
        """
        Get all data validation rules in a worksheet.
        
        This tool helps identify which cell ranges have validation rules
        and what types of validation are applied.
        
        Args:
            filepath: Path to Excel file
            sheet_name: Name of worksheet
            
        Returns:
            JSON string containing all validation rules in the worksheet
        """
        try:
            full_path = get_excel_path(filepath)
            from openpyxl import load_workbook
            from excel_mcp.cell_validation import get_all_validation_ranges
            
            wb = load_workbook(full_path, read_only=False)
            if sheet_name not in wb.sheetnames:
                return f"Error: Sheet '{sheet_name}' not found"
                
            ws = wb[sheet_name]
            validations = get_all_validation_ranges(ws)
            wb.close()
            
            if not validations:
                return "No data validation rules found in this worksheet"
                
            import json
            return json.dumps({
                "sheet_name": sheet_name,
                "validation_rules": validations
            }, indent=2, default=str)
            
        except Exception as e:
            logger.error(f"Error getting validation info: {e}")
            raise
  • Helper function that iterates through all data validations in the worksheet, extracts key metadata including ranges, type, and for list validations the allowed values, returning a list of validation info dictionaries.
    def get_all_validation_ranges(worksheet: Worksheet) -> List[Dict[str, Any]]:
        """Get all data validation ranges in a worksheet.
        
        Returns:
            List of dictionaries containing validation range information
        """
        validations = []
        
        try:
            for dv in worksheet.data_validations.dataValidation:
                validation_info = {
                    "ranges": str(dv.sqref),
                    "validation_type": dv.type,
                    "allow_blank": dv.allowBlank,
                }
                
                if dv.type == "list" and dv.formula1:
                    validation_info["allowed_values"] = _extract_list_values(dv.formula1, worksheet)
                    
                validations.append(validation_info)
                
        except Exception as e:
            logger.warning(f"Failed to get validation ranges: {e}")
            
        return validations 
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden. It discloses that the tool retrieves information (non-destructive read operation) and returns a JSON string, but lacks details on permissions, error handling, rate limits, or what happens with invalid inputs. It adds basic context but misses key behavioral traits.

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 front-loaded with the core purpose, followed by a helper sentence, and then structured parameter and return sections. Every sentence earns its place with no wasted words, making it highly efficient and easy to scan.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (2 parameters, read-only operation) and the presence of an output schema (implied by 'Returns' statement), the description is fairly complete. It covers purpose, parameters, and return format, but could improve by addressing error cases or usage nuances relative to siblings.

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 schema description coverage is 0%, so the description must compensate. It explicitly lists and briefly explains both parameters ('filepath' and 'sheet_name'), adding meaning beyond the bare schema. However, it does not provide format details (e.g., filepath syntax, case sensitivity for sheet names), leaving some gaps.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Get all data validation rules') and resource ('in a worksheet'), distinguishing it from sibling tools like 'validate_excel_range' or 'get_merged_cells' by focusing on validation rules rather than other worksheet properties or validation actions.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for identifying cell ranges with validation rules and their types, but does not explicitly state when to use this tool versus alternatives like 'validate_excel_range' or provide exclusions. It offers some context but lacks explicit guidance on tool selection.

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

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

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