Skip to main content
Glama
freefish1218

MCP HuggingFetch

by freefish1218

list_huggingface_files

Browse and filter files in HuggingFace repositories to locate specific model files using pattern matching, sorting, and depth controls.

Instructions

列出 HuggingFace 仓库中的文件,支持过滤和排序

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repo_idYesHuggingFace 仓库 ID(格式:owner/repo)
revisionNoGit 分支或标签main
patternNoGlob 模式过滤(例:*.safetensors)
excludeNo排除模式(例:*.bin)
max_filesNo最大文件数
max_depthNo最大递归深度
sortNo排序方式name

Implementation Reference

  • Core handler function for the 'list_huggingface_files' tool. Performs input validation, constructs options with 'standard' mode, calls downloader.list(), and formats the result.
    async callListTool(args) {
      try {
        // 基础验证
        if (!args.repo_id) {
          return CallToolResult.error(
            ToolContent.text('缺少必需参数: repo_id')
          );
        }
    
        logger.info(`列出文件: ${args.repo_id}`);
    
        // 构建选项 - 固定mode为standard
        const options = {
          revision: args.revision,
          pattern: args.pattern,
          exclude: args.exclude,
          maxFiles: args.max_files,
          maxDepth: args.max_depth,
          sort: args.sort,
          mode: 'standard', // 固定为标准模式
          token: args.token || process.env.HF_TOKEN
        };
    
        // 执行列表
        const result = await this.downloader.list(args.repo_id, options);
    
        if (result.success) {
          logger.info(`获取到 ${result.files?.length || 0} 个文件`);
          return CallToolResult.success(
            ToolContent.text(JSON.stringify(result, null, 2))
          );
        } else {
          logger.error('列表失败:', result.error);
          return CallToolResult.error(
            ToolContent.text(JSON.stringify({
              success: false,
              error: result.error,
              suggestions: result.suggestions
            }, null, 2))
          );
        }
      } catch (error) {
        logger.error('工具调用失败:', error);
        return CallToolResult.error(
          ToolContent.text(`工具调用失败: ${error.message}`)
        );
      }
    }
  • JSON Schema definition for the 'list_huggingface_files' tool inputs, including parameters like repo_id, revision, pattern, etc.
    getListTool() {
      return new Tool(
        'list_huggingface_files',
        '列出 HuggingFace 仓库中的文件,支持过滤和排序',
        {
          type: 'object',
          properties: {
            repo_id: {
              type: 'string',
              description: 'HuggingFace 仓库 ID(格式:owner/repo)',
              examples: ['2Noise/ChatTTS', 'microsoft/DialoGPT-medium']
            },
            revision: {
              type: 'string',
              description: 'Git 分支或标签',
              default: 'main'
            },
            pattern: {
              type: 'string',
              description: 'Glob 模式过滤(例:*.safetensors)'
            },
            exclude: {
              type: 'string',
              description: '排除模式(例:*.bin)'
            },
            max_files: {
              type: 'integer',
              description: '最大文件数',
              default: 100
            },
            max_depth: {
              type: 'integer',
              description: '最大递归深度',
              default: 3
            },
            sort: {
              type: 'string',
              enum: ['name', 'size', 'type'],
              description: '排序方式',
              default: 'name'
            }
          },
          required: ['repo_id']
        }
      );
    }
  • src/mcp/tools.js:24-31 (registration)
    Registration of the list_huggingface_files tool within the getTools() method that returns all available tools.
    getTools() {
      return [
        this.getDownloadTool(),
        this.getListTool(),
        this.getExploreTool(),
        this.getSearchTool()
      ];
    }
  • Tool dispatch registration in the central callTool switch statement, routing 'list_huggingface_files' to callListTool.
    async callTool(name, args) {
      switch (name) {
      case 'download_huggingface_model':
        return await this.callDownloadTool(args);
      case 'list_huggingface_files':
        return await this.callListTool(args);
      case 'explore_huggingface_repo':
        return await this.callExploreTool(args);
      case 'search_huggingface_files':
        return await this.callSearchTool(args);
      default:
        return CallToolResult.error(
          ToolContent.text(`未知工具: ${name}`)
        );
      }
    }

