list_huggingface_files
Browse and filter files in HuggingFace repositories to locate specific model files using pattern matching, sorting, and depth controls.
Instructions
列出 HuggingFace 仓库中的文件,支持过滤和排序
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"repo_id": "<repo_id>"
},
"name": "list_huggingface_files"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| repo_id | Yes | HuggingFace 仓库 ID(格式:owner/repo) | |
| revision | No | Git 分支或标签 | main |
| pattern | No | Glob 模式过滤(例:*.safetensors) | |
| exclude | No | 排除模式(例:*.bin) | |
| max_files | No | 最大文件数 | |
| max_depth | No | 最大递归深度 | |
| sort | No | 排序方式 | name |
Implementation Reference
- src/mcp/tools.js:292-339 (handler)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}`) ); } } - src/mcp/tools.js:36-81 (schema)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() ]; } - src/mcp/tools.js:446-461 (registration)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}`) ); } }