🤗 Hugging Face MCP Server 🤗

🤗 Hugging Face MCP Server 🤗

site icon
2025.03.20 39
PythonAI 模型服务数据访问中间件开发效率
Hugging Face MCP Server 是一个基于 Model Context Protocol (MCP) 的服务,提供对 Hugging Face Hub API 的只读访问。该服务允许像 Claude 这样的 LLM 与 Hugging Face 的模型、数据集、空间、论文和集合进行交互。
View on GitHub

Overview

基本能力

产品定位

Hugging Face MCP Server 是一个中间件服务,旨在为大型语言模型(如 Claude)提供便捷的 Hugging Face Hub 资源访问能力。

核心功能

  1. 提供对 Hugging Face 多种资源的访问:
  2. 模型(Models)
  3. 数据集(Datasets)
  4. 空间(Spaces)
  5. 论文(Papers)
  6. 集合(Collections)
  7. 支持自定义 hf:// URI 方案访问资源
  8. 提供两种提示模板:
  9. compare-models:比较多个 Hugging Face 模型
  10. summarize-paper:总结研究论文
  11. 实现多种工具类别:
  12. 模型工具(搜索模型、获取模型信息)
  13. 数据集工具(搜索数据集、获取数据集信息)
  14. 空间工具(搜索空间、获取空间信息)
  15. 论文工具(获取论文信息、获取每日论文)
  16. 集合工具(搜索集合、获取集合信息)

适用场景

  1. 需要让 LLM 访问 Hugging Face 资源的应用场景
  2. 需要比较不同模型性能的研究工作
  3. 需要快速获取和总结 AI 研究论文的场景
  4. 需要批量处理 Hugging Face 资源的自动化任务

工具列表

  1. Model Tools
  2. search-models: 根据查询、作者、标签等条件搜索模型
  3. get-model-info: 获取特定模型的详细信息
  4. Dataset Tools
  5. search-datasets: 搜索数据集
  6. get-dataset-info: 获取特定数据集的详细信息
  7. Space Tools
  8. search-spaces: 搜索空间,包括 SDK 类型过滤
  9. get-space-info: 获取特定空间的详细信息
  10. Paper Tools
  11. get-paper-info: 获取论文及其实现的信息
  12. get-daily-papers: 获取每日精选论文列表
  13. Collection Tools
  14. search-collections: 搜索集合
  15. get-collection-info: 获取特定集合的详细信息

常见问题解答

  1. API 速率限制问题:考虑添加 Hugging Face API 令牌
  2. 连接问题:确保机器可以访问 Hugging Face API
  3. 特定工具失败:尝试通过 Hugging Face 网站验证数据是否存在
  4. 日志位置
  5. macOS: ~/Library/Logs/Claude/mcp-server-huggingface.log
  6. Windows: %APPDATA%\Claude\logs\mcp-server-huggingface.log

使用教程

使用依赖

  1. 需要安装 Node.js 和 npm
  2. 可选:Hugging Face API 令牌(用于提高 API 速率限制)

安装教程

通过 Smithery 安装

npx -y @smithery/cli install @shreyaskarnik/huggingface-mcp-server --client claude

手动配置(开发/未发布服务器)

"mcpServers": {
  "huggingface": {
    "command": "uv",
    "args": [
      "--directory",
      "/absolute/path/to/huggingface-mcp-server",
      "run",
      "huggingface_mcp_server.py"
    ],
    "env": {
      "HF_TOKEN": "your_token_here"  // 可选
    }
  }
}

调试方式

使用 MCP Inspector 进行调试:

npx @modelcontextprotocol/inspector uv --directory /path/to/huggingface-mcp-server run huggingface_mcp_server.py

示例提示

  1. "Search for BERT models on Hugging Face with less than 100 million parameters"
  2. "Find the most popular datasets for text classification on Hugging Face"
  3. "What are today's featured AI research papers on Hugging Face?"
  4. "Summarize the paper with arXiv ID 2307.09288 using the Hugging Face MCP server"
  5. "Compare the Llama-3-8B and Mistral-7B models from Hugging Face"
  6. "Show me the most popular Gradio spaces for image generation"
  7. "Find collections created by TheBloke that include Mixtral models"

许可证

该项目遵循 MIT 开源许可条款,请参阅 MIT 了解完整条款。