Skip to main content
Glama

excel_tool

Read and write Excel and CSV files, and convert JSON data to spreadsheet formats for data management and analysis tasks.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionYesAction to perform: read, write, or convert_json_to_xlsx
filePathYesAbsolute path to the input file
outputFilePathNoAbsolute path to the output file (required for write and convert actions)
formatYesFile format: xlsx, csv
dataNoData to write (required for write action)
optionsNoAdditional options

Implementation Reference

  • Main execution logic for the excel_tool, handling read, write, and convert_json_to_xlsx actions for XLSX and CSV files.
    export default async function (request: any) {
      try {
        const { action, filePath, outputFilePath, format, data, options } = request.params.arguments;
    
        // Validate file path
        if (!path.isAbsolute(filePath)) {
          throw new Error("Input filePath must be absolute");
        }
    
        // Check if file exists for read action
        if (action === "read" && !fs.existsSync(filePath)) {
          throw new Error(`Error: File not found - ${filePath}`);
        }
    
        if ((action === "write" || action === "convert_json_to_xlsx") && !outputFilePath) {
          throw new Error("outputFilePath is required for write and convert actions");
        }
    
        if (outputFilePath && !path.isAbsolute(outputFilePath)) {
          throw new Error("outputFilePath must be absolute");
        }
    
        if (action === "read") {
          // Read file logic
          switch (format) {
            case "xlsx":
              return readXLSX({ filePath, format });
            case "csv":
              return await readCSV({ filePath, format });
            default:
              throw new Error(`Unsupported format for read: ${format}`);
          }
        } else if (action === "write") {
          // Write file logic
          if (!data) {
            throw new Error("Data is required for write action");
          }
          switch (format) {
            case "xlsx":
              return writeXLSX({ filePath: outputFilePath, data, format, options });
            case "csv":
              return await writeCSV({ filePath: outputFilePath, data, format, options });
            default:
              throw new Error(`Unsupported format for write: ${format}`);
          }
        } else if (action === "convert_json_to_xlsx") {
          if (format !== 'xlsx') {
            throw new Error("convert_json_to_xlsx action only supports xlsx format");
          }
          const fileContent = fs.readFileSync(filePath, 'utf-8');
          const jsonData = JSON.parse(fileContent);
          if (!Array.isArray(jsonData)) {
            throw new Error("JSON content must be an array of objects.");
          }
          return writeXLSX({ filePath: outputFilePath, data: jsonData, format: 'xlsx', options: options });
        }
        else {
          throw new Error(`Invalid action: ${action}`);
        }
      } catch (error: any) {
        // Error handling
        console.error(error);
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(`Error: ${error instanceof Error ? error.message : String(error)}`, null, 2),
            },
          ],
          isError: true
        };
      }
    }
  • Input schema for the excel_tool defining parameters such as action, filePath, outputFilePath, format, data, and options.
    export const schema = {
      name: "excel_tool",
      description: "Read and write Excel (xlsx) and CSV files, and convert from JSON.",
      type: "object",
      properties: {
        action: {
          type: "string",
          enum: ["read", "write", "convert_json_to_xlsx"],
          description: "Action to perform: read, write, or convert_json_to_xlsx"
        },
        filePath: {
          type: "string",
          description: "Absolute path to the input file"
        },
        outputFilePath: {
          type: "string",
          description: "Absolute path to the output file (required for write and convert actions)"
        },
        format: {
          type: "string",
          enum: ["xlsx", "csv"],
          description: "File format: xlsx, csv"
        },
        data: {
          type: "array",
          description: "Data to write (required for write action)",
          items: {
            type: "object",
            additionalProperties: true
          }
        },
        options: {
          type: "object",
          description: "Additional options",
          properties: {
            sheetName: {
              type: "string",
              description: "Sheet name for Excel files"
            },
            headerRow: {
              type: "boolean",
              description: "Include header row in output"
            }
          },
          additionalProperties: true
        }
      },
      required: ["action", "filePath", "format"]
    };
Behavior1/5

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

Tool has no description.

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

Conciseness1/5

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

Tool has no description.

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

Completeness1/5

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

Tool has no description.

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

Parameters1/5

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

Tool has no description.

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

Purpose1/5

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

Tool has no description.

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

Usage Guidelines1/5

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

Tool has no description.

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/xiaoguomeiyitian/ToolBox'

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