read_excel_by_sheet_name
Extract data from a specific sheet in Excel files by specifying the sheet name. If no sheet name is provided, it defaults to reading the first sheet. Results are returned in structured JSON format.
Instructions
Read content from a specific sheet by name in Excel (xlsx) files. Reads first sheet if sheet_name not provided.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | Path to the Excel file | |
| sheet_name | No | Name of the sheet to read (optional, defaults to first sheet) |
Implementation Reference
- Handler logic that selects the Excel sheet by name (defaults to first sheet), reads all rows converting cell values to strings, and populates the result dictionary.elif name == "read_excel_by_sheet_name": # Get sheet by name, default to first sheet if not specified sheet_name = arguments.get("sheet_name") if not sheet_name: sheet_name = workbook.sheetnames[0] elif sheet_name not in workbook.sheetnames: raise ValueError(f"Sheet '{sheet_name}' not found in workbook") 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
- src/excel_reader_server/server.py:33-50 (registration)Registration of the 'read_excel_by_sheet_name' tool in the MCP server's list_tools handler, including name, description, and input schema.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"] } ),
- JSON Schema defining the input parameters for the tool: required 'file_path' string and optional 'sheet_name' string.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"] }