HuggingFace 标志

HuggingFace

组织
huggingface

Hugging Face MCP Server

发布者huggingface
代码仓库hf-mcp-server
语言TypeScript
复刻数
104
星标数
295
可用工具
0
传输类型streamable-http
许可协议MIT
链接
  • 将工具接入 AI 工作流

    HuggingFace 提供 MCP 功能,可供兼容的 AI 客户端和智能体使用。

  • 0 个可用工具

    浏览下方可调用的操作;如果服务器提供了名称和描述,也会一并显示。

  • 可直接复制的配置

    使用安装配置片段,在您首选的 MCP 客户端中配置此服务器。

  • 开源社区热度

    关联的代码仓库有 295 个 Star 和 104 个 Fork。

Hugging Face Official MCP Server

Welcome to the official Hugging Face MCP Server 🤗. Connect your LLM to the Hugging Face Hub and thousands of Gradio AI Applications.

Installing the MCP Server

Follow the instructions below to get started:

Click here to add the Hugging Face connector to your account.

Alternatively, navigate to https://claude.ai/settings/connectors, and add "Hugging Face" from the gallery.

Enter the command below to install in Claude Code:

bash
claude mcp add hf-mcp-server -t http https://huggingface.co/mcp?login

Then start claude and follow the instructions to complete authentication.

bash
claude mcp add hf-mcp-server \
  -t http https://huggingface.co/mcp \
  -H "Authorization: Bearer <YOUR_HF_TOKEN>"

Enter the command below to install in Gemini CLI:

bash
gemini mcp add -t http huggingface https://huggingface.co/mcp?login

Then start gemini and follow the instructions to complete authentication.

Click here to add the Hugging Face connector directly to VSCode. Alternatively, install from the gallery at https://code.visualstudio.com/mcp:

If you prefer to configure manually or use an auth token, add the snippet below to your mcp.json configuration:

