MCP Deployment Guide for Hugging Face Spaces
What We Built
Your Thumbnail Crafter Space is now MCP-compatible! It can be called as a tool by AI assistants like HuggingChat.
Files Created
main.py- FastAPI server with MCP/toolsendpointtools.json- Tool schema for HuggingChat discoveryrequirements.txt- Python dependenciesDockerfile- Container configuration for Hugging Face SpacesREADME.md- Updated documentation
Deployment Steps
1. Push to Hugging Face
# Make sure you're in your project directory
cd "C:\HuggingFace\Huggy thumbnail crafter"
# Add all new files
git add main.py tools.json requirements.txt Dockerfile README.md
# Commit the changes
git commit -m "feat: Add MCP compatibility for HuggingChat integration
- Add FastAPI backend with /tools endpoint
- Implement generate_thumbnail and get_available_layouts tools
- Add Docker support for hybrid React + Python deployment
- Update README with MCP usage instructions"
# Push to Hugging Face
git push
2. Wait for Space to Rebuild
Once you push, Hugging Face will automatically:
- Detect the
Dockerfile - Build the Docker image
- Deploy your Space with both React frontend + Python backend
This may take 5-10 minutes.
3. Test the MCP Endpoint
Once deployed, test that the MCP endpoint works:
# Replace with your Space URL
curl -X POST https://huggingface.co/spaces/Chunte/Thumbnail-Crafter.mini/tools \\
-H "Content-Type: application/json" \\
-d '{"name":"get_available_layouts","arguments":{}}'
You should see a streaming JSON response:
{"output": true, "data": {"success": true, "layouts": [...]}}
{"output": false}
4. Register in HuggingChat
Option A: Automatic Discovery (if supported)
HuggingChat should automatically discover your Space's tools.json file.
Option B: Manual Registration
- Go to HuggingChat
- Click Settings β MCP Servers
- Click "Add Server"
- Enter your Space URL:
https://huggingface.co/spaces/Chunte/Thumbnail-Crafter.mini - Enable the server
5. Use in HuggingChat
Once registered, you can ask HuggingChat:
Generate a thumbnail for my new model "BERT-FineTuned"
with a red background and white text
HuggingChat will:
- Recognize it needs to generate a thumbnail
- Call your Space's
generate_thumbnailtool - Return the generated image
Available Tools
1. generate_thumbnail
Generates a custom thumbnail image.
Parameters:
title(string, required): Main text to displaylayout(string): Layout type - "impactTitle", "hfLogo", or "custom" (default: "impactTitle")bg_color(string): Background color hex (default: "#1a1a1a")text_color(string): Text color hex (default: "#ffffff")width(integer): Canvas width (default: 1280)height(integer): Canvas height (default: 720)
Returns:
- Base64-encoded PNG image
- Metadata (width, height, size, etc.)
Example:
{
"name": "generate_thumbnail",
"arguments": {
"title": "My AI Model",
"layout": "impactTitle",
"bg_color": "#FF6B6B",
"text_color": "#FFFFFF"
}
}
2. get_available_layouts
Returns list of available layout templates.
Parameters: None
Returns:
- Array of layout objects with id, name, and description
Local Testing
Start the Server Locally
# Install dependencies
pip install -r requirements.txt
# Run the server
python main.py
Server will run at http://localhost:7860
Test with Python
import requests
import json
response = requests.post(
"http://localhost:7860/tools",
json={
"name": "get_available_layouts",
"arguments": {}
},
stream=True
)
for line in response.iter_lines():
if line:
print(json.loads(line.decode('utf-8')))
Test with curl
curl -X POST http://localhost:7860/tools \\
-H "Content-Type: application/json" \\
-d '{"name":"get_available_layouts","arguments":{}}'
Endpoints
/- React frontend (when deployed)/tools- MCP endpoint for HuggingChat/tools.json- Tool schema definition/api/info- API information/health- Health check
Troubleshooting
Space Build Fails
Check Docker logs in your Space's "Build" tab
Common issues:
- Missing files in git (make sure all files are pushed)
- Invalid Dockerfile syntax
- Missing Python dependencies
MCP Endpoint Returns Error
- Check
/healthendpoint is responding - Verify
tools.jsonis accessible - Check server logs in Space settings
HuggingChat Can't Find Tools
- Verify
tools.jsonis in the root directory - Check that
/toolsendpoint returns200 OK - Try manual registration in HuggingChat settings
Image Generation Fails
Font not found: The server tries multiple font paths. If all fail, it uses a default font.
To add custom fonts, modify the Dockerfile:
RUN apt-get install -y fonts-liberation
COPY path/to/your/font.ttf /usr/share/fonts/truetype/
Architecture
βββββββββββββββββββββββββββββββββββββββ
β Hugging Face Space β
β β
β βββββββββββββββββββββββββββββββ β
β β FastAPI Backend (port 7860) β β
β β β β
β β β’ /tools (MCP endpoint) β β
β β β’ /api/info β β
β β β’ / (serves React app) β β
β βββββββββββββββββββββββββββββββ β
β β
β βββββββββββββββββββββββββββββββ β
β β React Frontend (static) β β
β β Built files in /static β β
β βββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββ
β
β HTTP/HTTPS
β
ββββββββ΄βββββββ
β HuggingChat β
β (AI Client) β
βββββββββββββββ
Next Steps
- Deploy to Hugging Face - Push your changes
- Test the endpoint - Verify
/toolsworks - Register in HuggingChat - Add your Space as an MCP server
- Try it out - Ask HuggingChat to generate thumbnails!
Support
Built with Claude Code π€