Anthropic conceived the Model Context Protocol (MCP), but Hugging Face turned it into a weapon for open-source AI. By allowing developers to attach remote MCP servers directly to HuggingChat—and its underlying open-source engine, chat-ui—open-weights models like Llama 3.3 70B and Qwen 2.5 72B can finally query internal SQL databases, trigger remote API workflows, and execute code hosted inside Hugging Face Spaces without proprietary lock-in.
At 365Finds, we have tracked tool-augmented LLM architectures from brittle bespoke function calling to standardized protocols. We admire HuggingChat's native MCP implementation because it decouples agentic tool definitions from proprietary model providers. However, developers must understand the operational trade-offs: multi-hop network latency, schema context consumption, and the lack of interactive human confirmation before tool invocation.
Here is how to set up the connection, host MCP services on Spaces, and run tools reliably against open-source models.
1. Preparing the Remote MCP Server
HuggingChat operates as an MCP client over remote transports (Streamable HTTP or Server-Sent Events, SSE). It cannot execute standard I/O (stdio) subprocesses running on your local machine. Your MCP server must be exposed as a public or authenticated HTTPS endpoint.
Developers typically take one of two deployment paths on Hugging Face Spaces:
Option A: Native Gradio 5 Spaces
If your tool is built in Python, Gradio 5 automatically exposes application functions as standardized MCP endpoints:
import gradio as gr
def query_sales_database(region: str) -> str:
"""Fetch aggregated sales data for a specific geographic region."""
# Internal database or API logic
return f"Total sales for {region}: $1,240,000 (Active accounts: 312)"
demo = gr.Interface(
fn=query_sales_database,
inputs=gr.Textbox(label="Region"),
outputs=gr.Textbox(label="Result"),
)
if __name__ == "__main__":
demo.launch(mcp_server=True)
Launching with mcp_server=True publishes the tool schema and execution handler directly alongside the web interface.
Option B: FastMCP on a Docker Space
For complex workflows, internal APIs, or multi-tool suites, write a dedicated MCP server using fastmcp or the official Python MCP SDK:
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("CompanyOps")
@mcp.tool()
def search_knowledge_base(query: str, max_results: int = 5) -> str:
"""Search internal technical documentation and knowledge bases."""
# Your vector database or Elasticsearch call here
return f"Retrieved {max_results} results for query: {query}"
if __name__ == "__main__":
mcp.run(transport="sse", port=7860, host="0.0.0.0")
On Hugging Face Spaces, bind the server to port 7860 so the platform routes external HTTPS requests to your container.
2. Connecting the MCP Server in HuggingChat
Once your endpoint is deployed and reachable via HTTPS, connect it to HuggingChat:
- Open HuggingChat: Navigate to HuggingChat and log in to your Hugging Face account.
- Access Tool Settings: Click the
+icon adjacent to the prompt input field (or navigate to Settings > MCP Servers). - Add Server: Click Add Server to open the registration modal.
- Configure Endpoint Details:
- Server Name: A clean, recognizable identifier (for example,
SalesDB-Bridge). - URL: The full HTTPS endpoint of your MCP server (e.g.,
https://username-my-mcp-space.hf.space/sseorhttps://hf.co/mcp). - Headers / Authentication: If your Space is private or requires authorization, pass your Hugging Face User Access Token as a Bearer token in the authorization header:
Authorization: Bearer hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
- Server Name: A clean, recognizable identifier (for example,
- Execute Health Check: Click Health Check. HuggingChat will query the server’s tools list via JSON-RPC. If connectivity and tool manifests succeed, the status badge turns green with a "Connected" confirmation.
- Activate the Server: Toggle the switch to Active to make its tools visible to the chat session.
3. Selecting Tool-Capable Open-Source Models
Not every open-weights LLM can parse and generate tool calls cleanly. Feeding JSON tool declarations to a model unoptimized for function calling leads to hallucinations and broken JSON payloads.
In HuggingChat, 365Finds recommends using:
- HuggingChat Omni Router: HuggingChat’s dynamic model router detects when a user query requires active MCP tools and forwards the conversation specifically to a capable backend.
- Qwen 2.5 72B Instruct: Exceptionally robust JSON schema adherence and tool parameter validation.
- Llama 3.3 70B Instruct: Reliable reasoning across multi-parameter tool calls.
When an active prompt requires external data, the model outputs an internal tool call. HuggingChat intercepts the call, hits your remote MCP endpoint, receives the structured JSON response, and feeds the output back into the conversation context for final synthesis.
4. Enterprise and Self-Hosted Configuration (chat-ui)
If your engineering organization hosts an internal instance of Hugging Face's open-source chat-ui, you can preconfigure global MCP servers for all developers rather than forcing each user to register endpoints manually.
Configure these environment variables in your deployment's .env:
# Define global, trusted MCP servers available to all team members
MCP_SERVERS=[{"name": "Production Metrics", "url": "https://mcp.internal.company.com/mcp", "headers": {"Authorization": "Bearer internal-key"}}, {"name": "Hugging Face Hub", "url": "https://hf.co/mcp"}]
# Forward the logged-in user's Hugging Face Access Token to user-specific endpoints
MCP_FORWARD_HF_USER_TOKEN=true
# Guard against hung backend services
MCP_TOOL_TIMEOUT_MS=15000
# Enable automated model routing for tool calls
LLM_ROUTER_ENABLE_TOOLS=true
Global servers configured via MCP_SERVERS appear automatically across the workspace. Users can toggle them off individually, but cannot delete corporate base endpoints.
5. What 365Finds Likes and What Needs Caution
At 365Finds, our stance is pragmatic:
| Dimension | 365Finds Evaluation | Practical Implication |
|---|---|---|
| Vendor Independence | Outstanding | Breaks OpenAI Action lock-in; tool definitions remain portable across Claude, HuggingChat, and self-hosted agents. |
| Spaces Ecosystem Synergy | High | Thousands of Gradio Spaces on Hugging Face can instantly be turned into agent tools without re-architecting infrastructure. |
| Inference Latency | High Overhead | Stacking round-trips (UI -> inference engine -> remote MCP Space -> inference synthesis) adds 2 to 5 seconds per tool call. |
| Execution Safety | Low Safeguards | HuggingChat lacks interactive human approval prompts prior to running actions; all exposed tools should be idempotent or read-only. |
| Context Window Consumption | Moderate Penalty | Complex schemas eat 1,000 to 3,000 prompt tokens upfront before conversation history begins. |
365Finds specifically advises against exposing write-heavy or destructive database mutations to HuggingChat’s MCP interface. Because the web UI executes tool calls autonomously once the LLM issues the payload, an erroneous hallucination can trigger unintended modifications. Keep remote tools focused on search, document extraction, vector indexing, and read-only analytical queries.