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}`) ); } }

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