Xiaozhi YouTube MCP

Xiaozhi YouTube MCP

Enables searching and playing songs via YouTube Data API v3, returning YouTube playback URLs.

Category
访问服务器

README

Xiaozhi YouTube MCP

A complete Model Context Protocol server that lets Xiaozhi or another MCP client search songs through the official YouTube Data API v3 and receive a YouTube playback URL.

What it provides

  • youtube_search_song: returns up to 10 Music-category results.
  • youtube_play_song: returns the best result for direct voice commands.
  • youtube_get_video: resolves an 11-character video ID to metadata and playback links.
  • YouTube title, channel, description, thumbnail, ISO-8601 duration, duration in seconds, view count, and embeddability.
  • stdio transport for desktop/local MCP clients.
  • Streamable HTTP transport for a hosted Xiaozhi backend.
  • Docker, Docker Compose, validation, error handling, cache, and tests.

Playback limitation

The official YouTube Data API returns video metadata and YouTube URLs; it does not return direct MP3/AAC media streams. This MCP therefore returns:

  • youtubeUrl: https://www.youtube.com/watch?v=...
  • embedUrl: https://www.youtube.com/embed/...

Playback requires a YouTube-capable client or an approved handoff to a YouTube player. This project intentionally does not extract or proxy YouTube media streams.

1. Create an API key

  1. Create or select a Google Cloud project.
  2. Enable YouTube Data API v3.
  3. Create an API key.
  4. Restrict the key to YouTube Data API v3 and, where practical, to your server IP.

2. Run locally

cp .env.example .env
# Edit .env and set YOUTUBE_API_KEY
npm install
npm run build
npm start

The default transport is stdio. Never write normal logs to stdout in stdio mode; this server logs startup messages to stderr.

Example MCP client configuration:

{
  "mcpServers": {
    "youtube": {
      "command": "node",
      "args": ["/absolute/path/xiaozhi-youtube-mcp/dist/src/index.js"],
      "env": {
        "YOUTUBE_API_KEY": "YOUR_KEY",
        "YOUTUBE_REGION_CODE": "VN",
        "YOUTUBE_RELEVANCE_LANGUAGE": "vi"
      }
    }
  }
}

Run directly with npx

After the package is published to npm:

YOUTUBE_API_KEY=YOUR_KEY npx --yes xiaozhi-youtube-mcp

For Streamable HTTP mode:

YOUTUBE_API_KEY=YOUR_KEY MCP_TRANSPORT=http PORT=3000 \
  npx --yes xiaozhi-youtube-mcp

MCP client configuration using npx:

{
  "mcpServers": {
    "youtube": {
      "command": "npx",
      "args": ["--yes", "xiaozhi-youtube-mcp"],
      "env": {
        "YOUTUBE_API_KEY": "YOUR_KEY",
        "YOUTUBE_REGION_CODE": "VN",
        "YOUTUBE_RELEVANCE_LANGUAGE": "vi"
      }
    }
  }
}

You can also run a GitHub repository before publishing to npm:

YOUTUBE_API_KEY=YOUR_KEY npx --yes github:YOUR_GITHUB_USER/xiaozhi-youtube-mcp

For repeatable production deployments, pin a package version rather than always using the latest version:

npx --yes xiaozhi-youtube-mcp@1.0.0

3. Host for Xiaozhi

cp .env.example .env
# Set YOUTUBE_API_KEY and MCP_TRANSPORT=http
npm install
npm run build
npm run start:http

Endpoints:

  • MCP: http://YOUR_SERVER:3000/mcp
  • Health: http://YOUR_SERVER:3000/health

For public use, put the service behind HTTPS using Nginx, Caddy, Cloudflare Tunnel, or another trusted reverse proxy. Configure the resulting HTTPS MCP URL in the server-side MCP section of your Xiaozhi backend/control panel. The exact UI varies by the Xiaozhi server distribution.

Docker

cp .env.example .env
# Edit .env

docker compose up -d --build
curl http://localhost:3000/health

Voice behavior

A user says:

Play Numb by Linkin Park

The model should call:

{
  "name": "youtube_play_song",
  "arguments": {
    "query": "Numb Linkin Park",
    "officialOnly": true
  }
}

The structured response contains a playback.url. A Xiaozhi integration that can open YouTube should hand that URL to its player. Otherwise, the assistant can read out or display the selected title and URL.

Configuration

Variable Default Description
YOUTUBE_API_KEY required Google API key
MCP_TRANSPORT stdio stdio or http
HOST 0.0.0.0 HTTP bind host
PORT 3000 HTTP port
MCP_PATH /mcp MCP HTTP route
YOUTUBE_REGION_CODE VN ISO two-letter region
YOUTUBE_RELEVANCE_LANGUAGE vi Search relevance language
YOUTUBE_SAFE_SEARCH moderate none, moderate, or strict
YOUTUBE_DEFAULT_MAX_RESULTS 5 Default result count, maximum 10
YOUTUBE_CACHE_TTL_SECONDS 300 In-memory API response cache

Verify

npm run check

Security and production notes

  • Keep the API key server-side and out of source control.
  • Apply API restrictions and quota alerts in Google Cloud.
  • Use HTTPS and network access controls for HTTP deployment.
  • Add reverse-proxy authentication if the endpoint is publicly reachable.
  • Cache searches to reduce API usage.
  • The server filters searches to YouTube video category 10 (Music), requests embeddable videos, and enables configurable SafeSearch.

Publish to GitHub and npm

git init
git add .
git commit -m "Initial Xiaozhi YouTube MCP"
git branch -M main
git remote add origin git@github.com:YOUR_GITHUB_USER/xiaozhi-youtube-mcp.git
git push -u origin main

npm login
npm publish

The npm package name must be available. If xiaozhi-youtube-mcp is already owned by someone else, use a scoped name such as @YOUR_GITHUB_USER/xiaozhi-youtube-mcp, update package.json, and run it with:

npx --yes @YOUR_GITHUB_USER/xiaozhi-youtube-mcp

Automated npm publishing

The included GitHub Actions workflow publishes when you create a GitHub Release. Add an npm automation token as the repository secret NPM_TOKEN, then create a release whose tag matches the version, for example v1.0.0.

推荐服务器

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

官方
精选