Skip to main content
Glama
ishayoyo

Excel MCP Server

by ishayoyo

get_file_info

Analyze Excel or CSV file size and receive chunking recommendations to optimize large file processing for data analysis.

Instructions

Analyze file size and get chunking recommendations

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYesPath to the CSV or Excel file
sheetNoSheet name for Excel files (optional)

Implementation Reference

  • Main handler function for the 'get_file_info' tool. Validates input, calls the utility function, adds intelligent recommendations for large files and chunking, formats response as ToolResponse.
    async getFileInfo(args: ToolArgs): Promise<ToolResponse> {
      try {
        if (!args.filePath) {
          return {
            content: [
              {
                type: 'text',
                text: JSON.stringify({
                  success: false,
                  error: 'Missing required parameter: filePath',
                }, null, 2),
              },
            ],
          };
        }
    
        const { filePath, sheet } = args;
        const fileInfo = await getFileInfo(filePath, sheet);
    
        // Add additional recommendations based on file size
        let recommendations = [];
    
        if (fileInfo.estimatedTokens > 50000) {
          recommendations.push('Large file detected. Strongly recommend using chunked reading to avoid token limits.');
          recommendations.push(`Use read_file_chunked or read_file with offset/limit parameters.`);
        } else if (fileInfo.estimatedTokens > 20000) {
          recommendations.push('Medium-sized file. Consider chunked reading for better performance.');
        } else {
          recommendations.push('File size is manageable for direct reading.');
        }
    
        recommendations.push(`Recommended chunk size: ${fileInfo.recommendedChunkSize} rows per chunk.`);
    
        if (fileInfo.sheets && fileInfo.sheets.length > 1) {
          recommendations.push(`Excel file contains ${fileInfo.sheets.length} sheets. Specify 'sheet' parameter to read specific sheets.`);
        }
    
        const response = {
          success: true,
          fileInfo: {
            ...fileInfo,
            fileSizeMB: Math.round((fileInfo.fileSize / 1024 / 1024) * 100) / 100,
          },
          recommendations,
          chunkingAdvice: {
            useChunking: fileInfo.estimatedTokens > 20000,
            optimalChunkSize: fileInfo.recommendedChunkSize,
            estimatedChunks: Math.ceil(fileInfo.totalRows / fileInfo.recommendedChunkSize),
            maxTokensPerChunk: Math.ceil((fileInfo.recommendedChunkSize * fileInfo.totalColumns * 10) / 4),
          }
        };
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(response, null, 2),
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify({
                success: false,
                error: error instanceof Error ? error.message : 'Unknown error occurred',
              }, null, 2),
            },
          ],
        };
      }
    }
  • Input schema definition for the 'get_file_info' tool, defining parameters filePath (required) and sheet (optional).
      name: 'get_file_info',
      description: 'Analyze file size and get chunking recommendations',
      inputSchema: {
        type: 'object',
        properties: {
          filePath: {
            type: 'string',
            description: 'Path to the CSV or Excel file',
          },
          sheet: {
            type: 'string',
            description: 'Sheet name for Excel files (optional)',
          },
        },
        required: ['filePath'],
      },
    },
  • src/index.ts:1217-1218 (registration)
    Tool registration in the MCP server request handler switch statement, dispatching 'get_file_info' calls to DataOperationsHandler.getFileInfo method.
    case 'get_file_info':
      return await this.dataOpsHandler.getFileInfo(toolArgs);
  • Core utility function that computes FileInfo including file stats, row/column counts, token estimates, chunk recommendations for CSV and Excel files.
    export async function getFileInfo(filePath: string, sheet?: string): Promise<FileInfo> {
      const absolutePath = path.resolve(filePath);
      const stats = await fs.stat(absolutePath);
      const ext = path.extname(filePath).toLowerCase();
    
      // Get basic file info
      let totalRows = 0;
      let totalColumns = 0;
      let sheets: string[] = [];
    
      if (ext === '.csv') {
        // For CSV, we need to read to count rows (but efficiently)
        const content = await fs.readFile(absolutePath, 'utf-8');
        const lines = content.split('\n').filter(line => line.trim() !== '');
        totalRows = lines.length;
    
        // Estimate columns from first line
        if (lines.length > 0) {
          const firstLine = csv.parse(lines[0])[0];
          totalColumns = firstLine.length;
        }
      } else if (ext === '.xlsx' || ext === '.xls') {
        const workbook = new ExcelJS.Workbook();
        await workbook.xlsx.readFile(absolutePath);
    
        sheets = workbook.worksheets.map(ws => ws.name);
        const worksheet = workbook.getWorksheet(sheet || sheets[0]);
    
        if (worksheet) {
          totalRows = worksheet.rowCount;
          totalColumns = worksheet.columnCount;
        }
      }
    
      // Estimate token count (rough approximation)
      const avgCellLength = 10; // characters
      const estimatedTokens = Math.ceil((totalRows * totalColumns * avgCellLength) / 4); // ~4 chars per token
    
      // Calculate recommended chunk size (target ~8000 tokens per chunk)
      const targetTokens = 8000;
      const recommendedChunkSize = Math.max(100, Math.floor(targetTokens / (totalColumns * avgCellLength / 4)));
    
      return {
        filePath: absolutePath,
        fileSize: stats.size,
        totalRows,
        totalColumns,
        estimatedTokens,
        recommendedChunkSize: Math.min(recommendedChunkSize, 5000), // Cap at 5000 rows
        sheets: sheets.length > 0 ? sheets : undefined
      };
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions analysis and recommendations but lacks details on permissions, rate limits, response format, or whether this is a read-only operation. For a tool with no annotation coverage, this leaves significant gaps in understanding its behavior.

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 extremely concise with just one sentence that efficiently conveys the core functionality. It's front-loaded with key actions ('analyze', 'get') and avoids any redundant or verbose language, making it easy to parse quickly.

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

Completeness2/5

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

Given the complexity of file analysis and the lack of annotations and output schema, the description is incomplete. It doesn't explain what 'chunking recommendations' entail, the format of the analysis results, or how this tool differs from other file-related siblings, leaving the agent with insufficient context for effective use.

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?

Schema description coverage is 100%, so the schema already documents both parameters ('filePath' and 'sheet') adequately. The description doesn't add any parameter-specific details beyond what's in the schema, such as file format constraints or chunking criteria, resulting in a baseline score of 3.

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 tool's purpose with specific verbs ('analyze', 'get') and resources ('file size', 'chunking recommendations'), making it easy to understand what the tool does. However, it doesn't explicitly differentiate from sibling tools like 'read_file' or 'data_profile' that might also provide file information, preventing a perfect score.

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. With many sibling tools available (e.g., 'read_file', 'data_profile', 'get_headers'), there's no indication of specific contexts, prerequisites, or exclusions for using 'get_file_info', leaving the agent to guess based on tool names alone.

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

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