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()
      ];
    }

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