list_huggingface_files
Browse and list all files in a Hugging Face repository, including details like file paths, sizes, and types. Filter by pattern, sort by size, name, or type, and explore specific directories.
Instructions
列出 HuggingFace 仓库中的所有文件,包括文件路径、大小、类型等详细信息
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | No | 仓库内的子路径(可选,用于浏览特定目录) | |
| pattern | No | 文件名过滤模式(glob 模式),例如: *.safetensors, *.json | |
| repo_id | Yes | HuggingFace 仓库 ID,格式:用户名/模型名 | |
| revision | No | Git 分支或标签,默认为 main | main |
| sort_by | No | 排序方式: size(按大小), name(按名称), type(按类型) | name |
Implementation Reference
- src/mcp/tools.js:36-81 (schema)Defines the Tool object for 'list_huggingface_files' including name, description, and JSON schema for input parameters.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:292-339 (handler)The handler function that validates input, prepares options, calls downloader.list() to fetch the file list, and returns 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}`) ); } }
- src/mcp/tools.js:450-451 (registration)Registers the 'list_huggingface_files' tool in the central callTool switch statement, dispatching to callListTool.case 'list_huggingface_files': return await this.callListTool(args);
- src/mcp/tools.js:25-30 (registration)Includes the list_huggingface_files tool (via getListTool()) in the list of available tools returned by getTools().return [ this.getDownloadTool(), this.getListTool(), this.getExploreTool(), this.getSearchTool() ];