Skip to main content
Glama
aigo666

MCP Development Framework

parse_excel

Extract data from Excel files to access sheet contents and structured information for analysis or integration.

Instructions

Parses an Excel file and returns its content including all sheets

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYesPath to the Excel file to parse

Implementation Reference

  • The execute method implements the core logic: validates input, processes file path, checks existence and format, reads all sheets with pandas, converts to structured JSON (file info, sheets with rows/cols/data), returns formatted JSON or errors.
    async def execute(self, arguments: dict) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
        """解析Excel文件并返回内容"""
        if "file_path" not in arguments:
            return [types.TextContent(
                type="text",
                text="Error: Missing required argument 'file_path'"
            )]
        
        file_path = arguments["file_path"]
        # 处理文件路径,支持挂载目录的转换
        file_path = self.process_file_path(file_path)
        
        if not os.path.exists(file_path):
            return [types.TextContent(
                type="text",
                text=f"Error: File not found at path: {file_path}"
            )]
        
        if not file_path.lower().endswith(('.xlsx', '.xls', '.xlsm')):
            return [types.TextContent(
                type="text",
                text=f"Error: File is not an Excel file: {file_path}"
            )]
        
        try:
            # 读取Excel文件中的所有sheet
            excel_file = pd.ExcelFile(file_path)
            sheet_names = excel_file.sheet_names
            
            result = {
                "file_name": os.path.basename(file_path),
                "sheet_count": len(sheet_names),
                "sheets": {}
            }
            
            # 解析每个sheet
            for sheet_name in sheet_names:
                df = pd.read_excel(excel_file, sheet_name=sheet_name)
                
                # 将DataFrame转换为字典
                sheet_data = df.to_dict(orient='records')
                
                # 获取列名
                columns = df.columns.tolist()
                
                # 获取行数和列数
                row_count = len(df)
                column_count = len(columns)
                
                result["sheets"][sheet_name] = {
                    "row_count": row_count,
                    "column_count": column_count,
                    "columns": columns,
                    "data": sheet_data
                }
            
            # 将结果转换为JSON字符串,并格式化输出
            result_json = json.dumps(result, ensure_ascii=False, indent=2, default=str)
            
            return [types.TextContent(
                type="text",
                text=result_json
            )]
            
        except Exception as e:
            return [types.TextContent(
                type="text",
                text=f"Error: Failed to parse Excel file: {str(e)}"
            )] 
  • Defines the input schema: object with required 'file_path' string parameter.
    input_schema = {
        "type": "object",
        "required": ["file_path"],
        "properties": {
            "file_path": {
                "type": "string",
                "description": "Path to the Excel file to parse",
            }
        },
    }
  • Registers the tool class ExcelTool inheriting BaseTool with name 'parse_excel' and description via ToolRegistry decorator.
    @ToolRegistry.register
    class ExcelTool(BaseTool):
        """Excel解析工具,用于解析Excel文件内容"""
        name = "parse_excel"
        description = "Parses an Excel file and returns its content including all sheets"
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. It states the tool parses and returns content, but lacks critical behavioral details: whether it handles large files, error conditions (e.g., invalid paths), output format (e.g., structured data vs. raw text), or performance implications. The description is minimal and misses key operational context.

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

Conciseness4/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 function. It's front-loaded with the core action and outcome, with no wasted words. However, it could be slightly more structured by including key behavioral notes, but it's appropriately sized for its simplicity.

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 no annotations and no output schema, the description is incomplete for a parsing tool. It doesn't explain what 'returns its content' means (e.g., data structure, sheet handling), error behavior, or limitations. For a tool with 1 parameter and 100% schema coverage, it lacks necessary context about output and operational traits.

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%, with the parameter 'file_path' fully documented in the schema. The description adds no additional meaning beyond what the schema provides (e.g., no details on file format expectations or path resolution). Baseline 3 is appropriate as the schema does the heavy lifting.

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 ('parses') and resource ('an Excel file'), specifying what the tool does. It distinguishes from some siblings like parse_csv and parse_pdf by mentioning Excel files, but doesn't explicitly differentiate from parse_file which might also handle Excel files. The purpose is specific and actionable.

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 like parse_file, parse_csv, or other parsing tools. It doesn't mention prerequisites (e.g., file accessibility), exclusions, or context for choosing this over siblings. Usage is implied by the name but not explicitly stated.

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/aigo666/mcp-framework'

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