Spaces:
Sleeping
Sleeping
Deployment Guide for Hugging Face Spaces
Overview
This guide explains how to deploy the Basicsearch MCP server to Hugging Face Spaces using Docker.
Prerequisites
- A Hugging Face account
- A YouTube Data API v3 key from Google Cloud Console
Deployment Steps
1. Create a New Space
- Go to Hugging Face Spaces
- Click "Create new Space"
- Choose a name for your space
- Select "Docker" as the SDK
- Click "Create Space"
2. Upload Your Code
You can either:
Option A: Use Git (Recommended)
# Clone your space
git clone https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME
cd YOUR_SPACE_NAME
# Copy files from this directory
cp /path/to/basicsearch/* .
# Commit and push
git add .
git commit -m "Initial deployment"
git push
Option B: Upload via Web Interface
- Upload the following files:
Dockerfileapp.pyserver.pypyproject.tomluv.lockREADME.md
3. Configure Environment Variables
- Go to your Space settings
- Navigate to "Repository secrets"
- Add a new secret:
- Name:
YOUTUBE_API_KEY - Value: Your YouTube API key
- Name:
4. Wait for Build
- Hugging Face will automatically detect the Dockerfile and build your container
- This may take a few minutes
- You can monitor the build logs in the "Settings" → "Logs" section
Testing Your Deployment
Once deployed, your Space will be available at:
https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME
Available Endpoints
Health Check
curl https://YOUR_USERNAME-YOUR_SPACE_NAME.hf.space/healthService Info
curl https://YOUR_USERNAME-YOUR_SPACE_NAME.hf.space/List Tools
curl https://YOUR_USERNAME-YOUR_SPACE_NAME.hf.space/toolsSearch YouTube Videos
curl -X POST https://YOUR_USERNAME-YOUR_SPACE_NAME.hf.space/search \ -H "Content-Type: application/json" \ -d '{"query": "Python tutorial", "max_results": 5}'
Architecture
Components
- server.py: Core MCP server with YouTube search functionality
- app.py: FastAPI HTTP wrapper for web deployment
- Dockerfile: Container definition for deployment
Port Configuration
- The server runs on port 7860 (Hugging Face Spaces default)
- This is configured via the
PORTenvironment variable
Troubleshooting
Build Fails
- Check the build logs in Settings → Logs
- Ensure all files are uploaded correctly
- Verify the Dockerfile syntax
API Key Issues
- Ensure
YOUTUBE_API_KEYis set in Repository secrets - The key must have YouTube Data API v3 enabled
- Check quota limits in Google Cloud Console
Connection Issues
- Spaces may take a few minutes to start after deployment
- Check if the Space is in "Running" state
- Review application logs for errors
Local Testing
Before deploying, test locally:
# Build the Docker image
docker build -t basicsearch-mcp .
# Run the container
docker run -p 7860:7860 -e YOUTUBE_API_KEY=your_key_here basicsearch-mcp
# Test the endpoint
curl http://localhost:7860/health
Monitoring
Health Checks
The Docker container includes automatic health checks that run every 30 seconds.
Logs
View logs in your Space's Settings → Logs section to monitor:
- API requests
- Error messages
- Performance metrics
Updating Your Deployment
To update your Space:
# Make your changes locally
# Commit and push
git add .
git commit -m "Update description"
git push
Hugging Face will automatically rebuild and redeploy your Space.
Cost Considerations
- Hugging Face Spaces offers free tier for public spaces
- YouTube Data API has daily quota limits (10,000 units/day by default)
- Each search request costs approximately 100 units
Security Best Practices
- Never commit API keys to your repository
- Use Hugging Face Repository secrets for sensitive data
- Consider implementing rate limiting in production
- Monitor API usage in Google Cloud Console