Skip to main content
Glama
freefish1218

MCP HuggingFetch

by freefish1218

search_huggingface_files

Search for specific files within HuggingFace repositories by entering a repository ID and search query to locate models, datasets, or configuration files.

Instructions

在 HuggingFace 仓库中搜索特定文件

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repo_idYesHuggingFace 仓库 ID(格式:owner/repo)
queryYes搜索关键词或模式
revisionNoGit 分支或标签main
max_resultsNo最大结果数

Implementation Reference

  • Main handler function for 'search_huggingface_files' tool. Validates input, calls downloader.search, and formats the response.
     */
    async callSearchTool(args) {
      try {
        // 基础验证
        if (!args.repo_id) {
          return CallToolResult.error(
            ToolContent.text('缺少必需参数: repo_id')
          );
        }
    
        if (!args.query) {
          return CallToolResult.error(
            ToolContent.text('缺少必需参数: query')
          );
        }
    
        logger.info(`搜索文件: ${args.repo_id} - ${args.query}`);
    
        // 使用search方法而不是list
        const result = await this.downloader.search(args.repo_id, args.query, {
          revision: args.revision,
          maxFiles: args.max_results,
          token: args.token || process.env.HF_TOKEN
        });
    
        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}`)
        );
      }
    }
  • Tool schema definition including name, description, and JSON schema for input parameters.
    getSearchTool() {
      return new Tool(
        'search_huggingface_files',
        '在 HuggingFace 仓库中搜索特定文件',
        {
          type: 'object',
          properties: {
            repo_id: {
              type: 'string',
              description: 'HuggingFace 仓库 ID(格式:owner/repo)',
              examples: ['2Noise/ChatTTS', 'microsoft/DialoGPT-medium']
            },
            query: {
              type: 'string',
              description: '搜索关键词或模式'
            },
            revision: {
              type: 'string',
              description: 'Git 分支或标签',
              default: 'main'
            },
            max_results: {
              type: 'integer',
              description: '最大结果数',
              default: 50
            }
          },
          required: ['repo_id', 'query']
        }
      );
    }
  • Dispatch registration in the central callTool switch statement.
    case 'search_huggingface_files':
      return await this.callSearchTool(args);
  • src/mcp/tools.js:24-31 (registration)
    Registration of the search tool in the list of available tools returned by getTools().
    getTools() {
      return [
        this.getDownloadTool(),
        this.getListTool(),
        this.getExploreTool(),
        this.getSearchTool()
      ];
    }
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It states the tool searches for files but doesn't describe what happens (e.g., returns file paths/metadata, pagination behavior, error handling for invalid repos). It lacks details on rate limits, authentication needs, or whether it's read-only (implied but not explicit).

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 a single, efficient sentence in Chinese that directly states the tool's purpose without unnecessary words. It's front-loaded with the core action ('搜索') and resource, making it easy to parse. Every part of the sentence contributes to understanding the tool.

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 has 4 parameters, no annotations, and no output schema, the description is incomplete. It doesn't explain what the tool returns (e.g., list of file names, metadata), error conditions, or behavioral constraints. For a search tool with multiple inputs, more context is needed to use it effectively.

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, providing clear details for all 4 parameters (repo_id format, query purpose, revision default, max_results default). The description adds no additional parameter semantics beyond the schema, so it meets the baseline of 3 for high schema coverage without compensating value.

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 action ('搜索' - search) and resource ('HuggingFace 仓库中...文件' - files in HuggingFace repository). It distinguishes from siblings like 'download_huggingface_model' (downloads models) and 'list_huggingface_files' (lists files without search). However, it doesn't explicitly differentiate from 'explore_huggingface_repo', 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 doesn't mention when to prefer 'search_huggingface_files' over 'list_huggingface_files' (e.g., for filtered results) or 'explore_huggingface_repo' (e.g., for broader repository exploration). There's no context about prerequisites or exclusions.

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

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