YouTube Shorts & Instagram Reels MCP Server
Enables automated posting of videos to YouTube Shorts and Instagram Reels with OAuth 2.0 authentication, file validation, and comprehensive video processing capabilities. Provides MCP-compatible tools for seamless social media video uploads through a FastAPI server.
README
YouTube Shorts & Instagram Reels MCP Server
A Model Context Protocol (MCP) compatible FastAPI server that enables automated posting of videos to YouTube Shorts and Instagram Reels.
Features
- 🎬 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
Quick Start
- 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
API Endpoints
Upload to YouTube Shorts
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"
}
Upload to Instagram Reels
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/"
}
MCP Tool Usage
The server exposes two MCP tools for programmatic access:
post_to_youtube
await post_to_youtube(
title="My Video Title",
description="Video description",
tags=["tag1", "tag2", "tag3"],
video_path="/path/to/video.mp4"
)
post_to_instagram
await post_to_instagram(
caption="My reel caption #hashtag",
video_path="/path/to/video.mp4"
)
Prerequisites & Setup
YouTube API Setup
-
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
Instagram API Setup
-
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
Configuration
Environment Variables
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
File Requirements
Supported Formats
- Video: MP4, MOV, AVI, MKV, WebM
- Max Size: 100MB (configurable)
- Duration: Recommended under 60 seconds for optimal Shorts detection
YouTube Shorts Criteria
- Videos under 60 seconds are automatically tagged as Shorts
- Vertical or square aspect ratios work best
- Resolution: 1080x1920 (9:16) recommended
Instagram Reels Criteria
- Duration: 3-90 seconds
- Aspect ratio: 9:16 (vertical) recommended
- Resolution: 1080x1920 recommended
Testing
Test the Server
# 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"
Run Test Suite
python test_server.py
Error Handling
The 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
Troubleshooting
Common Issues
-
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
Logs and Debugging
Enable debug mode for detailed logging:
DEBUG=True python main.py
Security Considerations
- Store credentials in environment variables, never in code
- Use HTTPS in production
- Implement rate limiting
- Validate all file uploads
- Monitor API usage quotas
License
MIT License - see LICENSE file for details.
File Requirements
Supported Formats
- Video: MP4, MOV, AVI, MKV, WebM
- Max Size: 100MB (configurable)
- Duration: Recommended under 60 seconds for optimal Shorts detection
YouTube Shorts Criteria
- Videos under 60 seconds are automatically tagged as Shorts
- Vertical or square aspect ratios work best
- Resolution: 1080x1920 (9:16) recommended
Instagram Reels Criteria
- Duration: 15-90 seconds
- Aspect ratio: 9:16 (vertical) recommended
- Resolution: 1080x1920 recommended
Configuration
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=60
Error Handling
The 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
Security Considerations
- Store credentials in environment variables, never in code
- Use HTTPS in production
- Implement rate limiting
- Validate all file uploads
- Monitor API usage quotas
Development
Running in Development Mode
DEBUG=True python main.py
Testing the API
# 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"
Troubleshooting
Common Issues
-
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
Logs and Debugging
Enable debug mode for detailed logging:
DEBUG=True python main.py
License
MIT License - see LICENSE file for details.
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
Support
For issues and questions:
- Check the troubleshooting section
- Review API documentation
- Open an issue on GitHub
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。