Hugging Face MCP Server

by shreyaskarnik
Verified

remote-capable server

The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.

Integrations

  • Allows retrieval and summarization of research papers using arXiv IDs, with features to control summary detail level and access implementation details.

  • Enables searching for Gradio spaces on Hugging Face, specifically mentioned as part of the Space Tools for finding popular Gradio spaces for various applications.

  • Provides read-only access to Hugging Face Hub APIs, allowing interaction with models, datasets, spaces, papers, and collections. Includes tools for searching and retrieving detailed information across these resource types.

🤗 Hugging Face MCP 服务器 🤗

一个模型上下文协议 (MCP) 服务器,提供对 Hugging Face Hub API 的只读访问权限。该服务器允许像 Claude 这样的法学硕士 (LLM) 与 Hugging Face 的模型、数据集、空间、论文和合集进行交互。

成分

资源

该服务器公开了流行的 Hugging Face 资源:

  • 用于访问资源的自定义hf:// URI 方案
  • 具有hf://model/{model_id} URI 的模型
  • 具有hf://dataset/{dataset_id} URI 的数据集
  • 具有hf://space/{space_id} URI 的空间
  • 所有资源都有描述性名称和 JSON 内容类型

提示

服务端提供了两种提示模板:

  • compare-models :生成多个 Hugging Face 模型之间的比较
    • 必需的model_ids参数(以逗号分隔的模型 ID)
    • 检索模型详细信息并对其进行格式化以供比较
  • summarize-paper :总结 Hugging Face 的一篇研究论文
    • 论文识别所需的arxiv_id参数
    • 可选的detail_level参数(简要/详细)用于控制摘要深度
    • 将论文元数据与实施细节相结合

工具

服务器实现了几个工具类别:

  • 模型工具
    • search-models :使用查询、作者、标签和限制过滤器搜索模型
    • get-model-info :获取特定模型的详细信息
  • 数据集工具
    • search-datasets :使用过滤器搜索数据集
    • get-dataset-info :获取有关特定数据集的详细信息
  • 太空工具
    • search-spaces :带有包括 SDK 类型在内的过滤器的搜索空间
    • get-space-info :获取特定空间的详细信息
  • 纸质工具
    • get-paper-info :获取有关论文及其实施的信息
    • get-daily-papers :获取精选日报列表
  • 收集工具
    • search-collections :使用各种过滤器搜索集合
    • get-collection-info :获取特定集合的详细信息

配置

服务器不需要配置,但支持可选的Hugging Face身份验证:

  • 使用您的 Hugging Face API 令牌设置HF_TOKEN环境变量:
    • 更高的 API 速率限制
    • 访问私人存储库(如果获得授权)
    • 提高大容量请求的可靠性

快速入门

安装

通过 Smithery 安装

要通过Smithery自动为 Claude Desktop 安装 huggingface-mcp-server:

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

克劳德桌面

在 MacOS 上: ~/Library/Application\ Support/Claude/claude_desktop_config.json在 Windows 上: %APPDATA%/Claude/claude_desktop_config.json

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

发展

构建和发布

准备分发包:

  1. 同步依赖项并更新锁文件:
uv sync
  1. 构建软件包分发版:
uv build

这将在dist/目录中创建源和轮子分布。

  1. 发布到 PyPI:
uv publish

注意:您需要通过环境变量或命令标志设置 PyPI 凭据:

  • 令牌: --tokenUV_PUBLISH_TOKEN
  • 或用户名/密码: --username / UV_PUBLISH_USERNAME--password / UV_PUBLISH_PASSWORD

调试

由于 MCP 服务器通过 stdio 运行,调试起来可能比较困难。为了获得最佳调试体验,我们强烈建议使用MCP Inspector

您可以使用以下命令通过npm启动 MCP Inspector:

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

启动后,检查器将显示一个 URL,您可以在浏览器中访问该 URL 以开始调试。

克劳德的示例提示

当将此服务器与 Claude 一起使用时,请尝试以下示例提示:

  • “在 Hugging Face 上搜索参数少于 1 亿的 BERT 模型”
  • “在 Hugging Face 上查找最受欢迎的文本分类数据集”
  • “今天关于 Hugging Face 的 AI 研究论文有哪些?”
  • “使用 Hugging Face MCP 服务器总结 arXiv ID 为 2307.09288 的论文”
  • “比较 Hugging Face 的 Llama-3-8B 和 Mistral-7B 模型”
  • “向我展示最流行的用于图像生成的 Gradio 空间”
  • “查找由 TheBloke 创建的包含 Mixtral 模型的系列”

故障排除

如果您遇到服务器问题:

  1. 在 Claude Desktop 中检查服务器日志:
    • macOS: ~/Library/Logs/Claude/mcp-server-huggingface.log
    • Windows: %APPDATA%\Claude\logs\mcp-server-huggingface.log
  2. 对于 API 速率限制错误,请考虑添加 Hugging Face API 令牌
  3. 确保您的机器具有互联网连接以访问 Hugging Face API
  4. 如果某个工具失败,请尝试通过 Hugging Face 网站访问相同的数据以验证其是否存在
-
security - not tested
A
license - permissive license
-
quality - not tested

模型上下文协议服务器为 Claude 和其他 LLM 提供对 Hugging Face Hub API 的只读访问权限,从而能够通过自然语言与模型、数据集、空间、论文和集合进行交互。

  1. Components
    1. Resources
    2. Prompts
    3. Tools
  2. Configuration
    1. Quickstart
      1. Install
    2. Development
      1. Building and Publishing
      2. Debugging
    3. Example Prompts for Claude
      1. Troubleshooting
        ID: d5kfni7860