YouTube Search MCP Server
Search YouTube videos and download audio via web scraping without API key.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@YouTube Search MCP Serversearch for python tutorials"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
YouTube Search API
Zero-cost YouTube video search service powered by web scraping
Features
✅ No YouTube API key required - completely free
✅ RESTful API design with Swagger documentation
✅ MCP (Model Context Protocol) support - integrate with AI assistants
✅ Redis caching optimization (1 hour TTL)
✅ Complete video metadata extraction
✅ Sorting and filtering capabilities
✅ Docker containerization support
Related MCP server: YouTube MCP Server
Quick Start
Install Dependencies
uv syncStart the Service
python main.pyThe service will start at http://localhost:8000.
API Documentation
Visit http://localhost:8000/docs for interactive API documentation.
API Usage Examples
Basic Search
curl "http://localhost:8000/api/v1/search?keyword=Python tutorial"Specify Result Count
curl "http://localhost:8000/api/v1/search?keyword=Python&limit=5"Sort by Date
curl "http://localhost:8000/api/v1/search?keyword=Python&sort_by=date&limit=3"Audio Download Feature
Download YouTube videos as MP3 audio files with automatic caching and cleanup.
Download Features
✅ Download YouTube videos as 128kbps MP3 files
✅ Support for single and batch downloads
✅ Redis-based caching to avoid duplicate downloads
✅ Automatic cleanup of expired files (24-hour TTL)
✅ Rate limiting: 20 downloads per IP per hour
✅ Video duration limit: maximum 10 minutes
✅ Direct streaming or download link format
Download API Examples
Single Video Download (Link Format)
# Get download link
curl -X POST "http://localhost:8000/api/v1/download/audio?video_id=dQw4w9WgXcQ&format=link"
# Response
{
"video_id": "dQw4w9WgXcQ",
"title": "Rick Astley - Never Gonna Give You Up",
"duration": 212,
"download_url": "http://localhost:8000/downloads/dQw4w9WgXcQ_Rick_Astley.mp3",
"cached": false,
"file_size": 3400000
}Single Video Download (Stream Format)
# Direct MP3 stream - returns binary audio data
curl -X POST "http://localhost:8000/api/v1/download/audio?video_id=dQw4w9WgXcQ&format=stream" -o output.mp3Batch Download
# Download multiple videos at once (max 20)
curl -X POST "http://localhost:8000/api/v1/download/batch" \
-H "Content-Type: application/json" \
-d '{
"video_ids": ["dQw4w9WgXcQ", "jNQXAC9IVRw"]
}'
# Response
{
"total": 2,
"successful": 1,
"failed": 1,
"items": [
{
"video_id": "dQw4w9WgXcQ",
"status": "success",
"download_url": "http://localhost:8000/downloads/...",
"duration": 212,
"cached": false
},
{
"video_id": "jNQXAC9IVRw",
"status": "failed",
"error_message": "Video duration exceeds limit"
}
]
}Configuration
Set these environment variables to customize download behavior:
# Download storage directory
DOWNLOAD_DIR=/tmp/youtube_audio
# Base URL for serving downloads (used in download links)
DOWNLOAD_BASE_URL=http://localhost:8000/downloads
# Download timeout in seconds
DOWNLOAD_TIMEOUT=300
# Maximum video duration in seconds (default: 600 = 10 minutes)
MAX_VIDEO_DURATION=600
# Audio bitrate in kbps
AUDIO_BITRATE=128
# Cache TTL in hours
CACHE_TTL_HOURS=24
# Rate limit: downloads per IP per hour
RATE_LIMIT_DOWNLOAD_PER_HOUR=20
# Enable rate limiting
RATE_LIMIT_ENABLED=trueError Handling
The API returns appropriate HTTP status codes:
400- Invalid video ID or parameters403- Video too long, live stream, or access restricted404- Video not found or deleted503- Download failed or YouTube unavailable507- Server storage full
Cleanup
Expired audio files are automatically deleted after 24 hours. Manual cleanup can be triggered:
# Manual cleanup script
python scripts/cleanup_cron.py
# Schedule with cron (daily at 2 AM)
0 2 * * * /usr/bin/python /path/to/scripts/cleanup_cron.py >> /path/to/logs/cleanup.log 2>&1MCP Integration (Model Context Protocol)
This service provides MCP server functionality, allowing AI assistants (such as Claude Desktop) to directly invoke YouTube search tools via the MCP protocol.
MCP Service Types
HTTP Service: Provided via StreamableHTTPSessionManager, integrated with existing FastAPI application
Supported Transport Modes: HTTP (MVP)
Future Iterations: Consider supporting stdio and SSE modes
REST API and MCP Coexistence
REST API Preservation: Existing REST API endpoints (
/api/v1/search, etc.) remain fully functionalFlexible Deployment: Choose between integrated (same FastAPI app) or separate (independent process) deployment
Backward Compatibility: MCP additions do not modify any existing REST API signatures or behaviors
MCP Configuration
Claude Desktop Setup
Add the following to Claude Desktop's configuration file (~/.config/claude/settings.json or %APPDATA%\Claude\settings.json):
{
"servers": {
"youtube-search-mcp": {
"command": "uv",
"args": ["run", "python", "mcp_stdio.py"],
"env": {
"MCP_SEARCH_TIMEOUT": "15",
"MCP_SEARCH_RETRIES": "3",
"PYTHONUNBUFFERED": "1"
}
}
}
}Environment Variables
MCP_SEARCH_TIMEOUT(default: 15 seconds): Search operation timeoutMCP_SEARCH_RETRIES(default: 3 times): Retry attempts on search failureREDIS_HOST,REDIS_PORT,REDIS_DB: Redis cache configuration (optional)
Starting the MCP Server
# Start MCP server (stdio mode)
python mcp_stdio.py
# Or using uv
uv run python mcp_stdio.pyMCP Tool: youtube_search
Tool Name: youtube_search
Description: Search YouTube videos and return complete metadata
Parameters:
Parameter | Type | Required | Default | Description |
| string | ✅ | - | Search keyword (1-200 characters) |
| integer | ❌ | 1 | Number of results to return (1-100) |
| string | ❌ | relevance | Sort order: |
Response Format:
{
"videos": [
{
"video_id": "mIF-nn_y2_8",
"title": "Jackie Cheung - Farewell Kiss",
"channel": "Music Without Boundaries",
"url": "https://www.youtube.com/watch?v=mIF-nn_y2_8",
"channel_url": "https://www.youtube.com/@channel_name",
"publish_date": "2020-01-15",
"view_count": "1500000",
"description": "Classic Cantonese song..."
}
],
"message": "Successfully returned 1 result"
}Error Handling:
Empty keyword: Returns
{"error": "INVALID_KEYWORD", "message": "Search keyword cannot be empty..."}Invalid limit: Returns
{"error": "INVALID_LIMIT", "message": "limit must be between 1-100..."}YouTube service unavailable: Returns
{"error": "SERVICE_UNAVAILABLE", "message": "YouTube service is temporarily unavailable..."}Cache service failure: Gracefully degrades to direct search and returns normal results
Environment Configuration
Copy .env.example to .env and modify as needed:
cp .env.example .envDocker Deployment
docker-compose up -dTesting
pytest tests/Project Structure
src/youtube_search/
├── models/ # Pydantic data models
├── services/ # Business logic layer
├── api/ # API routes
└── utils/ # Utility functionsLicense
MIT License
Available Tools
1 toolyoutube_searchA
搜尋 YouTube 影片。支援按關鍵字搜尋,可指定結果數量限制(1-100,預設 1)和排序方式(relevance 或 date,預設 relevance)。返回包含視頻 ID、標題、頻道、URL、觀看次數和上傳日期的完整結果。
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | 最大返回結果數(可選,1-100,預設 1) | |
| keyword | Yes | 搜尋關鍵詞(必填,1-200 字元) | |
| sort_by | No | 排序方式(可選,'relevance' 或 'date',預設 'relevance') | relevance |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations, the description carries the full burden. It mentions return fields and parameter defaults but does not disclose rate limits, authentication, error behavior, or any side effects, leaving some behavioral gaps.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is two sentences, front-loaded with the purpose, and contains no unnecessary words. Every sentence adds value, making it highly concise and well-structured.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
For a simple search tool with three parameters and no output schema, the description covers purpose, all parameter options (with defaults), and lists return fields, providing sufficient context for an agent to invoke it correctly.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema coverage is 100%, so the schema already documents all parameters. The description adds little new meaning beyond summarizing defaults and values; it does not compensate with additional context.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states it searches YouTube videos with a specific verb ('搜尋') and resource ('YouTube 影片'), and lists supported operations and return fields, making the purpose unambiguous.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description provides clear context for when to use the tool (to search YouTube by keyword) and explains adjustable parameters, but lacks explicit exclusions or alternatives since no sibling tools exist.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
TDQS
Only one tool exists, so there is no possibility of confusion between tools. The single tool has a clear purpose.
With only one tool, naming consistency is perfect. The name 'youtube_search' follows a clear verb_noun pattern.
The server has only one tool, which feels thin for a video platform. While it covers basic search, typical servers offer more endpoints for a richer interaction.
The server only provides search functionality. Missing features like fetching video details, channel information, or trending videos create significant gaps for a comprehensive YouTube tool.
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
Search YouTube and read video, channel and transcript data as JSON. No Google Cloud project.
Scrape YouTube videos and channels: titles, views, likes, subscriber counts, and upload dates.
YouTube video search with transcript extraction as first-class output.
YouTube transcripts, search, channel/playlist listings and upload tracking for AI agents. No signup.
Related MCP Servers
- -licenseNot gradedqualityNot gradedmaintenanceEnables LLMs to search, download, and extract information from YouTube music videos, converting them to high-quality MP3 files.
- FlicenseBqualityDmaintenanceEnables interaction with YouTube through search and transcript extraction functionality. Allows searching for videos and retrieving full transcripts with timestamps for content analysis.27
- FlicenseNot gradedqualityDmaintenanceEnables LLMs to search YouTube for music, download videos as MP3 files, and play audio with playback controls.8
- AlicenseAqualityCmaintenanceEnables searching, retrieving metadata, and downloading YouTube videos or audio without requiring an API key. It utilizes yt-dlp to support media retrieval and playlist management within MCP-compliant clients like Claude and Cursor.81MIT
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/sacahan/YTSearch'
If you have feedback or need assistance with the MCP directory API, please join our Discord server