A Model Context Protocol (MCP) compatible FastAPI server that enables automated posting of videos to YouTube Shorts and Instagram Reels.
- 🎬 YouTube Shorts Upload: Automatic detection and upload of short-form videos to YouTube
- 📱 Instagram Reels Upload: Direct upload to Instagram Reels with caption support
- 🔐 OAuth 2.0 Authentication: Secure authentication for both platforms
- 🛡️ File Validation: Comprehensive file type and size validation
- 🔄 Token Refresh: Automatic OAuth token refresh for YouTube
- 🎯 MCP Compatible: Full MCP tool integration for seamless automation
- ⚡ Async Operations: High-performance async file handling
- 📏 Video Processing: Automatic video duration detection using ffprobe
- Install dependencies:
pip install -r requirements.txt- Configure credentials:
cp .env.example .env
# Edit .env with your API credentials (see setup sections below)- Start the server:
python main.py- Test the API:
- Visit http://localhost:8000/docs for interactive API documentation
- Use the
/upload/youtubeand/upload/instagramendpoints - Access MCP tools at http://localhost:8000/mcp
POST /upload/youtube
Content-Type: multipart/form-data
file: <video_file>
title: "My Amazing Short"
description: "Check out this cool video!"
tags: "shorts,viral,amazing"Response:
{
"success": true,
"video_id": "dQw4w9WgXcQ",
"watch_url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
}POST /upload/instagram
Content-Type: multipart/form-data
file: <video_file>
caption: "Check out my new reel! #viral #reels"Response:
{
"success": true,
"reel_id": "17841234567890123",
"permalink": "https://www.instagram.com/reel/ABC123def456/"
}The server exposes two MCP tools for programmatic access:
await post_to_youtube(
title="My Video Title",
description="Video description",
tags=["tag1", "tag2", "tag3"],
video_path="/path/to/video.mp4"
)await post_to_instagram(
caption="My reel caption #hashtag",
video_path="/path/to/video.mp4"
)-
Google Cloud Console:
- Go to Google Cloud Console
- Create a new project or select existing one
- Enable YouTube Data API v3 in the API Library
- Create OAuth 2.0 credentials (Desktop application)
-
Get OAuth Tokens:
- Use Google OAuth 2.0 Playground
- Configure with your Client ID and Secret
- Select
https://www.googleapis.com/auth/youtube.uploadscope - Complete OAuth flow and get access_token + refresh_token
-
Facebook Developer Account:
- Go to Facebook Developers
- Create a new app (Business type)
- Add Instagram Graph API product
-
Instagram Business Account:
- Connect your Instagram Business/Creator account to a Facebook Page
- Generate access token with proper permissions
- Get your Instagram User ID
-
File Hosting (Required):
- Instagram requires publicly accessible video URLs
- Configure AWS S3, Cloudinary, or custom hosting in .env
- Videos are temporarily uploaded to hosting service before Instagram API call
Copy .env.example to .env and configure:
# YouTube API Credentials
YOUTUBE_CLIENT_ID=your_client_id.apps.googleusercontent.com
YOUTUBE_CLIENT_SECRET=GOCSPX-your_client_secret
YOUTUBE_ACCESS_TOKEN=ya29.your_access_token
YOUTUBE_REFRESH_TOKEN=1//your_refresh_token
# Instagram API Credentials
INSTAGRAM_ACCESS_TOKEN=IGAAyour_instagram_token
INSTAGRAM_APP_ID=your_app_id
INSTAGRAM_APP_SECRET=your_app_secret
INSTAGRAM_USER_ID=your_user_id
# Server Configuration
HOST=0.0.0.0
PORT=8000
DEBUG=False
# File Upload Configuration
MAX_FILE_SIZE_MB=100
ALLOWED_VIDEO_EXTENSIONS=mp4,mov,avi,mkv,webm- Video: MP4, MOV, AVI, MKV, WebM
- Max Size: 100MB (configurable)
- Duration: Recommended under 60 seconds for optimal Shorts detection
- Videos under 60 seconds are automatically tagged as Shorts
- Vertical or square aspect ratios work best
- Resolution: 1080x1920 (9:16) recommended
- Duration: 3-90 seconds
- Aspect ratio: 9:16 (vertical) recommended
- Resolution: 1080x1920 recommended
# Test health endpoint
curl http://localhost:8000/health
# Test YouTube upload
curl -X POST "http://localhost:8000/upload/youtube" \
-F "file=@test_video.mp4" \
-F "title=Test Video" \
-F "description=Test Description" \
-F "tags=test,api"
# Test Instagram upload
curl -X POST "http://localhost:8000/upload/instagram" \
-F "file=@test_video.mp4" \
-F "caption=Test reel #test"python test_server.pyThe server provides detailed error responses:
{
"success": false,
"error": "File too large. Maximum size is 100MB"
}Common error scenarios:
- Invalid file format
- File too large
- Authentication failures
- API rate limits
- Network timeouts
-
YouTube Authentication Errors
- Verify OAuth credentials are correct
- Check if access token has expired (auto-refreshed)
- Ensure YouTube Data API v3 is enabled
-
Instagram Upload Failures
- Verify Instagram Business/Creator account is linked
- Check access token permissions
- Ensure video meets Instagram requirements
- Configure file hosting (AWS S3, Cloudinary, etc.)
-
File Upload Issues
- Check file size limits
- Verify file format is supported
- Ensure sufficient disk space for temporary files
Enable debug mode for detailed logging:
DEBUG=True python main.py- Store credentials in environment variables, never in code
- Use HTTPS in production
- Implement rate limiting
- Validate all file uploads
- Monitor API usage quotas
MIT License - see LICENSE file for details.
- Video: MP4, MOV, AVI, MKV, WebM
- Max Size: 100MB (configurable)
- Duration: Recommended under 60 seconds for optimal Shorts detection
- Videos under 60 seconds are automatically tagged as Shorts
- Vertical or square aspect ratios work best
- Resolution: 1080x1920 (9:16) recommended
- Duration: 15-90 seconds
- Aspect ratio: 9:16 (vertical) recommended
- Resolution: 1080x1920 recommended
Environment variables can be customized:
# Server Configuration
HOST=0.0.0.0
PORT=8000
DEBUG=False
# File Upload Configuration
MAX_FILE_SIZE_MB=100
ALLOWED_VIDEO_EXTENSIONS=mp4,mov,avi,mkv,webm
# API Rate Limiting
RATE_LIMIT_REQUESTS_PER_MINUTE=60The server provides detailed error responses:
{
"success": false,
"error": "File too large. Maximum size is 100MB"
}Common error scenarios:
- Invalid file format
- File too large
- Authentication failures
- API rate limits
- Network timeouts
- Store credentials in environment variables, never in code
- Use HTTPS in production
- Implement rate limiting
- Validate all file uploads
- Monitor API usage quotas
DEBUG=True python main.py# Test health endpoint
curl http://localhost:8000/health
# Test YouTube upload
curl -X POST "http://localhost:8000/upload/youtube" \
-F "file=@test_video.mp4" \
-F "title=Test Video" \
-F "description=Test Description" \
-F "tags=test,api"-
YouTube Authentication Errors
- Verify OAuth credentials are correct
- Check if access token has expired
- Ensure YouTube Data API v3 is enabled
-
Instagram Upload Failures
- Verify Instagram Business/Creator account is linked
- Check access token permissions
- Ensure video meets Instagram requirements
-
File Upload Issues
- Check file size limits
- Verify file format is supported
- Ensure sufficient disk space for temporary files
Enable debug mode for detailed logging:
DEBUG=True python main.pyMIT License - see LICENSE file for details.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
For issues and questions:
- Check the troubleshooting section
- Review API documentation
- Open an issue on GitHub