Optional integration with YouTube Data API v3 for enhanced metadata extraction functionality as a fallback mechanism.
Extracts video information including metadata (title, description, channel, publish date, view count) and transcripts from YouTube videos without requiring an API key.
MCP YouTube Extract
A Model Context Protocol (MCP) server for YouTube operations, demonstrating core MCP concepts including tools and logging.
⨠No API Key Required! Works out of the box using yt-info-extract for video metadata and yt-ts-extract for transcripts.
Features
MCP Server: A fully functional MCP server with:
Tools: Extract information from YouTube videos including metadata and transcripts
Comprehensive Logging: Detailed logging throughout the application
Error Handling: Robust error handling with fallback logic for transcripts
YouTube Integration: Built-in YouTube capabilities using yt-info-extract and yt-ts-extract:
Extract video information (title, description, channel, publish date, view count)
Get video transcripts with intelligent fallback logic
Support for both manually created and auto-generated transcripts
No API key required for basic functionality
š¦ Available on PyPI
This package is now available on PyPI! You can install it directly with:
Visit the package page: mcp-youtube-extract on PyPI
Installation
Quick Start (Recommended)
The easiest way to get started is to install from PyPI:
Or using pipx (recommended for command-line tools):
This will install the latest version with all dependencies. You can then run the MCP server directly:
Using uv (Development)
For development or if you prefer uv:
From source
Clone the repository:
git clone https://github.com/sinjab/mcp_youtube_extract.git cd mcp_youtube_extractInstall in development mode:
uv sync --dev
Configuration
Environment Variables
No configuration required! The server works out of the box using yt-info-extract for metadata extraction.
Optional: For enhanced functionality, you can optionally set a YouTube API key:
Optional:
YOUTUBE_API_KEY: Your YouTube Data API key (optional, provides additional fallback for metadata extraction)
Getting Your YouTube API Key (Optional)
While not required, you can optionally set up a YouTube Data API key for enhanced functionality. Here's how to get one:
Step 1: Create a Google Cloud Project
Go to the Google Cloud Console
Click "Select a project" at the top of the page
Click "New Project" and give it a name (e.g., "MCP YouTube Extract")
Click "Create"
Step 2: Enable the YouTube Data API
In your new project, go to the API Library
Search for "YouTube Data API v3"
Click on it and then click "Enable"
Step 3: Create API Credentials
Go to the Credentials page
Click "Create Credentials" and select "API Key"
Your new API key will be displayed - copy it immediately
Click "Restrict Key" to secure it (recommended)
Step 4: Restrict Your API Key (Recommended)
In the API key settings, click "Restrict Key"
Under "API restrictions", select "Restrict key"
Choose "YouTube Data API v3" from the dropdown
Click "Save"
Step 5: Set Up Billing (Required)
Go to the Billing page
Link a billing account to your project
Note: YouTube Data API has a free tier of 10,000 units per day, which is typically sufficient for most use cases
API Key Usage Limits
Free Tier: 10,000 units per day
Cost: $5 per 1,000 units after free tier
Note: API key is only used as a fallback when yt-info-extract fails
Most users won't need an API key as yt-info-extract handles most requests
Security Best Practices
Never commit your API key to version control
Use environment variables as shown in the configuration section
Restrict your API key to only the YouTube Data API
Monitor usage in the Google Cloud Console
Usage
Running the MCP Server
Using PyPI Installation (Recommended)
Using Development Setup
Running Tests
Note: The tests/ directory contains 4 files:
test_context_fix.py- Pytest test for context API fallback functionalitytest_with_api_key.py- Pytest test for full functionality with API keytest_youtube_unit.py- Unit tests for core YouTube functionalitytest_inspector.py- Standalone inspection script (not a pytest test)
Test Coverage: The project currently has 62% overall coverage with excellent coverage of core functionality:
youtube.py: 81% coverage (core business logic)logger.py: 73% coverage (logging utilities)server.py: 22% coverage (MCP protocol handling)__init__.py: 100% coverage (package initialization)
Running the Inspection Script
The test_inspector.py file is a standalone script that connects to the MCP server and validates its functionality:
This script will:
Connect to the MCP server
List available tools, resources, and prompts
Test the
get_yt_video_infotool with a sample videoValidate that the server is working correctly
Using the YouTube Tool
The server provides one main tool: get_yt_video_info
This tool takes a YouTube video ID and returns:
Video metadata (title, description, channel, publish date, view count) via yt-info-extract
Video transcript (with fallback logic for different transcript types) via yt-ts-extract
Example Usage:
Client Configuration
To use this MCP server with a client, add the following configuration to your client's settings:
Using PyPI Installation (Recommended)
With optional API key:
Using Development Setup
With optional API key:
Development
Project Structure
Testing Strategy
The project uses a comprehensive testing approach:
Unit Tests (
test_youtube_unit.py): Test core YouTube functionality with mocked yt-info-extractIntegration Tests (
test_context_fix.py,test_with_api_key.py): Test full server functionalityManual Validation (
test_inspector.py): Interactive server inspection tool
Error Handling
The project includes robust error handling:
Graceful extraction failures: Returns appropriate error messages instead of crashing
Multiple fallback strategies: yt-info-extract provides automatic fallback between YouTube Data API, yt-dlp, and pytubefix
Transcript fallback logic: Multiple strategies for transcript retrieval via yt-ts-extract
Consistent error responses: Standardized error message format
Comprehensive logging: Detailed logs for debugging and monitoring
Building
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Getting Started
Fork the repository
Create a feature branch (
git checkout -b feature/amazing-feature)Commit your changes (
git commit -m 'Add some amazing feature')Push to the branch (
git push origin feature/amazing-feature)Open a Pull Request
Support
If you encounter any issues or have questions, please:
Check the existing issues
Create a new issue with detailed information about your problem
Include logs and error messages when applicable