get_range
Extract cell values from specified ranges in Excel or CSV files to access spreadsheet data for analysis or processing.
Instructions
Get values from a range of cells
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filePath | Yes | Path to the CSV or Excel file | |
| startCell | Yes | Start cell in A1 notation (e.g., "A1") | |
| endCell | Yes | End cell in A1 notation (e.g., "D10") | |
| sheet | No | Sheet name for Excel files (optional) |
Implementation Reference
- src/handlers/data-operations.ts:164-220 (handler)The core handler function implementing the get_range tool. Reads file content, parses A1 notation for start and end cells, validates the range, extracts the 2D array of values from the specified range, and returns formatted JSON response.async getRange(args: ToolArgs): Promise<ToolResponse> { try { const { filePath, startCell, endCell, sheet } = args; const data = await readFileContent(filePath, sheet); const start = parseA1Notation(startCell); const end = parseA1Notation(endCell); // Validate range if (start.row > end.row || start.col > end.col) { return { content: [ { type: 'text', text: JSON.stringify({ success: false, error: 'Invalid range: start cell must be before end cell', }, null, 2), }, ], }; } const rangeData = []; for (let row = start.row; row <= end.row && row < data.length; row++) { const rowData = []; for (let col = start.col; col <= end.col && col < (data[row]?.length || 0); col++) { rowData.push(data[row][col]); } rangeData.push(rowData); } return { content: [ { type: 'text', text: JSON.stringify({ success: true, range: `${startCell}:${endCell}`, data: rangeData, }, null, 2), }, ], }; } catch (error) { return { content: [ { type: 'text', text: JSON.stringify({ success: false, error: error instanceof Error ? error.message : 'Unknown error occurred', }, null, 2), }, ], }; } }
- src/index.ts:120-144 (schema)Input schema definition for the get_range tool, specifying parameters like filePath, startCell, endCell, and sheet with types and requirements.name: 'get_range', description: 'Get values from a range of cells', inputSchema: { type: 'object', properties: { filePath: { type: 'string', description: 'Path to the CSV or Excel file', }, startCell: { type: 'string', description: 'Start cell in A1 notation (e.g., "A1")', }, endCell: { type: 'string', description: 'End cell in A1 notation (e.g., "D10")', }, sheet: { type: 'string', description: 'Sheet name for Excel files (optional)', }, }, required: ['filePath', 'startCell', 'endCell'], }, },
- src/index.ts:1203-1205 (registration)Tool registration/dispatch in the MCP server request handler. Maps calls to 'get_range' to the DataOperationsHandler.getRange method.case 'get_range': return await this.dataOpsHandler.getRange(toolArgs); case 'get_headers':