youtube-mcp

youtube-mcp

Local YouTube MCP server for turning public video, channel, and playlist URLs into structured context, with bounded comment retrieval, timestamped captions, and owned-playlist management using your own Google Cloud credentials.

Category
访问服务器

README

youtube-mcp

Local YouTube MCP server for Codex. It turns public video, channel, and playlist URLs into structured context, bounded public-comment retrieval, timestamped caption research, and owned-playlist management.

The repository is public, but the server is intentionally local and single-user: bring your own Google Cloud credentials, authenticate your own YouTube channel, and keep credentials and tokens on your machine. It is not a hosted service or a multi-user connector.

Tools

  • youtube_get_video
  • youtube_get_comments
  • youtube_find_comments
  • youtube_get_channel
  • youtube_get_channel_videos
  • youtube_search_videos
  • youtube_get_playlist_items
  • youtube_list_transcript_languages
  • youtube_get_transcript
  • youtube_get_authenticated_channel
  • youtube_list_owned_playlists
  • youtube_get_owned_playlist_items
  • youtube_create_playlist
  • youtube_update_playlist
  • youtube_add_playlist_video
  • youtube_remove_playlist_item
  • youtube_reorder_playlist_item

Public research tools remain read-only. Authenticated V2 tools manage only playlists owned by the locally authenticated channel; the server does not expose account-library reads, media downloads, ASR generation, or background processing.

Requirements

  • Node.js 22+
  • pnpm
  • A Google Cloud project with YouTube Data API v3 enabled
  • A restricted YouTube Data API key for public read tools
  • yt-dlp on PATH for transcript tools (or YT_DLP_PATH)

Authenticated playlist tools additionally require a Google OAuth desktop client. ChatGPT access through an OpenAI Secure MCP Tunnel is optional; it is not needed for local Codex use.

Authenticated playlist setup

In Google Cloud, enable YouTube Data API v3, create an OAuth Desktop app client, and configure the loopback redirect URI from YOUTUBE_REDIRECT_URI (by default http://127.0.0.1:8787/callback) as required by that client configuration. Configure its client ID and optional client secret in .env, then run the local PKCE flow once:

pnpm auth:login
pnpm auth:status

Tokens are saved outside the repository at ~/.config/youtube-mcp/tokens.json with private filesystem permissions. pnpm auth:logout revokes the local session when possible and removes that file.

youtube_list_owned_playlists and youtube_get_owned_playlist_items use explicit pagination. youtube_create_playlist defaults to private. Update and add operations apply directly; removal and reorder require confirm: true. Only playlists owned by the authenticated channel can be read through the owned workflow or changed.

Set YOUTUBE_SMOKE_OWNED_PLAYLIST_URL only for a private test playlist you own to add an authenticated, read-only ownership smoke check. It does not create, update, add, remove, or reorder items.

Setup

  1. Copy .env.example to .env.
  2. Set YOUTUBE_API_KEY to a restricted YouTube Data API key.
  3. Install and build:
pnpm install
pnpm build
  1. Run the stable local stdio server:
pnpm start

For contributor development only, run pnpm dev.

Codex setup

Build the server, then add a local MCP entry to your Codex configuration:

[mcp_servers.youtube]
command = "node"
args = ["--env-file=/absolute/path/to/youtube-mcp/.env", "/absolute/path/to/youtube-mcp/dist/server.js"]

Replace /absolute/path/to/youtube-mcp with your clone path. Rebuild after source changes before using the stable server.

Tool behavior

youtube_get_video accepts normal watch, Shorts, live, embed, and youtu.be URLs. It returns public metadata only.

youtube_get_comments accepts limit (default 50, maximum 100), order (relevance or time), an explicit pageToken, includeReplies, and optional matchTerms.

  • A call fetches one page only and returns next_page_token when YouTube supplies one.
  • includeReplies returns only the inline reply subset provided by YouTube. replies_truncated is true when more replies exist.
  • matchTerms applies a case-insensitive literal OR filter after retrieving the page. When it is used, search_scope is always retrieved_page_only; it does not search every comment on the video.

youtube_find_comments searches a caller-specified maxPages (1–5) of comment threads for matchTerms. It returns searched_pages, complete, and next_page_token; its search_scope is always retrieved_pages_only.

youtube_get_channel accepts public /channel/CHANNEL_ID and /@handle URLs. youtube_get_channel_videos returns one explicit page of the channel's public uploads playlist.

youtube_search_videos returns one explicit page of public video search results, enriched with normalized video metadata. Search is quota-expensive, so requests are limited to 25 results.

youtube_get_playlist_items accepts public /playlist?list=... and /watch?...&list=... URLs and returns one explicit item page. Items retain their playlist item IDs and positions for safe future authenticated workflows.

youtube_list_transcript_languages lists caption tracks exposed for a video. youtube_get_transcript returns one explicit page of timestamped creator or automatic caption segments. It prefers English when no language is requested, then falls back to the video language. Transcript retrieval uses local yt-dlp metadata and YouTube-exposed caption URLs; it never downloads media, writes a cache, or generates ASR text. Availability can change and is not guaranteed for every public video.

Optional ChatGPT connection

Keep this server and .env on the Mac. Create an OpenAI Secure MCP Tunnel, run tunnel-client where it can reach the built stdio server, and register the tunnel endpoint in ChatGPT Developer Mode. The tunnel lets ChatGPT reach a private MCP server without a public listener. Follow the current Secure MCP Tunnel documentation for tunnel creation and tunnel-client configuration.

Do not commit the Google API key, OAuth client credentials, OpenAI runtime key, generated tunnel configuration, or local token file.

Privacy and API terms

This server runs locally. It does not include telemetry, a hosted backend, or a shared credential service. OAuth tokens are stored only in the local token file described above, and YouTube API requests use the credentials configured by the local user.

Users are responsible for their own Google Cloud projects and compliance with the YouTube API Services Terms of Service and YouTube Developer Policies. Caption tools use yt-dlp only to retrieve YouTube-exposed caption tracks; caption availability and extraction behavior can change without notice.

Verification

pnpm format:check
pnpm lint
pnpm typecheck
pnpm test
pnpm build
pnpm transcript:doctor
pnpm auth:status
pnpm smoke

pnpm smoke makes live read-only requests. It uses YOUTUBE_SMOKE_URL when set; otherwise it uses a default public video. Set YOUTUBE_SMOKE_COMMENTS_URL when you need to require a comments-enabled smoke target, and YOUTUBE_SMOKE_TRANSCRIPT_URL to verify a caption-enabled transcript target.

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选