Skip to main content
Glama
marekrost

mcp-server-spreadsheet

read_range

Extract specific cell data from spreadsheet files by defining a rectangular range. Returns values as a structured 2D array with empty cells as null.

Instructions

Read a rectangular range of cells as a list of rows.

Returns a 2D array where each inner list is one row of values. Empty cells return null.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fileYesPath to the spreadsheet file
range_strYesCell range in A1 notation, e.g. 'A1:D10' or '$A$1:$D$10'
sheetNoSheet name. Defaults to the first sheet if omitted.

Implementation Reference

  • Implementation of the 'read_range' tool handler, which uses the mcp.tool decorator and interacts with openpyxl to read a spreadsheet range.
    @mcp.tool()
    def read_range(
        file: Annotated[str, Field(description="Path to the spreadsheet file")],
        range_str: Annotated[str, Field(description="Cell range in A1 notation, e.g. 'A1:D10' or '$A$1:$D$10'")],
        sheet: Annotated[str | None, Field(description="Sheet name. Defaults to the first sheet if omitted.")] = None,
    ) -> list[list]:
        """Read a rectangular range of cells as a list of rows.
    
        Returns a 2D array where each inner list is one row of values.
        Empty cells return null.
        """
        wb = load_workbook(file)
        ws = _resolve_sheet(wb, sheet)
        min_col, min_row, max_col, max_row = parse_range(range_str)
        rows = ws.iter_rows(
            min_row=min_row,
            max_row=max_row,
            min_col=min_col,
            max_col=max_col,
        )
        return [list(r) for r in rows]

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/marekrost/mcp-server-spreadsheet'

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