by sinjab
Extracts YouTube video metadata and transcripts via an MCP server with comprehensive logging and robust error handling.
MCP YouTube Extract provides an MCP‑compatible server that retrieves detailed information from YouTube videos, including title, description, channel, publish date, and full transcripts. It supports both manually created and auto‑generated captions, applying fallback strategies when needed.
pip install mcp-youtube-extract
export YOUTUBE_API_KEY=your_youtube_api_key
mcp_youtube_extract
get_yt_video_info
tool from any MCP client, passing a YouTube video ID.get_yt_video_info
.Q: Do I need a YouTube API key?
A: Yes, YOUTUBE_API_KEY
is required for metadata retrieval. Transcripts are fetched via the YouTube caption service and also need the key.
Q: Can I run the server without installing Python packages globally?
A: Use pipx
or uv
for isolated installations, e.g., pipx install mcp-youtube-extract
or uv sync --dev
from the source.
Q: What happens if a video has no captions? A: The tool returns an empty transcript field and a descriptive message instead of throwing an error.
Q: How is logging handled?
A: The logger.py
module configures rotating file logs and console output with timestamps and log levels.
Q: Is there a way to limit API usage? A: Yes, monitor your quota in the Google Cloud Console and restrict the API key to the YouTube Data API only.
A Model Context Protocol (MCP) server for YouTube operations, demonstrating core MCP concepts including tools and logging.
This package is now available on PyPI! You can install it directly with:
pip install mcp-youtube-extract
Visit the package page: mcp-youtube-extract on PyPI
The easiest way to get started is to install from PyPI:
pip install mcp-youtube-extract
Or using pipx (recommended for command-line tools):
pipx install mcp-youtube-extract
This will install the latest version with all dependencies. You can then run the MCP server directly:
mcp_youtube_extract
For development or if you prefer uv:
# Install uv if you haven't already
curl -LsSf https://astral.sh/uv/install.sh | sh
# Clone and install the project
git clone https://github.com/sinjab/mcp_youtube_extract.git
cd mcp_youtube_extract
# Install dependencies (including dev dependencies)
uv sync --dev
# Set up your API key for development
cp .env.example .env
# Edit .env and add your YouTube API key
Clone the repository:
git clone https://github.com/sinjab/mcp_youtube_extract.git
cd mcp_youtube_extract
Install in development mode:
uv sync --dev
For development, create a .env
file in the project root with your YouTube API key:
# YouTube API Configuration
YOUTUBE_API_KEY=your_youtube_api_key_here
For production, set the environment variable directly in your system:
export YOUTUBE_API_KEY=your_youtube_api_key_here
Required:
YOUTUBE_API_KEY
: Your YouTube Data API key (required for video metadata)To use this MCP server, you'll need a YouTube Data API key. Here's how to get one:
# Install from PyPI
pip install mcp-youtube-extract
# Run the server
mcp_youtube_extract
# Using uv
uv run mcp_youtube_extract
# Or directly
python -m mcp_youtube_extract.server
# Run all pytest tests
uv run pytest
# Run specific pytest test
uv run pytest tests/test_with_api_key.py
# Run tests with coverage
uv run pytest --cov=src/mcp_youtube_extract --cov-report=term-missing
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)The test_inspector.py
file is a standalone script that connects to the MCP server and validates its functionality:
# Run the inspection script to test server connectivity and functionality
uv run python tests/test_inspector.py
This script will:
get_yt_video_info
tool with a sample videoThe server provides one main tool: get_yt_video_info
This tool takes a YouTube video ID and returns:
Example Usage:
# Extract video ID from YouTube URL: https://www.youtube.com/watch?v=dQw4w9WgXcQ
video_id = "dQw4w9WgXcQ"
result = get_yt_video_info(video_id)
To use this MCP server with a client, add the following configuration to your client's settings:
{
"mcpServers": {
"mcp_youtube_extract": {
"command": "mcp_youtube_extract",
"env": {
"YOUTUBE_API_KEY": "your_youtube_api_key"
}
}
}
}
{
"mcpServers": {
"mcp_youtube_extract": {
"command": "uv",
"args": [
"--directory",
"<your-project-directory>",
"run",
"mcp_youtube_extract"
],
"env": {
"YOUTUBE_API_KEY": "your_youtube_api_key"
}
}
}
}
mcp_youtube_extract/
├── src/
│ └── mcp_youtube_extract/
│ ├── __init__.py
│ ├── server.py # MCP server implementation
│ ├── youtube.py # YouTube API utilities
│ └── logger.py # Logging configuration
├── tests/
│ ├── __init__.py
│ ├── test_context_fix.py # Context API fallback tests
│ ├── test_inspector.py # Server inspection tests
│ ├── test_with_api_key.py # Full functionality tests
│ └── test_youtube_unit.py # Unit tests for core functionality
├── logs/ # Application logs
├── .env # Environment variables (create from .env.example)
├── .gitignore # Git ignore rules (includes coverage files)
├── pyproject.toml
├── LICENSE # MIT License
└── README.md
The project uses a comprehensive testing approach:
test_youtube_unit.py
): Test core YouTube functionality with mocked APIstest_context_fix.py
, test_with_api_key.py
): Test full server functionalitytest_inspector.py
): Interactive server inspection toolThe project includes robust error handling:
# Install build dependencies
uv add --dev hatch
# Build the package
uv run hatch build
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
git checkout -b feature/amazing-feature
)git commit -m 'Add some amazing feature'
)git push origin feature/amazing-feature
)If you encounter any issues or have questions, please:
Please log in to share your review and rating for this MCP.
{ "mcpServers": { "mcp_youtube_extract": { "command": "mcp_youtube_extract", "args": [], "env": { "YOUTUBE_API_KEY": "<YOUR_API_KEY>" } } } }
Discover more MCP servers with similar functionality and use cases
by line
Enables AI agents to send, receive, and manage various LINE messages and rich menus through the LINE Messaging API.
by EnesCinr
twitter-mcp is a Model Context Protocol (MCP) server that enables interaction with Twitter, allowing users to post tweets and search for tweets programmatically.
by chaindead
Manage Telegram dialogs, messages, drafts, and read statuses through an MCP server, enabling AI assistants to interact with Telegram seamlessly.
by trypeggy
instagram_dm_mcp is a Model Context Protocol (MCP) server that enables sending Instagram Direct Messages from your account. It allows integration with large language models (LLMs) to automate Instagram messaging and other interactions.
by vidhupv
x-mcp is an MCP server that allows users to create, manage, and publish X/Twitter posts directly through Claude chat.
by ertiqah
Enables GPT‑powered assistants to tap into a user's public LinkedIn activity, allowing automatic post creation, performance analysis, and voice‑consistent rewrites directly from Claude or ChatGPT.
by metricool
mcp-metricool is a Multi-Agent Collaboration Protocol (MCP) server that integrates with Metricool's social media analytics platform, enabling AI agents to access and analyze social media metrics, campaign data, and schedule content across various networks.
by universal-mcp
A Universal MCP server for interacting with Reddit posts, comments, and subreddits.
by netdata
Real-time, per‑second infrastructure monitoring platform that provides instant insights, auto‑discovery, edge‑based machine‑learning anomaly detection, and lightweight visualizations without requiring complex configuration.