Skip to main content
Glama
ArchimedesCrypto

MCP Excel Reader

read_excel

Extract structured data from Excel files by specifying file paths, sheet names, and row ranges for data analysis and processing.

Instructions

Read an Excel file and return its contents as structured data

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYesPath to the Excel file to read
sheetNameNoName of the sheet to read (optional)
startRowNoStarting row index (optional)
maxRowsNoMaximum number of rows to read (optional)

Implementation Reference

  • Core handler function that reads and parses the Excel file, computes chunks based on estimated size, and returns structured data including sheets, rows, and columns.
    private readExcelFile(args: ReadExcelArgs): ExcelData {
      const { filePath, sheetName, startRow = 0, maxRows } = args;
      if (!existsSync(filePath)) {
        throw new McpError(
          ErrorCode.InvalidRequest,
          `File not found: ${filePath}`
        );
      }
    
      try {
        // Read file as buffer first
        const data = readFileSync(filePath);
        const workbook = XLSX.read(data, {
          type: 'buffer',
          cellDates: true,
          cellNF: false,
          cellText: false,
          dateNF: 'yyyy-mm-dd'
        });
        const fileName = filePath.split(/[\\/]/).pop() || '';
        const selectedSheetName = sheetName || workbook.SheetNames[0];
        const worksheet = workbook.Sheets[selectedSheetName];
        const allData = XLSX.utils.sheet_to_json(worksheet, {
          raw: true,
          dateNF: 'yyyy-mm-dd'
        }) as Record<string, any>[];
    
        const totalRows = allData.length;
        const columns = totalRows > 0 ? Object.keys(allData[0] as object) : [];
        const totalColumns = columns.length;
    
        // Calculate chunk size based on data size
        let effectiveMaxRows = maxRows;
        if (!effectiveMaxRows) {
          const initialChunk = allData.slice(0, 100); // Sample first 100 rows
          if (initialChunk.length > 0) {
            effectiveMaxRows = calculateChunkSize(initialChunk, MAX_RESPONSE_SIZE);
          } else {
            effectiveMaxRows = 100; // Default if no data
          }
        }
    
        const endRow = Math.min(startRow + effectiveMaxRows, totalRows);
        const chunkData = allData.slice(startRow, endRow);
        
        const hasMore = endRow < totalRows;
        const nextChunk = hasMore ? {
          rowStart: endRow,
          columns
        } : undefined;
    
        return {
          fileName,
          totalSheets: workbook.SheetNames.length,
          currentSheet: {
            name: selectedSheetName,
            totalRows,
            totalColumns,
            chunk: {
              rowStart: startRow,
              rowEnd: endRow,
              columns,
              data: chunkData
            },
            hasMore,
            nextChunk
          }
        };
      } catch (error) {
        throw new McpError(
          ErrorCode.InternalError,
          `Error reading Excel file: ${error instanceof Error ? error.message : String(error)}`
        );
      }
    }
  • TypeScript interface defining the input arguments for the read_excel tool.
    interface ReadExcelArgs {
      filePath: string;
      sheetName?: string;
      startRow?: number;
      maxRows?: number;
    }
  • src/index.ts:170-199 (registration)
    Registration of the read_excel tool in the ListToolsRequestSchema handler, including name, description, and input schema.
    this.server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools: [
        {
          name: 'read_excel',
          description: 'Read an Excel file and return its contents as structured data',
          inputSchema: {
            type: 'object',
            properties: {
              filePath: {
                type: 'string',
                description: 'Path to the Excel file to read',
              },
              sheetName: {
                type: 'string',
                description: 'Name of the sheet to read (optional)',
              },
              startRow: {
                type: 'number',
                description: 'Starting row index (optional)',
              },
              maxRows: {
                type: 'number',
                description: 'Maximum number of rows to read (optional)',
              },
            },
            required: ['filePath'],
          },
        },
      ],
    }));
  • src/index.ts:201-235 (registration)
    Dispatch handler for CallToolRequestSchema that validates arguments, calls the readExcelFile handler, and returns the result for the read_excel tool.
    this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
      if (request.params.name !== 'read_excel') {
        throw new McpError(
          ErrorCode.MethodNotFound,
          `Unknown tool: ${request.params.name}`
        );
      }
    
      if (!isValidReadExcelArgs(request.params.arguments)) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'Invalid read_excel arguments'
        );
      }
    
      try {
        const data = this.readExcelFile(request.params.arguments);
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(data, null, 2),
            },
          ],
        };
      } catch (error) {
        if (error instanceof McpError) {
          throw error;
        }
        throw new McpError(
          ErrorCode.InternalError,
          `Unexpected error: ${error instanceof Error ? error.message : String(error)}`
        );
      }
    });
  • Type guard and validator function for ReadExcelArgs input.
    const isValidReadExcelArgs = (args: any): args is ReadExcelArgs =>
      typeof args === 'object' &&
      args !== null &&
      typeof args.filePath === 'string' &&
      (args.sheetName === undefined || typeof args.sheetName === 'string') &&
      (args.startRow === undefined || typeof args.startRow === 'number') &&
      (args.maxRows === undefined || typeof args.maxRows === 'number');
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions reading and returning data, implying a read-only operation, but fails to address critical aspects like error handling (e.g., what happens if the file doesn't exist or is corrupted), performance considerations, or format specifics of the returned structured data.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's purpose without any wasted words. It is appropriately sized and front-loaded with the core functionality.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (4 parameters, no output schema, no annotations), the description is minimally adequate. It covers the basic purpose but lacks details on behavioral traits and output format, which are important for a data-reading tool without structured output documentation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, so the input schema already documents all parameters thoroughly. The description adds no additional meaning beyond what the schema provides, such as examples or usage tips for the parameters, meeting the baseline for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('Read') and resource ('an Excel file') with the outcome ('return its contents as structured data'). It's specific about what the tool does, but since there are no sibling tools mentioned, it cannot demonstrate differentiation from alternatives.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives, prerequisites, or exclusions. It simply states what the tool does without context for usage decisions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/ArchimedesCrypto/excel-reader-mcp'

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