Building a Production MCP Server for AI Assistant Integration

hugging_face · Tech · 2024 · source Agentic: no · promotional bias: high · source-backed · extracted with prompt 0.5.0 (schema v2)

Generated from extraction.json — do not edit by hand. Every claim cites verbatim source evidence; stated means the quote directly asserts the claim, implied means it supports it indirectly.

Problem

Domain: Tech

Hugging Face wanted AI assistants to access the Hub and Spaces through MCP while supporting user customization and production deployment constraints.

Constraints:

Architecture

Hugging Face’s MCP server exposes the Hub and Spaces to AI assistants through a remotely accessible URL. Users configure available tools on the Hugging Face MCP settings page; anonymous users get a standard Hub/Image Generator set, while authenticated users use HF_TOKEN or OAuth so the server can look up selected tools, chosen Gradio applications, and ZeroGPU quota per request. The open-source server supports STDIO, SSE, and Streamable HTTP variants, but production launches with Streamable HTTP in stateless direct-response mode to keep horizontal scaling simple and avoid long-lived connection management. Observability dashboards help inspect client connections and tool-list behavior.

Diagram confidence: explicit (topology described by the source).

flowchart LR
  ai-assistant-client[AI assistant client] --> remote-mcp-url[Remote MCP URL]
  remote-mcp-url --> streamable-http-transport[Streamable HTTP transport]
  streamable-http-transport --> stateless-direct-response-server[Stateless direct response server]
  stateless-direct-response-server --> auth-and-quota-lookup[Auth and quota lookup]
  auth-and-quota-lookup --> dynamic-tool-configuration[Dynamic tool configuration]
  dynamic-tool-configuration --> hub-and-spaces-tools[Hub and Spaces tools]
  stateless-direct-response-server --> hub-and-spaces-tools
  stateless-direct-response-server --> observability-dashboard[Observability dashboard]
  open-source-server-variants[Open-source server variants] --> streamable-http-transport
Drag to pan · scroll or use +/− to zoom · reconstructed from the source's described component topology

Components

Component Role Interacts with
ai-assistant-client MCP-capable assistant, IDE, chat app, or bridge client that connects to the Hugging Face MCP server. remote-mcp-url, streamable-http-transport
remote-mcp-url Simple public URL entry point for the hosted Hugging Face MCP server. ai-assistant-client, streamable-http-transport
streamable-http-transport Production transport choice for remote MCP, run in stateless direct-response mode. remote-mcp-url, stateless-direct-response-server
stateless-direct-response-server Horizontally scalable request/response MCP server that does not keep per-connection state between requests. streamable-http-transport, auth-and-quota-lookup, dynamic-tool-configuration, hub-and-spaces-tools
auth-and-quota-lookup HF_TOKEN/OAuth lookup layer that applies selected tools, Gradio apps, and ZeroGPU quota for authenticated accounts. stateless-direct-response-server, dynamic-tool-configuration
dynamic-tool-configuration Settings-page-backed tool selection so users can customize the tool set exposed to assistants. auth-and-quota-lookup, hub-and-spaces-tools
hub-and-spaces-tools Assistant-accessible tools for Hub usage, image generation, selected Gradio apps, and thousands of AI applications through Spaces. stateless-direct-response-server
observability-dashboard Connection dashboard for understanding client connection behavior and tool-list change notification handling. stateless-direct-response-server
open-source-server-variants Open-source implementation that can run STDIO, SSE, Streamable HTTP, direct response, and server-push modes for experimentation or compatibility. streamable-http-transport

Data flow

An AI assistant or MCP client connects to the remote hf.co/mcp URL and runs MCP initialization requests such as Initialize, Notifications/Initialize, tools/list, and prompts/list. For each request, the server uses the supplied HF_TOKEN or OAuth credentials when present, looks up the user’s selected tools and Gradio applications, applies quota rules, and answers with direct request/response semantics. Tool calls can then access Hugging Face Hub resources or Spaces. The open-source server can run other transport modes, but the production path avoids server-maintained session state and relies on clients refreshing connections/tool lists instead of long-lived push notifications.

4 supporting quotes
“We also wanted to make access simple by avoiding complicated downloads and configuration, so making it remotely accessible via a simple URL was a must.”article, stated
“For anonymous users we supply a standard set of Tools for using the Hub along with an Image Generator.”article, stated
“This is managed using the supplied HF_TOKEN or OAuth credentials that we look up on request.”article, stated
“The MCP Protocol sends several requests during initialization. A typical connection sequence is: Initialize, Notifications/Initialize, tools/list and then prompts/list.”article, stated

Why this architecture

