Skip to main content
Glama

read_excel

Extract data from Excel files by specifying file path, sheet name, row limits, and header configuration to convert spreadsheet content into readable text format.

Instructions

Read an Excel file and return its contents as a string.

Args:
    file_path: Path to the Excel file
    sheet_name: Name of the sheet to read (only for .xlsx, .xls)
    nrows: Maximum number of rows to read
    header: Row to use as header (0-indexed)
    
Returns:
    String representation of the Excel data

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes
sheet_nameNo
nrowsNo
headerNo

Implementation Reference

  • The @mcp.tool() decorated function that implements the 'read_excel' tool. It reads Excel (.xlsx, .xls, .xlsm), CSV, TSV, or JSON files using pandas and returns the DataFrame as a formatted string. Supports sheet selection, row limits, and custom headers. The decorator registers it as an MCP tool, and the docstring/signature provide the schema.
    @mcp.tool()
    def read_excel(file_path: str, sheet_name: Optional[str] = None, 
                 nrows: Optional[int] = None, header: Optional[int] = 0) -> str:
        """
        Read an Excel file and return its contents as a string.
        
        Args:
            file_path: Path to the Excel file
            sheet_name: Name of the sheet to read (only for .xlsx, .xls)
            nrows: Maximum number of rows to read
            header: Row to use as header (0-indexed)
            
        Returns:
            String representation of the Excel data
        """
        _, ext = os.path.splitext(file_path)
        ext = ext.lower()
        
        read_params = {"header": header}
        if nrows is not None:
            read_params["nrows"] = nrows
        
        if ext in ['.xlsx', '.xls', '.xlsm']:
            if sheet_name is not None:
                read_params["sheet_name"] = sheet_name
            df = pd.read_excel(file_path, **read_params)
        elif ext == '.csv':
            df = pd.read_csv(file_path, **read_params)
        elif ext == '.tsv':
            df = pd.read_csv(file_path, sep='\t', **read_params)
        elif ext == '.json':
            df = pd.read_json(file_path)
        else:
            return f"Unsupported file extension: {ext}"
        
        return df.to_string(index=False)
Behavior2/5

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

With no annotations provided, the description carries full burden but only states the basic action and return format. It misses critical behavioral details like error handling (e.g., invalid file paths), performance implications (e.g., large file handling), or side effects (e.g., file locking).

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 well-structured parameter list and return statement. Every sentence earns its place with no redundant information, making it efficient and easy to parse.

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

Completeness3/5

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

Given no annotations and no output schema, the description adequately covers parameters but lacks details on behavioral traits and output specifics. It's minimally viable for a read operation but could benefit from more context on limitations or usage scenarios.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description fully compensates by clearly explaining all four parameters, including their purposes and constraints (e.g., sheet_name only for .xlsx/.xls, header as 0-indexed). This adds essential meaning beyond the bare schema.

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 ('Read an Excel file') and the resource ('Excel file'), distinguishing it from siblings like write_excel or update_excel by focusing on data extraction rather than modification or analysis.

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

Usage Guidelines2/5

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

No guidance is provided on when to use this tool versus alternatives like analyze_excel or filter_excel. The description lacks context about use cases, prerequisites, or comparisons with sibling tools.

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

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