YouTube MCP Server
Streamable HTTP MCP server for YouTube that enables video search, channel exploration, playlist browsing, and video detail retrieval via the YouTube Data API.
README
YouTube MCP Server
Streamable HTTP MCP server for YouTube — search videos, explore channels, browse playlists, and fetch video details.
Author: overment
[!WARNING] You connect this server to your MCP client at your own responsibility. Language models can make mistakes, misinterpret instructions, or perform unintended actions. Review tool outputs before acting on them. The HTTP layer is designed for convenience during development, not production-grade security.
Notice
This repo works in two ways:
- As a Node/Hono server for local workflows
- As a Cloudflare Worker for remote interactions
How It Works
MCP Client ──► YouTube MCP Server ──► YouTube Data API v3 ──► structured results
All five tools are read-only queries against the YouTube Data API v3. They return both human-readable text summaries and structured JSON output (structuredContent), so LLMs and downstream agents can consume the data directly.
Features
- ✅ Search Videos — Find videos across YouTube by keyword, with sort and date filters
- ✅ Find Channels — Look up channels by name, get channel IDs for further exploration
- ✅ Scan Channels — Fetch the latest videos from any channel
- ✅ Browse Playlists — List playlists from a channel or videos from a specific playlist
- ✅ Video Details — Get full metadata: duration, views, likes, comments, tags, description
- ✅ Structured Output — Every tool returns both text and
structuredContent(MCP outputSchema) - ✅ Flexible Auth — API key via client header or server config
- ✅ Dual Runtime — Node.js/Bun or Cloudflare Workers
Installation
Prerequisites: Bun and a YouTube Data API v3 key (enable "YouTube Data API v3" in your GCP project).
Ways to Run (Pick One)
- Local (API key) — Fastest start
- Cloudflare Worker (wrangler dev) — Local Worker testing
- Cloudflare Worker (deploy) — Remote production
1. Local (API Key) — Quick Start
git clone <repo>
cd youtube-mcp
bun install
Create .env:
PORT=3000
AUTH_STRATEGY=none
bun dev
# MCP: http://127.0.0.1:3000/mcp
The YouTube API key can be provided in two ways:
Option A — Client header (recommended for multi-user):
Each MCP client request includes the key via X-YouTube-Api-Key header.
Option B — Server-side fallback:
Set API_KEY in .env so the server uses it when no client header is present:
AUTH_STRATEGY=api_key
API_KEY=AIzaSy...your_youtube_key
Connect to your MCP client:
Claude Desktop / Cursor:
{
"mcpServers": {
"youtube": {
"command": "bunx",
"args": [
"mcp-remote",
"http://localhost:3000/mcp",
"--header",
"X-YouTube-Api-Key: ${YOUTUBE_API_KEY}"
]
}
}
}
Or without the header (if API_KEY is set server-side):
{
"mcpServers": {
"youtube": {
"command": "bunx",
"args": ["mcp-remote", "http://localhost:3000/mcp", "--transport", "http-only"],
"env": { "NO_PROXY": "127.0.0.1,localhost" }
}
}
}
2. Cloudflare Worker (Local Dev)
bun x wrangler dev --local | cat
Set the API key as a secret:
bun x wrangler secret put API_KEY
Endpoint: http://127.0.0.1:8787/mcp
3. Cloudflare Worker (Deploy)
- Create KV namespace:
bun x wrangler kv:namespace create TOKENS
-
Update
wrangler.tomlwith the KV namespace ID -
Set secrets:
bun x wrangler secret put API_KEY
- Deploy:
bun x wrangler deploy
Endpoint: https://<worker-name>.<account>.workers.dev/mcp
API Key Resolution
Each tool resolves the YouTube API key in this order:
- Client header
X-YouTube-Api-Key— forwarded from the MCP client request - Server config
providerToken— falls back toAPI_KEYorBEARER_TOKENfrom env
This lets you run a single server instance for multiple users (each sends their own key) or set a shared key server-side.
Tools
find_channel
Search for YouTube channels by name. Returns channel IDs that can be used with scan_channel.
// Input
{
query: string; // Channel name or search query
maxResults?: number; // 1–10, default 5
}
// Output (structuredContent)
{
query: string;
count: number;
channels: Array<{
channelId: string;
title: string;
description: string;
thumbnailUrl: string;
customUrl?: string;
}>;
}
scan_channel
Get the latest videos from a YouTube channel.
// Input
{
channelId: string; // YouTube channel ID (e.g., UC...)
maxResults?: number; // 1–50, default 10
}
// Output (structuredContent)
{
channelId: string;
videoCount: number;
videos: Array<{
videoId: string;
title: string;
description: string;
publishedAt: string;
thumbnailUrl: string;
}>;
}
search_videos
Search for videos across all of YouTube.
// Input
{
query: string; // Search query
maxResults?: number; // 1–50, default 10
order?: string; // "relevance" | "date" | "viewCount" | "rating" (default: "relevance")
publishedAfter?: string; // ISO 8601 date filter (e.g., "2024-01-01T00:00:00Z")
}
// Output (structuredContent)
{
query: string;
count: number;
videos: Array<{
videoId: string;
title: string;
description: string;
channelId: string;
channelTitle: string;
publishedAt: string;
thumbnailUrl: string;
}>;
}
get_playlist
Dual-mode tool: list playlists from a channel or list videos in a playlist.
// Input (provide one of channelId or playlistId)
{
channelId?: string; // List playlists from this channel
playlistId?: string; // List videos in this playlist
maxResults?: number; // 1–50, default 20
}
// Output when channelId is provided (structuredContent)
{
type: "playlists";
channelId: string;
count: number;
playlists: Array<{
playlistId: string;
title: string;
description: string;
itemCount: number;
thumbnailUrl: string;
}>;
}
// Output when playlistId is provided (structuredContent)
{
type: "videos";
playlistId: string;
count: number;
videos: Array<{
videoId: string;
title: string;
description: string;
channelTitle: string;
position: number;
thumbnailUrl: string;
}>;
}
video_details
Get detailed information about a single video including statistics, duration, and metadata.
// Input
{
videoId: string; // YouTube video ID
}
// Output (structuredContent)
{
videoId: string;
title: string;
description: string;
channelId: string;
channelTitle: string;
publishedAt: string;
duration: string; // ISO 8601 duration (e.g., "PT12M34S")
viewCount: number;
likeCount: number;
commentCount: number;
tags: string[];
thumbnailUrl: string;
}
Examples
1. Discover a channel and list its latest videos
{ "name": "find_channel", "arguments": { "query": "Fireship" } }
Response:
Found 5 channels for "Fireship":
1. Fireship (@Fireship)
ID: UCsBjURrPoezykLs9EqgamOA
...
Then use the channel ID:
{ "name": "scan_channel", "arguments": { "channelId": "UCsBjURrPoezykLs9EqgamOA", "maxResults": 5 } }
2. Search for recent videos on a topic
{
"name": "search_videos",
"arguments": {
"query": "rust programming",
"order": "date",
"maxResults": 10,
"publishedAfter": "2025-01-01T00:00:00Z"
}
}
3. Browse a channel's playlists, then list videos
{ "name": "get_playlist", "arguments": { "channelId": "UCsBjURrPoezykLs9EqgamOA" } }
Then drill into a specific playlist:
{ "name": "get_playlist", "arguments": { "playlistId": "PL0vfts4VzfNjnBhBlI4W3on..." } }
4. Get full details for a video
{ "name": "video_details", "arguments": { "videoId": "dQw4w9WgXcQ" } }
Response:
Title: Rick Astley - Never Gonna Give You Up
Channel: Rick Astley
Published: 2009-10-25T06:57:33Z
Duration: PT3M33S
Views: 1,600,000,000
Likes: 16,000,000
Comments: 2,800,000
Tags: rick astley, never gonna give you up, ...
HTTP Endpoints
| Endpoint | Method | Purpose |
|---|---|---|
/mcp |
POST | MCP JSON-RPC 2.0 |
/mcp |
GET | SSE stream (Node.js only) |
/health |
GET | Health check |
Development
bun dev # Start with hot reload
bun run typecheck # TypeScript check
bun run lint # Lint code (Biome)
bun run build # Production build
bun start # Run production
Architecture
src/
├── index.ts # Node.js/Bun entry (Hono server)
├── worker.ts # Cloudflare Workers entry
├── config/
│ ├── env.ts # Re-exports shared config
│ └── metadata.ts # Server & tool descriptions
├── core/
│ ├── capabilities.ts # MCP capabilities (logging, tools)
│ ├── context.ts # Request context registry
│ └── mcp.ts # McpServer builder + tool registration
├── http/
│ ├── app.ts # Hono app (CORS, auth, routes)
│ ├── auth-app.ts # OAuth Authorization Server (PORT+1)
│ ├── middlewares/ # Auth header forwarding (incl. X-YouTube-Api-Key), CORS
│ └── routes/ # /health, /mcp (Streamable HTTP)
├── shared/
│ ├── tools/
│ │ ├── find-channel.ts # find_channel tool
│ │ ├── scan-channel.ts # scan_channel tool
│ │ ├── search-videos.ts # search_videos tool
│ │ ├── get-playlist.ts # get_playlist tool
│ │ ├── video-details.ts # video_details tool
│ │ ├── registry.ts # Tool registry (single source of truth)
│ │ └── types.ts # ToolContext, defineTool, ToolResult
│ ├── services/
│ │ └── http-client.ts # Rate-limited fetch wrapper
│ ├── config/
│ │ └── env.ts # Unified env parsing (both runtimes)
│ ├── storage/ # Token/session stores (file, KV, memory, SQLite)
│ ├── oauth/ # OAuth 2.1 PKCE flow + discovery
│ ├── mcp/ # JSON-RPC dispatcher (Workers)
│ ├── auth/ # Auth strategy types
│ ├── crypto/ # AES-GCM encryption for token storage
│ └── http/ # CORS + JSON response helpers
├── adapters/
│ ├── http-hono/ # Hono security middleware, OAuth/discovery routes
│ └── http-workers/ # Workers router, env shim, KV init
└── utils/ # Logger, cancellation, pagination, etc.
Troubleshooting
| Issue | Solution |
|---|---|
| "YouTube API key required" | Pass the key via X-YouTube-Api-Key header or set API_KEY in .env / wrangler secret put API_KEY |
| "YouTube API error: 403" | The API key may be invalid, or the YouTube Data API v3 isn't enabled in your GCP project |
| "YouTube API error: 429" | Quota exceeded. YouTube allows 10,000 units/day by default. Wait or request a quota increase. |
| "Video not found" | The video ID is wrong, or the video is private/deleted |
| "Either channelId or playlistId must be provided" | get_playlist requires one of the two — pass at least one |
| Workers deploy fails | Ensure KV namespace ID is set in wrangler.toml |
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。