This guide walks through deploying the Document-MCP application to Hugging Face Spaces.
- Hugging Face Account: Sign up at https://huggingface.co/join
- OAuth Application: Created at https://huggingface.co/settings/connected-applications
- Git with HF CLI (optional but recommended):
pip install huggingface_hub
-
Fill in details:
- Space name:
Document-MCP(or your preferred name) - License:
apache-2.0ormit - Select the SDK: Choose Docker
- Space hardware: Start with CPU basic (free tier)
- Visibility: Public or Private
- Space name:
-
Click Create Space
IMPORTANT: HF Spaces run at a different URL than the management page. Your app's actual URL will be detected automatically via request headers.
If you haven't already created an OAuth app:
-
Go to https://huggingface.co/settings/connected-applications
-
Click Create new application
-
Fill in:
- Application Name:
Documentation-MCP - Homepage URL:
https://huggingface.co/spaces/YOUR_USERNAME/Document-MCP - Redirect URI:
https://huggingface.co/spaces/YOUR_USERNAME/Document-MCP/auth/callback - Scopes: Select
openidandprofile
- Application Name:
-
Click Create
-
Save the Client ID and Client Secret - you'll need these for environment variables
Note: The OAuth redirect URI will automatically adjust to your Space's actual running URL (e.g., https://YOUR_USERNAME-document-mcp.hf.space/auth/callback) via HTTP headers. The configured HF_SPACE_URL is only used as a fallback.
In your HF Space settings, add these secrets:
- Go to your Space:
https://huggingface.co/spaces/YOUR_USERNAME/Document-MCP - Click Settings tab
- Scroll to Repository secrets
- Add the following secrets:
JWT_SECRET_KEY=<generate-a-random-32-char-string>
HF_OAUTH_CLIENT_ID=<your-oauth-client-id>
HF_OAUTH_CLIENT_SECRET=<your-oauth-client-secret>
HF_SPACE_URL=https://huggingface.co/spaces/YOUR_USERNAME/Document-MCP
Note on HF_SPACE_URL: This is only a fallback. The application automatically detects its actual running URL using X-Forwarded-Host and X-Forwarded-Proto headers set by HF Spaces proxy. You can set this to the Space management URL for simplicity.
Run this to generate a secure random key:
python3 -c "import secrets; print(secrets.token_hex(32))"Or:
openssl rand -hex 32# Clone your HF Space repository
git clone https://huggingface.co/spaces/YOUR_USERNAME/Document-MCP
cd Document-MCP
# Copy all project files (excluding .git)
cp -r /path/to/Document-MCP/{backend,frontend,Dockerfile,.dockerignore} .
# Add and commit
git add .
git commit -m "Initial deployment"
# Push to HF Space
git push# Install HF CLI
pip install huggingface_hub
# Login
huggingface-cli login
# Upload repository
cd /path/to/Document-MCP
huggingface-cli upload YOUR_USERNAME/Document-MCP . --repo-type=space- Go to Files tab in your Space
- Click Add file → Upload files
- Upload:
Dockerfile.dockerignorebackend/directory (all contents)frontend/directory (all contents)
- HF Spaces will automatically build your Docker container
- Check the Logs tab to monitor build progress
- Build typically takes 5-10 minutes for first deployment
- Once complete, your app will be available at:
https://YOUR_USERNAME-Document-MCP.hf.space
- Open the Space URL in your browser
- You should see the Login page
- Click Sign in with Hugging Face
- Authorize the OAuth app
- You'll be redirected back to the app with a JWT token
- Browse the demo vault with pre-seeded notes
The Space exposes the MCP server over HTTPS so tools like Claude Desktop can connect without running anything locally. Every JWT maps to an isolated vault directory (data/vaults/<user_id>), so each Hugging Face account sees only its own notes.
-
Get your JWT token:
- Go to the in-app Settings page
- Click Copy token (or generate a new one)
-
Configure your MCP client (example for Claude Desktop):
{
"mcpServers": {
"obsidian-docs": {
"transport": "http",
"url": "https://YOUR_USERNAME-Document-MCP.hf.space/mcp",
"headers": {
"Authorization": "Bearer YOUR_JWT_TOKEN_HERE"
}
}
}
}- Local development (optional): If you want to run the MCP server via STDIO on your laptop, use the "Local Development" snippet from the app's Settings page.
Check logs in the Space's "Logs" tab. Common issues:
- npm install fails: Check
frontend/package.jsondependencies - Python install fails: Check
backend/pyproject.tomldependencies - Out of memory: Upgrade to a paid tier with more RAM
The app now auto-detects its URL from request headers. If OAuth fails:
- Check HF Space application logs for "OAuth base URL" messages to see what URL was detected
- Verify your OAuth app's Redirect URI matches one of:
- The Space management URL:
https://huggingface.co/spaces/YOUR_USERNAME/Document-MCP/auth/callback - The running app URL (shown in logs):
https://YOUR_USERNAME-document-mcp.hf.space/auth/callback
- The Space management URL:
- Ensure OAuth app scopes include
openidandprofile - Try updating your OAuth app's Redirect URI to match the URL shown in the logs
- Check application logs in the Space's "Logs" tab
- Verify all environment variables are set correctly
- Ensure
JWT_SECRET_KEYis at least 16 characters
This is expected - the demo uses ephemeral storage. Data resets on container restart. The app seeds demo content on every startup.
For persistent storage, you'd need to:
- Upgrade to HF Spaces Pro with persistent storage
- Or use external database (Supabase, PlanetScale, etc.)
To deploy updates:
cd /path/to/Document-MCP
git add .
git commit -m "Update: description of changes"
git pushHF Spaces will automatically rebuild and redeploy.
- View logs: Space Logs tab
- Check build status: Space "Building" indicator
- Test health endpoint:
https://YOUR_USERNAME-Document-MCP.hf.space/health
- CPU basic: Free tier, sufficient for demo/personal use
- Persistent storage: Requires paid tier ($5-20/month)
- More CPU/RAM: Upgrade if you experience slow performance
- HF Spaces Docs: https://huggingface.co/docs/hub/spaces
- OAuth Docs: https://huggingface.co/docs/hub/oauth
- Docker SDK Guide: https://huggingface.co/docs/hub/spaces-sdks-docker