Hub documentation
Building with the SDK
Hub
Building with the SDK
Build MCP-powered agents with the Hugging Face agentic SDKs. Thehuggingface_hub (Python) and@huggingface/tiny-agents (JavaScript) libraries provide everything you need to connect LLMs to MCP tools.
Installation
Python
JavaScript
pip install"huggingface_hub[mcp]"Quick Start: Run an Agent
The fastest way to get started is with thetiny-agents CLI:
Python
JavaScript
tiny-agents run julien-c/flux-schnell-generator
This loads an agent from thetiny-agents collection, connects to its MCP servers, and starts an interactive chat.
Using the Agent Class
TheAgent class manages the chat loop and MCP tool execution. It usesInference Providers to run the LLM.
Python
JavaScript
from huggingface_hubimport Agentimport asyncioagent = Agent( model="Qwen/Qwen2.5-72B-Instruct", provider="novita", servers=[ {"type":"sse","url":"https://evalstate-flux1-schnell.hf.space/gradio_api/mcp/sse" } ])asyncdefmain():asyncfor chunkin agent.run("Generate an image of a sunset"):ifhasattr(chunk,'choices'): delta = chunk.choices[0].deltaif delta.content:print(delta.content, end="")asyncio.run(main())
See theAgent reference for all options.
Using MCPClient Directly
For more control, useMCPClient to manage MCP servers and tool calls directly.
Python
JavaScript
import asynciofrom huggingface_hubimport MCPClientasyncdefmain():asyncwith MCPClient( model="Qwen/Qwen2.5-72B-Instruct", provider="novita", )as client:# Connect to an MCP serverawait client.add_mcp_server(type="sse", url="https://evalstate-flux1-schnell.hf.space/gradio_api/mcp/sse" )# Process a request with tools messages = [{"role":"user","content":"Generate an image of a sunset"}]asyncfor chunkin client.process_single_turn_with_tools(messages):ifhasattr(chunk,'choices'): delta = chunk.choices[0].deltaif delta.content:print(delta.content, end="")asyncio.run(main())
See theMCPClient reference for all options.
Share Your Agent
Contribute agents to thetiny-agents collection on the Hub. Include:
agent.json- Agent configuration (required)PROMPT.mdorAGENTS.md- System prompt (optional)EXAMPLES.md- Sample prompts and use cases (optional)
Learn More
- huggingface_hub MCP Reference - Python API reference
- tiny-agents Documentation - JavaScript API reference
- Inference Providers - Available LLM providers
- tiny-agents Collection - Browse community agents
- MCP Server Guide - Connect to the Hugging Face MCP Server