The architecture favors low-friction remote access and operational simplicity. Dynamic tools are needed because Hugging Face users want different Hub and Spaces capabilities; a simple URL avoids local installation; Streamable HTTP tracks the current MCP direction; and stateless direct response minimizes resource overhead because the current tool set does not need sampling, elicitation, or server-maintained connection state. The team keeps broader transport support in the open-source server for compatibility while choosing the simpler production profile.

4 supporting quotes
“This meant making the MCP Server dynamic by adjusting users' tools on the fly.”article, stated
“Direct Response provides the lowest deployment resource overhead - and we don't currently have any Tools that require Sampling or Elicitation during execution.”article, stated
“None of our existing tools require us to maintain any other state between requests.”article, stated
“our open source code supports all variants, but for production we chose to go with the most modern one.”article, stated

Scale

Alternatives considered (roads not taken)

STDIO transport for production remote access

Rejected because: STDIO is typically for local client/server use on the same computer, while Hugging Face needed remote access by URL.

"STDIO

Typically used when the MCP Server is running on the same computer as the Client."

— article, stated

HTTP with SSE as the production remote transport

Rejected because: SSE was still used by clients but deprecated in favor of Streamable HTTP, so Hugging Face avoided investing heavily in it.

“Used for remote connections over HTTP. Deprecated in the 2025-03-26 version of MCP but still in use.”article, stated
“we didn't want to invest heavily in managing it due to its imminent deprecation.”article, stated

Stateful server-push streams for production

Rejected because: They support notifications and elicitation but require keep-alive, reconnection/resumption, session affinity or shared state, and many idle client connections.

“Server Push Streams - Long-lived SSE connection supporting server-initiated messages.”article, stated
“These connections need extra management such as keep-alive and resumption mechanics on re-connection.”article, stated

Static one-size-fits-all tool list

Rejected because: Hugging Face wanted users to customize tools and selected Gradio applications for their own needs.

“We wanted to let people customize the server for their own needs, as well as easily access thousands of AI applications available on Spaces.”article, stated

Patterns

tool-use-orchestration (integration)

The MCP server exposes Hugging Face resources and Spaces as assistant-accessible tools.

“The Model Context Protocol (MCP) is fulfilling its promise of being the standard to connect AI Assistants to the outside world.”article, implied

observability-tracing (operations)

The implementation includes observability into client connection behavior and tool-list change handling.

“The team implemented comprehensive observability features, including a connection dashboard that provides insights into how different clients manage connections and handle tool list change notifications.”summary, stated

Tradeoffs

Use a stateless direct-response production configuration.

Chose stateless direct response over stateful server-push connection management.

Rationale: The summary says this allowed simple horizontal scaling and avoided session-affinity/shared-state complexity.

“The stateless approach enables simple horizontal scaling where any server instance can handle any request, avoiding the complexity of session affinity or shared state mechanisms that would be required for stateful configurations.”summary, stated

Which remote MCP transport to use in production.

Chose Streamable HTTP over HTTP with SSE or STDIO as the main production path.

Rationale: Streamable HTTP is the newer flexible remote transport, while SSE was deprecated and STDIO is local-first.

"Streamable HTTP

A more flexible remote HTTP transport that provides more options for deployment than the outgoing SSE version"

— article, stated

Whether to support real-time tool-list change notifications at launch.

Chose client refresh/reconnect behavior instead of server-push notifications over maintaining long-lived connections for every configured client.

Rationale: Immediate push would require many idle connections and notifications could still be missed after inactive clients disconnect.

“In practice, it is far simpler for the Client to refresh the connection and Tool List as needed.”article, stated
“using Server Push Streams adds a lot of complexity to a public deployment, when lower-resource solutions for refreshing the Tool List exist.”article, stated

How to make hf.co/mcp friendly in browsers without breaking clients.

Chose browser-aware friendly instructions over always returning a web page or unfriendly JSON/405 behavior.

Rationale: Friendly instructions improved UX, but returning a page to VS Code caused high polling traffic, so browser detection was needed.

“This hugely improves the User Experience - the default response is otherwise an unfriendly bit of JSON.”article, stated
“VSCode would poll the endpoint multiple times per second!”article, stated

Gotchas (what bit them)

Rapid MCP protocol evolution complicated production design choices.

Root cause: Client applications vary in support for protocol features and revisions.

Resolution: Hugging Face built support across transport variants while choosing a simpler production configuration.

“These rapid changes mean support for different MCP Features and revisions in Client applications varies, providing extra challenges for our design choices.”article, stated

Evaluation

No formal evaluation method is described; observability is used to inspect connection behavior.

Outcomes

The case emphasizes production design choices rather than quantified usage outcomes.