YouTube MCP Server

YouTube MCP Server

Integrates with YouTube's Data API to enable video search, detailed video information retrieval, and transcript fetching with multi-language support and async performance.

Category
访问服务器

README

YouTube MCP Server

A Model Context Protocol (MCP) server that provides comprehensive YouTube integration with video search, detailed video information retrieval, and transcript fetching capabilities.

Features

  • 🔍 Video Search: Search YouTube videos with pagination support
  • 📹 Video Details: Get comprehensive video information including statistics, content details, and metadata
  • 📝 Transcript Fetching: Real transcript extraction with intelligent language prioritization
  • 🌐 Multi-language Support: Automatic language detection and fallback for transcripts
  • ⚡ Async Performance: Built with async/await for optimal performance
  • 🔒 Input/Output Validation: Complete schema validation with detailed error reporting

Tools

1. search_videos

Search for videos on YouTube with flexible pagination.

Parameters:

  • query (string, required): Search query for finding videos
  • pageToken (string, optional): Token for pagination to get next/previous page results

Example:

{
  "query": "python programming tutorial",
  "pageToken": "CAUQAA"
}

Returns: Search results with video snippets and pagination tokens

2. get_videos

Get detailed information about specific YouTube videos.

Parameters:

  • ids (array, required): List of video IDs to retrieve (max 50)
  • parts (array, optional): Parts of video data to retrieve
    • Available parts: snippet, contentDetails, statistics, status, player, recordingDetails, fileDetails, processingDetails, suggestions, liveStreamingDetails, localizations, topicDetails
    • Default: ["snippet"]

Example:

{
  "ids": ["dQw4w9WgXcQ", "9bZkp7q19f0"],
  "parts": ["snippet", "contentDetails", "statistics"]
}

Returns: Comprehensive video data including duration, view counts, like counts, descriptions, and more

3. get_video_transcript

Extract video transcripts with intelligent language handling.

Parameters:

  • videoId (string, required): YouTube video ID
  • language (string, optional): Preferred language code (e.g., 'en', 'es', 'fr')

Language Priority:

  1. Requested language (if specified)
  2. English (fallback)
  3. Manual transcripts (preferred over auto-generated)
  4. Any available transcript

Example:

{
  "videoId": "dQw4w9WgXcQ",
  "language": "en"
}

Returns: Transcript with text segments, precise timestamps, and language metadata

Installation

Prerequisites

  1. YouTube Data API v3 Key:
    • Visit Google Cloud Console
    • Create a new project or select an existing one
    • Enable YouTube Data API v3
    • Create credentials (API Key)
    • Copy the API key for configuration

Setup

  1. Install the server:

    git clone <repository-url>
    cd youtube-mcp-server
    uv sync
    
  2. Configure environment:

    cp .env.example .env
    # Edit .env and add your YouTube API key:
    # YOUTUBE_API_KEY=your_actual_api_key_here
    
  3. Test installation:

    uv run python test_server.py
    

Claude Desktop Integration

Add to your Claude Desktop configuration:

{
  "mcpServers": {
    "youtube": {
      "command": "uvx",
      "args": [
        "--from",
        "git+https://github.com/yourusername/youtube-mcp-server",
        "youtube-mcp-server"
      ],
      "env": {
        "YOUTUBE_API_KEY": "your_youtube_api_key_here"
      }
    }
  }
}

Usage Examples

Basic Video Search

# Search for Python tutorials
result = await search_videos("python programming tutorial")

Get Video Details

# Get comprehensive video information
result = await get_videos(
    ids=["dQw4w9WgXcQ"], 
    parts=["snippet", "contentDetails", "statistics"]
)

Fetch Transcript

# Get transcript in preferred language
result = await get_video_transcript("dQw4w9WgXcQ", language="en")

API Rate Limits

The YouTube Data API v3 has the following quota limits:

  • Default quota: 10,000 units per day
  • Search requests: 100 units each
  • Video details: 1 unit per video
  • Transcript requests: No additional quota cost (uses separate API)

Typical usage:

  • Video search + details: ~110 units (allows ~90 searches/day)
  • Transcript fetching: No quota impact

Development

Project Structure

youtube-mcp-server/
├── youtube_mcp_server/
│   ├── __init__.py
│   ├── __main__.py
│   ├── server.py          # MCP server implementation
│   ├── handlers.py        # Tool function implementations
│   └── tools.json         # Tool schema definitions
├── test_cases.json        # Comprehensive test cases
├── test_server.py         # Test suite with schema validation
├── main.py               # Development entry point
├── pyproject.toml        # Project configuration
└── README.md

Running Tests

# Run comprehensive test suite
uv run python test_server.py

# Run the server locally
uv run python main.py

Adding Features

  1. Define tool schema in youtube_mcp_server/tools.json
  2. Implement function in youtube_mcp_server/handlers.py
  3. Update mapping in TOOL_FUNCTIONS
  4. Add test cases in test_cases.json
  5. Run tests to validate

Error Handling

The server provides comprehensive error handling:

  • 🔑 API Key Issues: Clear messages for missing/invalid YouTube API keys
  • 📊 Quota Management: Informative messages about API quota limits
  • ✅ Input Validation: Detailed validation errors for incorrect parameters
  • 🌐 Network Resilience: Graceful handling of connection issues
  • 🔍 Schema Validation: Full input/output validation with detailed error messages

Technical Details

Dependencies

  • MCP Framework: mcp>=1.6.0 for Model Context Protocol support
  • Google API Client: google-api-python-client>=2.0.0 for YouTube Data API
  • Transcript API: youtube-transcript-api>=0.6.0 for transcript extraction
  • Environment: python-dotenv>=1.0.0 for configuration management
  • Validation: jsonschema>=4.0.0 for schema validation

Performance

  • Async Architecture: All operations use async/await for optimal performance
  • Connection Pooling: Efficient HTTP connection management
  • Error Recovery: Automatic retry logic for transient failures
  • Schema Caching: Tool schemas loaded once at startup

Security

  • Environment Variables: API keys stored securely in environment
  • Input Sanitization: All inputs validated against strict schemas
  • Rate Limiting: Built-in respect for YouTube API rate limits
  • Error Isolation: Detailed error messages without exposing internals

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Implement your changes with tests
  4. Ensure all tests pass: uv run python test_server.py
  5. Submit a pull request

License

MIT License - see LICENSE file for details.

Support

  • Documentation: Check test cases in test_cases.json for usage examples
  • Validation: Run uv run python test_server.py to validate your setup
  • API Reference: YouTube Data API v3 Documentation
  • Issues: Open GitHub issues for bugs or feature requests

Built with ❤️ using the Model Context Protocol framework.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选