Skip to main content
Glama
aigo666

MCP Development Framework

parse_file

Extract text and data from PDF, Word, Excel, CSV, and Markdown files to process document content within the MCP Development Framework.

Instructions

解析文件内容,支持PDF、Word、Excel、CSV和Markdown格式

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes文件的本地路径,例如'/path/to/document.pdf'

Implementation Reference

  • Registration of the 'parse_file' tool via @ToolRegistry.register decorator on FileTool class, including name assignment.
    @ToolRegistry.register
    class FileTool(BaseTool):
        """
        综合文件处理工具,根据文件扩展名自动选择合适的处理方式
        支持的文件类型:
        - PDF文件 (.pdf)
        - Word文档 (.doc, .docx)
        - Excel文件 (.xls, .xlsx, .xlsm)
        - CSV文件 (.csv)
        - Markdown文件 (.md)
        """
        
        name = "parse_file"
  • Input schema defining the required 'file_path' parameter for the tool.
    input_schema = {
        "type": "object",
        "required": ["file_path"],
        "properties": {
            "file_path": {
                "type": "string",
                "description": "文件的本地路径,例如'/path/to/document.pdf'",
            }
        },
    }
  • The handler function that executes the tool: validates input, processes file path, determines file type by extension, delegates to specialized sub-tools (PdfTool, WordTool, etc.), and handles errors.
    async def execute(self, arguments: Dict[str, Any]) -> List[types.TextContent | types.ImageContent | types.EmbeddedResource]:
        """
        解析文件内容
        
        Args:
            arguments: 参数字典,必须包含'file_path'键
        
        Returns:
            解析结果列表
        """
        if "file_path" not in arguments:
            return [types.TextContent(
                type="text",
                text="错误: 缺少必要参数 '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"错误: 文件不存在: {file_path}"
            )]
        
        # 获取文件扩展名(转换为小写)
        file_ext = os.path.splitext(file_path)[1].lower()
        
        try:
            # 根据文件扩展名选择处理工具
            if file_ext == '.pdf':
                return await self.pdf_tool.execute(arguments)
            elif file_ext in ['.doc', '.docx']:
                return await self.word_tool.execute(arguments)
            elif file_ext in ['.xls', '.xlsx', '.xlsm']:
                return await self.excel_tool.execute(arguments)
            elif file_ext == '.csv':
                return await self.csv_tool.execute(arguments)
            elif file_ext == '.md':
                return await self.markdown_tool.execute(arguments)
            else:
                return [types.TextContent(
                    type="text",
                    text=f"错误: 不支持的文件类型: {file_ext}"
                )]
        except Exception as e:
            error_details = traceback.format_exc()
            return [types.TextContent(
                type="text",
                text=f"错误: 处理文件时发生错误: {str(e)}\n{error_details}"
            )] 
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 what the tool does (parse content) and lists formats, but lacks behavioral details such as error handling, performance characteristics, memory usage, or output structure. For a parsing tool with no annotations, this is a significant gap in transparency.

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—a single sentence that efficiently states the core function and supported formats. It is front-loaded with the main purpose and wastes no words. Every part of the sentence earns its place by providing essential information.

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. It doesn't explain what '解析文件内容' entails (e.g., text extraction, metadata parsing), the return format, or error cases. For a parsing tool with one parameter but complex behavior, this leaves too much unspecified for effective agent 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?

The input schema has 100% description coverage, with 'file_path' clearly documented. The description adds no additional parameter semantics beyond implying format support through the listed extensions. Since schema coverage is high, the baseline is 3, and the description doesn't compensate with extra details like path validation or format inference rules.

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: '解析文件内容' (parse file content) with specific formats listed (PDF, Word, Excel, CSV, Markdown). It distinguishes itself from siblings like 'parse_csv' or 'parse_pdf' by being a multi-format parser, though it doesn't explicitly contrast them. The verb+resource combination is specific but lacks explicit sibling differentiation.

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 its siblings (e.g., parse_csv, parse_pdf). It lists supported formats but doesn't explain if this is a general-purpose parser or when specialized siblings might be preferred. There are no explicit usage contexts, exclusions, or alternatives mentioned.

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