Labsco
sinjab logo

MCP YouTube Extract

β˜… 19

from sinjab

Extracts information from YouTube videos and channels using the YouTube Data API.

πŸ”₯πŸ”₯πŸ”₯βœ“ VerifiedPaid serviceAdvanced setup

MCP YouTube Extract

PyPI version Python 3.13+ License: MIT Code style: black

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:

pip install mcp-youtube-extract

Visit the package page: mcp-youtube-extract on PyPI

Development

Project Structure

mcp_youtube_extract/
β”œβ”€β”€ src/
β”‚   └── mcp_youtube_extract/
β”‚       β”œβ”€β”€ __init__.py
β”‚       β”œβ”€β”€ server.py          # MCP server implementation
β”‚       β”œβ”€β”€ google_api.py      # yt-info-extract integration
β”‚       β”œβ”€β”€ transcript_api.py  # yt-ts-extract integration
β”‚       β”œβ”€β”€ youtube.py         # Unified API facade
β”‚       └── 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

Testing Strategy

The project uses a comprehensive testing approach:

  1. Unit Tests (test_youtube_unit.py): Test core YouTube functionality with mocked yt-info-extract
  2. Integration Tests (test_context_fix.py, test_with_api_key.py): Test full server functionality
  3. Manual 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

# Install build dependencies
uv add --dev hatch

# Build the package
uv run hatch build

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

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Support

If you encounter any issues or have questions, please:

  1. Check the existing issues
  2. Create a new issue with detailed information about your problem
  3. Include logs and error messages when applicable