json
"huggingface": {
    "url": "https://huggingface.co/mcp",
    "headers": {
        "Authorization": "Bearer <YOUR_HF_TOKEN>"
    }

Click here to install the Hugging Face MCP Server directly in Cursor.

If you prefer to use configure manually or specify an Authorization Token, use the snippet below:

json
"huggingface": {
    "url": "https://huggingface.co/mcp",
    "headers": {
        "Authorization": "Bearer <YOUR_HF_TOKEN>"
    }

Once installed, navigate to https://huggingface.co/settings/mcp to configure your Tools and Spaces.

[!TIP] Add ?no_image_content=true to the URL to remove ImageContent blocks from Gradio Servers.

hf_mcp_server_small

Quick Guide (Repository Packages)

This repo contains:

  • (/mcp) MCP Implementations of Hub API and Search endpoints for integration with MCP Servers.
  • (/app) An MCP Server and Web Application for deploying endpoints.

MCP Server

The following transports are supported:

  • STDIO
  • StreamableHTTP in Stateless JSON Mode (StreamableHTTPJson)

The Web Application and HTTP Transports start by default on Port 3000.

The StreamableHTTP service is available at /mcp. Although not strictly enforced by the specification, this is a common convention.

The public Streamable HTTP deployment serves its MCP Server Card at /mcp/server-card. The public card advertises the canonical https://huggingface.co/mcp endpoint without authentication-specific query parameters; loopback deployments and explicit non-Hugging Face hosts in MCP_ALLOWED_HOSTS advertise their own /mcp endpoint. Card responses support cache revalidation with an ETag.

The Web Application at /metrics reports server status and MCP method metrics. It can be placed behind an optional lightweight shared-password gate using METRICS_PAGE_PASSWORD. Browser visits to / redirect to the MCP welcome page at /mcp. Tool selection is resolved independently for each request from the optional Hugging Face user configuration API and the bouquet/mix query parameters. Note to security researches and bots, this is intentionally lightweight and not considered sensitive or protected data.

Use ?bouquet=openai to expose Hub filesystem, repository search and details, dynamic Space, Jobs, and sandbox tools. Jobs, dynamic Space, and sandbox tools require Hugging Face authentication.

Running Locally

You can run the MCP Server locally with either npx or docker.

bash
npx @llmindset/hf-mcp-server       # Start in STDIO mode
npx @llmindset/hf-mcp-server-http  # Start in stateless Streamable HTTP JSON mode

To run with docker:

bash
docker pull ghcr.io/evalstate/hf-mcp-server:latest
docker run --rm -p 3000:3000 ghcr.io/evalstate/hf-mcp-server:latest

image

All commands above start the Management Web interface on http://localhost:3000/metrics. Browser visits to http://localhost:3000/ redirect to the MCP welcome page at http://localhost:3000/mcp. See [Environment Variables](#Environment Variables) for configuration options. Docker defaults to Streamable HTTP (JSON RPC) mode.

Development

This project uses pnpm for build and development. Corepack is used to ensure everyone uses the same pnpm version (10.12.3).

For OAuth discovery, dynamic registration, or Client ID Metadata Document diagnostics, see docs/oauth-diagnostics.md and run pnpm oauth:diagnose.

Benchmark harnesses, historical results, and optimization plans are maintained in the separate hf-mcp-optimise workspace.

bash
# Install dependencies
pnpm install

# Build all packages
pnpm build

Build Commands

pnpm run clean -> clean build artifacts

pnpm run build -> build packages

pnpm run start -> start the mcp server application

pnpm run buildrun -> clean, build and start

pnpm run dev -> concurrently watch mcp and start dev server with HMR

Docker Build

Build the image:

bash
docker build -t hf-mcp-server .

Run with default settings (Streaming HTTP JSON Mode), with the dashboard at /metrics on Port 3000. HTTP clients must send a Hugging Face token in the Authorization: Bearer header:

bash
docker run --rm -p 3000:3000 hf-mcp-server

Run STDIO MCP Server:

bash
docker run -i --rm -e TRANSPORT=stdio -p 3000:3000 -e DEFAULT_HF_TOKEN=hf_xxx hf-mcp-server

TRANSPORT can be stdio or streamableHttpJson (default).

Transport Endpoints

The different transport types use the following endpoints:

  • Stateless Streamable HTTP JSON: /mcp
  • MCP Server Card for Streamable HTTP JSON: /mcp/server-card
  • STDIO: Uses stdin/stdout directly, no HTTP endpoint

Environment Variables

The server respects the following environment variables:

  • TRANSPORT: The transport type to use (stdio or streamableHttpJson)
  • DEFAULT_HF_TOKEN: Default token for local STDIO deployments. HTTP transports do not use this as a fallback for requests without an Authorization: Bearer header.
  • If running with stdio transport, HF_TOKEN is used if DEFAULT_HF_TOKEN is not set.
  • MCP_ALLOWED_HOSTS: Additional comma-separated Host allowlist for MCP and API routes. Loopback hosts localhost,127.0.0.1,::1 are always allowed. Use exact hostnames or leading wildcard entries such as *.example.com.
  • HF_API_TIMEOUT: Timeout for Hugging Face API requests in milliseconds (default: 12500ms / 12.5 seconds)
  • USER_CONFIG_API: Optional URL for the per-user discovery projection returned by tools/list, including configured Spaces. These settings control which deployed tools are advertised, not whether a direct tools/call to a known tool may execute. Generated Gradio aliases still use the configured Space mapping. When unset, immutable built-in defaults are used.
  • ALLOW_INTERNAL_ADDRESS_HOSTS: Optional comma-separated host allowlist to permit internal/reserved DNS resolutions for trusted domains during outbound checks (supports exact hosts and *. wildcards, for example: huggingface.co,*.hf.space).
  • MCP_STRICT_COMPLIANCE: set to True for GET 405 rejects in JSON Mode (default serves a welcome page).
  • MCP_STRICT_TOKEN: set to true to reject token-less Streamable HTTP connections with 401 before any server instance is built. Default (unset or any other value) keeps the current behavior: token-less requests continue with the anonymous tool set. Supplied tokens must pass whoami validation: invalid tokens return 401, and unavailable validation (including network errors and upstream failures) returns 503 without allowing the request to proceed. With strict mode disabled, validation failures other than 401 retain the existing fail-open behavior.
  • DISABLE_TOOLS: Optional comma-separated tool names to hide from tools/list and reject if called, for example hub_repo_search,hf_fs. Rejected calls remain visible as errors in the MCP dashboard tool-call statistics.
  • PROXY_TOOLS_CSV: Optional CSV that defines Streamable HTTP proxy tool sources (see below).
  • PROXY_TOKEN: Optional token used only for startup authentication while discovering PROXY_TOOLS_CSV schemas.
  • GRADIO_SKIP_INITIALIZE: When set to true, Gradio MCP calls skip the initialize handshake and issue tools/call directly.
  • METRICS_PAGE_PASSWORD: Optional shared password for the Management Web interface at /metrics and its /api/* endpoints. When unset or empty, the interface remains public. This does not protect /mcp or /mcp/server-card.
  • HF_SKILLS_DIR: Local directory containing a prebuilt SEP-2640 skills snapshot: skills.json carries each skill's uri, complete frontmatter, and per-file {uri,digest} resource manifest, alongside the expanded skill directories. On HTTP transports, the server verifies every raw SHA-256 digest and checks the actual SKILL.md frontmatter before atomically retaining all files in memory. Snapshots have a three-hour freshness TTL; stale requests keep using the last valid snapshot while one background refresh is loaded and verified, and refresh failures retain that verified snapshot with a five-minute retry delay. The HTTP server implements skills/list, skills/get, resources/read, and optional resources/directory/read, and advertises io.modelcontextprotocol/skills with directoryRead: true only when a valid snapshot is available. Skills are not exposed over the long-lived STDIO transport. Defaults to /mnt/hf-skills/distribution/latest, intended for a Hugging Face Space volume mounted from hf://buckets/huggingface/skills.
  • LOG_SKILL_EVENTS: Enables historical product-usage logging for SEP-2640 Skills probes when LOGGING_DATASET_ID and a logging token are configured (default: true). Events are written under skills/YYYY-MM-DD/, separately from tool queries, and contain client/protocol correlation, success, duration, cursor presence, aggregate result counts, and the requested skill:// URI for targeted get/read operations. Cursor values, frontmatter, resource content, response bodies, and error messages are not recorded.

Optional Management Interface Password

Set METRICS_PAGE_PASSWORD to a non-empty value to enable a lightweight shared-password gate for the Management Web interface and its API endpoints:

  • Browser visits to / redirect to /mcp. Visits to /metrics are redirected to /metrics/login until the password is accepted.
  • A successful login redirects back to /metrics.
  • A successful login stores a signed, 30-day HttpOnly, SameSite=Lax cookie. HTTPS requests also receive the Secure cookie attribute.
  • /api/transport, /api/sessions, and /api/transport-metrics require the cookie or a valid scraper credential.
  • /mcp and the public /mcp/server-card are not affected.

This is intended only to discourage casual browsing. It has no users, roles, rate limiting, or audit trail and is not a substitute for real authentication, HTTPS, or access control at the platform/reverse-proxy layer. When HTTPS terminates at a reverse proxy, the proxy must overwrite X-Forwarded-Proto with the actual client protocol so the application can apply the cookie's Secure attribute correctly.

For a Hugging Face Space, configure this as a Space secret in the Space settings. A GitHub Actions secret is not automatically passed to a running Space by this repository's workflows. With the Hugging Face CLI, the equivalent command is:

bash
hf spaces secrets add <org>/<space> -s METRICS_PAGE_PASSWORD='<shared-password>'

Automated scrapers can send the password in a header:

bash
curl --fail-with-body --silent --show-error \
  -H "X-Metrics-Password: ${METRICS_PAGE_PASSWORD}" \
  https://your-space.hf.space/api/transport-metrics

For simple URL-based jobs, a URL-encoded query parameter is also accepted:

bash
curl --fail-with-body --silent --show-error --get \
  --data-urlencode "metrics_password=${METRICS_PAGE_PASSWORD}" \
  https://your-space.hf.space/api/transport-metrics

Prefer the header where possible. Query-string passwords can be retained in reverse-proxy or access logs, monitoring systems, shell process listings, and browser history even though the application does not log the credential itself.

To expose the shared Hugging Face skills catalog from a Space, mount the bucket and keep HF_SKILLS_DIR pointed at its latest distribution directory:

bash
hf spaces volumes set <org>/<space> -v hf://buckets/huggingface/skills:/mnt/hf-skills:ro
hf spaces variables add <org>/<space> -e HF_SKILLS_DIR=/mnt/hf-skills/distribution/latest

Proxy tools (Streamable HTTP via CSV)

You can load proxy tool definitions at startup by setting PROXY_TOOLS_CSV to a HTTPS URL or a local file path. If those proxy servers require authentication, set PROXY_TOKEN. User, default, and logging tokens are never used for startup proxy schema discovery. The server fetches each MCP endpoint once on startup, runs initialize + tools/list (10s timeout), and registers any tools returned. If a source fails or returns no tools, it is skipped (no startup failure).

CSV format

tool_name,url,response_type
papers,https://evalstate-hf-papers.hf.space/mcp,SSE
news,https://example.com/mcp,JSON
  • tool_name: local tool name for single-tool upstreams; identifier for the proxy source when the upstream exposes multiple tools.
  • url: Streamable HTTP MCP endpoint.
  • response_type: legacy compatibility field; SSE and JSON are both accepted. Proxy calls can still consume upstream Streamable HTTP responses, while this server always returns direct JSON-RPC responses to its clients.

Tool naming

Tool naming depends on how many tools the upstream MCP endpoint returns:

  • Single upstream tool: the exposed tool name is the first CSV column.
  • Multiple upstream tools: the exposed tool names are the upstream tool names.

If an exposed proxy tool name collides with an already-registered tool, the proxy tool is skipped and a warning is logged.

You can include these tool names in bouquets or mixes to advertise them through tools/list. Use bouquet=proxy or mix=proxy to advertise all proxy tools loaded from PROXY_TOOLS_CSV (in addition to the base built-in tools). Direct calls to a known startup-configured proxy tool do not depend on that discovery selection.

Dynamic Space health checks

monitor/distribution/bin/monitor.py --check is a read-only CSV health check for the catalog configured by DYNAMIC_SPACE_DATA. It checks Hub runtime state and each runnable Space's Gradio MCP schema, but never invokes a tool, restarts a Space, or opens a PR. Run it locally with:

bash
pnpm health:dynamic-spaces

It uses Python 3 and the standard library. The catalog URL must be public. It uses HF_TOKEN, then DEFAULT_HF_TOKEN, for private Space metadata and schema requests. Sleeping Spaces are accepted from Hub metadata without waking them unless HEALTH_PROBE_SLEEPING=true.

For the eight-hour repair schedule and read-only dashboard, follow monitor/README.md. The Bucket preserves reports and the atomic ledger. HF_TOKEN (falling back to DEFAULT_HF_TOKEN) is the parent Hub credential for health reads, restarts, and PR creation; both repair actions are enabled when it is present. RESPONSES_API_KEY (or its OPENAI_API_KEY fallback) is the Doctor model credential. MONITOR_HF_TOKEN, if set, is a separate read-only token passed only to the Doctor. Omit HF_TOKEN for a public read-only monitor. Job logs contain one status line per Space and a final summary.

Exit code 0 means every Space is healthy and 1 means at least one Space is unhealthy or degraded. Invalid catalog or configuration is reported as exit code 2. Optional tuning variables are HEALTH_TIMEOUT_SECONDS, HEALTH_ATTEMPTS, HEALTH_RETRY_DELAY_SECONDS, and HEALTH_PROBE_SLEEPING. See monitor/README.md for retry and manual-reset policy.

安装

TypingMind
{
  "mcpServers": {
    "huggingface": {
      "url": "https://hf.co/mcp"
    }
  }
}

将 HuggingFace MCP 与多个 AI 模型配合使用

TypingMind 在工作区级别连接 MCP 工具,因此连接 HuggingFace 后,您就可以在 TypingMind 中搭配不同的 AI 模型使用,无需为每个模型单独设置。 此 MCP 通过远程托管的 MCP 服务器 URL 在 TypingMind 中连接。

添加 MCP 服务器 URL

如果 HuggingFace 已托管在远程服务器上,或您的团队希望让多个用户共用一个连接器,请选择此方式。

1

打开 MCP 连接器

在 TypingMind 中,前往“插件”,打开“MCP 连接器”,然后选择“添加 URL”。

  1. 在您的浏览器中打开 TypingMind。
  2. 进入“插件”。
  3. 打开“MCP 连接器”。
  4. 点击“添加 URL”。
TypingMind 的“添加自定义 MCP 服务器 URL”表单
2

粘贴服务器 URL

在“服务器 URL”字段中输入 https://hf.co/mcp。根据服务器要求,添加连接名称、描述、图标、自定义 HTTP 请求头或 OAuth 客户端设置。

  1. 将 https://hf.co/mcp 粘贴到“服务器 URL”字段中。
  2. 为 HuggingFace 输入连接名称。
  3. 您可以添加描述和图标,以便更容易识别此连接。
  4. 如果服务器需要身份验证,请添加自定义 HTTP 请求头或 OAuth 客户端信息。
3

创建连接

点击“创建连接”,然后返回插件列表,确认新的 MCP 连接显示为“有效”。

  1. 点击“创建连接”。
  2. 返回 MCP 连接器列表。
  3. 确认 HuggingFace 连接显示为“有效”。
  4. 如果连接未立即出现,请刷新插件列表。
4

切换模型,无需重新连接

使用您偏好的模型开始聊天,在“插件”中启用 HuggingFace 工具,并根据需要随时切换到其他模型。该 MCP 连接在 TypingMind 工作区中仍然可用。

  1. 在 TypingMind 中开始新聊天。
  2. 选择您想使用的 AI 模型。
  3. 在“插件”中启用 HuggingFace 工具。
  4. 需要时,请让模型使用该工具。
  5. 切换到其他 AI 模型,继续使用同一个 MCP 连接。
在 TypingMind 聊天中使用已启用的 MCP 工具和选定的 AI 模型
您能使用 HuggingFace 帮我完成这项任务吗?
HuggingFace
当然。我已阅读。
以下是我使用 HuggingFace 得到的结果。

常见问题

HuggingFace MCP 服务器有什么用途?

HuggingFace 是一个 MCP 服务器,可让兼容的 AI 客户端连接外部工具并获取上下文。在 TypingMind 中,只需添加一次此 MCP 服务器,即可在您的 AI 工作区中使用其工具。

可以在 TypingMind 中让多个 AI 模型使用 HuggingFace MCP 吗?

可以。TypingMind 在工作区层面连接 MCP 工具,因此您可以让 Claude、ChatGPT、Gemini 等不同 AI 模型,或您在 TypingMind 中配置的其他模型使用 HuggingFace,而无需为每个模型单独配置 MCP 服务器。

为什么在 TypingMind 中使用 HuggingFace MCP?

TypingMind 将多个 AI 模型、提示词、插件、AI 智能体、API 密钥和 MCP 工具整合到同一个工作区中,是优秀的大语言模型聊天前端之一。连接 HuggingFace 后,您可以在偏好的不同模型中使用其 MCP 工具,同时在 TypingMind 中井然有序地管理聊天工作流程。

如何将 HuggingFace MCP 连接到 TypingMind?

在 TypingMind 中添加 HuggingFace 托管的 MCP 服务器 URL,即可连接。如果您希望在 TypingMind 工作区中使用远程 MCP 连接,这种方式很适合。

HuggingFace MCP 在 TypingMind 中提供哪些工具?

HuggingFace 提供 MCP 功能,您可以在 TypingMind 的插件页面启用这些功能,然后在聊天中使用,或将其分配给 AI 智能体。

使用 HuggingFace MCP 需要向 TypingMind 提供我的 API 密钥吗?

不需要。TypingMind 采用本地优先的设计,让您自行掌控模型提供商、API 密钥、提示词和 MCP 配置。如果 HuggingFace 需要身份验证,请在创建连接时,为该 MCP 服务器添加所需的请求头、OAuth 设置或本地配置。

相关 MCP 服务器

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