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)

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