Skip to main content
Glama

read_excel_by_sheet_index

Extract data from a specific sheet in Excel files by specifying its index number. Reads the first sheet by default when no index is provided.

Instructions

Read content from a specific sheet by index in Excel (xlsx) files. Reads first sheet (index 0) if sheet_index not provided.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYesPath to the Excel file
sheet_indexNoIndex of the sheet to read (optional, defaults to 0)

Implementation Reference

  • Executes the tool logic: retrieves sheet by index (default 0), validates index, reads all rows into list of lists with string values, stores in result dict.
    elif name == "read_excel_by_sheet_index": # Get sheet by index, default to 0 if not specified sheet_index = arguments.get("sheet_index", 0) if sheet_index < 0 or sheet_index >= len(workbook.sheetnames): raise ValueError(f"Sheet index {sheet_index} is out of range") sheet_name = workbook.sheetnames[sheet_index] sheet = workbook[sheet_name] sheet_data = [] for row in sheet.rows: row_data = [str(cell.value) if cell.value is not None else "" for cell in row] sheet_data.append(row_data) result[sheet_name] = sheet_data
  • Input schema for the tool: requires file_path (string), optional sheet_index (integer >=0).
    types.Tool( name="read_excel_by_sheet_index", description="Read content from a specific sheet by index in Excel (xlsx) files. Reads first sheet (index 0) if sheet_index not provided.", inputSchema={ "type": "object", "properties": { "file_path": { "type": "string", "description": "Path to the Excel file" }, "sheet_index": { "type": "integer", "description": "Index of the sheet to read (optional, defaults to 0)", "minimum": 0 } }, "required": ["file_path"] } )
  • The tool is registered by including it in the list returned by @server.list_tools() handler.
    return [ types.Tool( name="read_excel", description="Read content from Excel (xlsx) files", inputSchema={ "type": "object", "properties": { "file_path": { "type": "string", "description": "Path to the Excel file" } }, "required": ["file_path"] } ), types.Tool( name="read_excel_by_sheet_name", description="Read content from a specific sheet by name in Excel (xlsx) files. Reads first sheet if sheet_name not provided.", inputSchema={ "type": "object", "properties": { "file_path": { "type": "string", "description": "Path to the Excel file" }, "sheet_name": { "type": "string", "description": "Name of the sheet to read (optional, defaults to first sheet)" } }, "required": ["file_path"] } ), types.Tool( name="read_excel_by_sheet_index", description="Read content from a specific sheet by index in Excel (xlsx) files. Reads first sheet (index 0) if sheet_index not provided.", inputSchema={ "type": "object", "properties": { "file_path": { "type": "string", "description": "Path to the Excel file" }, "sheet_index": { "type": "integer", "description": "Index of the sheet to read (optional, defaults to 0)", "minimum": 0 } }, "required": ["file_path"] } ) ]

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/softgridinc-pte-ltd/mcp-excel-reader-server'

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