# Remote HTTP Server for yt-dlp-mcp ## Overview The yt-dlp-mcp HTTP server provides remote access to all yt-dlp MCP tools using the official **Streamable HTTP** transport protocol from the Model Context Protocol specification. This allows you to: - Deploy yt-dlp-mcp on a server and access it from multiple clients - Use yt-dlp tools from Claude Desktop, Cline, or other MCP clients over HTTP - Share a single yt-dlp installation across a team or organization - Run downloads on a dedicated machine with better bandwidth/storage ## Quick Start ### Installation ```bash npm install -g @kevinwatt/yt-dlp-mcp ``` ### Start the Server ```bash # Start with defaults (port 3000, host 0.0.0.0) yt-dlp-mcp-http # Or with custom configuration YTDLP_HTTP_PORT=8080 YTDLP_API_KEY=your-secret-key yt-dlp-mcp-http ``` The server will start and display: ``` ╔════════════════════════════════════════════════╗ ║ 🎬 yt-dlp-mcp HTTP Server ║ ╟────────────────────────────────────────────────╢ ║ Version: 0.7.0 ║ ║ Protocol: Streamable HTTP (MCP Spec) ║ ║ Endpoint: http://0.0.0.0:3000/mcp ║ ║ Health: http://0.0.0.0:3000/health ║ ╟────────────────────────────────────────────────╢ ║ Security: ║ ║ • API Key: ✓ Enabled ║ ║ • CORS: * ║ ║ • Rate Limit: 60/min per session ║ ║ • Session Timeout: 60 minutes ║ ╚════════════════════════════════════════════════╝ ``` ## Configuration ### Environment Variables | Variable | Default | Description | |----------|---------|-------------| | `YTDLP_HTTP_PORT` | `3000` | Server port | | `YTDLP_HTTP_HOST` | `0.0.0.0` | Server host (use `0.0.0.0` for all interfaces) | | `YTDLP_API_KEY` | (none) | API key for authentication (highly recommended) | | `YTDLP_CORS_ORIGIN` | `*` | CORS allowed origin (use specific origin in production) | | `YTDLP_RATE_LIMIT` | `60` | Max requests per minute per session | | `YTDLP_SESSION_TIMEOUT` | `3600000` | Session timeout in milliseconds (1 hour) | Plus all standard yt-dlp-mcp environment variables: - `YTDLP_DOWNLOADS_DIR` - `YTDLP_DEFAULT_RESOLUTION` - `YTDLP_DEFAULT_SUBTITLE_LANG` - etc. ### Production Configuration Example ```bash # Create a .env file cat > .env <` header - Ensure no extra whitespace in the key ### 429 Rate Limit - Increase rate limit: `export YTDLP_RATE_LIMIT=120` - Check if client is reusing sessions properly - Verify session IDs are being tracked ### CORS Errors ```bash # Allow specific origin export YTDLP_CORS_ORIGIN=https://your-app.com # Allow all origins (development only) export YTDLP_CORS_ORIGIN=* ``` ## Architecture ### Streamable HTTP Transport The server uses the official MCP Streamable HTTP transport which: - Supports Server-Sent Events (SSE) for streaming responses - Maintains stateful sessions with automatic cleanup - Provides JSON-RPC 2.0 message handling - Implements protocol version negotiation ### Session Management - Each client connection creates a unique session (UUID) - Sessions auto-expire after inactivity (default: 1 hour) - Expired sessions are cleaned up every 5 minutes - Rate limiting is per-session ### Security Layers ``` Client Request ↓ CORS Middleware (Origin validation) ↓ API Key Middleware (Bearer token) ↓ Rate Limiting (Per-session counter) ↓ MCP Transport (Request validation, 4MB limit) ↓ Tool Handlers (Zod schema validation) ↓ yt-dlp Execution ``` ## Performance ### Benchmarks - ~50-100ms latency for metadata operations - ~200-500ms for search operations - Download speeds limited by yt-dlp and network bandwidth - Can handle 100+ concurrent sessions on modern hardware ### Optimization Tips 1. Use SSD for downloads directory 2. Increase rate limits for trusted clients 3. Deploy on server with good bandwidth 4. Use CDN/caching for frequently accessed videos 5. Monitor and tune session timeout based on usage ## Comparison: HTTP vs Stdio | Feature | HTTP Server | Stdio (Local) | |---------|-------------|---------------| | Remote Access | ✅ Yes | ❌ No | | Multi-client | ✅ Yes | ❌ No | | Authentication | ✅ API Keys | ❌ N/A | | Rate Limiting | ✅ Built-in | ❌ No | | Session Management | ✅ Stateful | ❌ Stateless | | Setup Complexity | Medium | Easy | | Latency | Higher | Lower | | Use Case | Production, Teams | Personal, Development | ## License Same as parent project (MIT) ## Support - GitHub Issues: https://github.com/kevinwatt/yt-dlp-mcp/issues - MCP Specification: https://spec.modelcontextprotocol.io