Schema Changelog

Changes observed during successful MCP inspections. Dates show when Glama detected each change.

  1. Changed10 schema fields changedv1.0.0
    • addedInput schema / properties / exclude
      Added value: +{
      +  "description": "排除模式(例:*.bin)",
      +  "type": "string"
      +}
    • addedInput schema / properties / max_depth
      Added value: +{
      +  "default": 3,
      +  "description": "最大递归深度",
      +  "type": "integer"
      +}
    • addedInput schema / properties / max_files
      Added value: +{
      +  "default": 100,
      +  "description": "最大文件数",
      +  "type": "integer"
      +}
    • removedInput schema / properties / path
      Removed value: -{
      -  "description": "仓库内的子路径(可选,用于浏览特定目录)",
      -  "type": "string"
      -}
    • changedInput schema / properties / pattern / description
      Previous value: -"文件名过滤模式(glob 模式),例如: *.safetensors, *.json"New value: +"Glob 模式过滤(例:*.safetensors)"
    • changedInput schema / properties / repo_id / description
      Previous value: -"HuggingFace 仓库 ID,格式:用户名/模型名"New value: +"HuggingFace 仓库 ID(格式:owner/repo)"
    • changedInput schema / properties / repo_id / examples
      Previous value: -[
      -  "2Noise/ChatTTS",
      -  "microsoft/DialoGPT-medium",
      -  "openai/whisper-large-v3"
      -]New value: +[
      +  "2Noise/ChatTTS",
      +  "microsoft/DialoGPT-medium"
      +]
    • changedInput schema / properties / revision / description
      Previous value: -"Git 分支或标签,默认为 main"New value: +"Git 分支或标签"
    • addedInput schema / properties / sort
      Added value: +{
      +  "default": "name",
      +  "description": "排序方式",
      +  "enum": [
      +    "name",
      +    "size",
      +    "type"
      +  ],
      +  "type": "string"
      +}
    • removedInput schema / properties / sort_by
      Removed value: -{
      -  "default": "name",
      -  "description": "排序方式: size(按大小), name(按名称), type(按类型)",
      -  "enum": [
      -    "size",
      -    "name",
      -    "type"
      -  ],
      -  "type": "string"
      -}
  2. First observed

TDQS

C2.9/5.0
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 filtering and sorting capabilities, but does not cover critical aspects such as rate limits, authentication requirements, error handling, or pagination behavior. For a tool with 7 parameters and 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 in Chinese that directly states the tool's function and key features (filtering and sorting). It is front-loaded with the core purpose and wastes no words, making it efficient for an agent to parse.

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 tool's complexity (7 parameters, no annotations, no output schema), the description is insufficient. It lacks details on behavioral traits, output format, error conditions, and differentiation from siblings. While the schema covers parameters well, the description does not compensate for the missing contextual information needed for effective tool invocation.

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%, meaning all parameters are well-documented in the input schema. The description adds minimal value by hinting at filtering and sorting, but does not provide additional semantics beyond what the schema already explains. This meets 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 tool's purpose: '列出 HuggingFace 仓库中的文件' (list files in a HuggingFace repository). It specifies the action (list) and resource (files in a HuggingFace repo), making it easy to understand. However, it does not explicitly differentiate from sibling tools like 'explore_huggingface_repo' or 'search_huggingface_files', which might have overlapping functionality.

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. It mentions '支持过滤和排序' (supports filtering and sorting), but does not specify scenarios, prerequisites, or exclusions. With sibling tools like 'search_huggingface_files' available, the lack of differentiation leaves the agent without clear usage context.

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

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/freefish1218/mcp-huggingfetch'

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