Xiaozhi YouTube MCP
Provides tools for searching songs via YouTube Data API v3 and returning playback URLs. Supports searching for up to 10 music-category results, playing the best match for voice commands, and retrieving video metadata including title, channel, duration, view count, and embed links.
Click on "Deploy 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., "@Xiaozhi YouTube MCP play Numb by Linkin Park"
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.
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.
Related MCP server: youtube-mcp
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
Create or select a Google Cloud project.
Enable YouTube Data API v3.
Create an API key.
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 startThe 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-mcpFor Streamable HTTP mode:
YOUTUBE_API_KEY=YOUR_KEY MCP_TRANSPORT=http PORT=3000 \
npx --yes xiaozhi-youtube-mcpMCP 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-mcpFor repeatable production deployments, pin a package version rather than always using the latest version:
npx --yes xiaozhi-youtube-mcp@1.0.03. Host for Xiaozhi
cp .env.example .env
# Set YOUTUBE_API_KEY and MCP_TRANSPORT=http
npm install
npm run build
npm run start:httpEndpoints:
MCP:
http://YOUR_SERVER:3000/mcpHealth:
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/healthVoice 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 |
| required | Google API key |
|
|
|
|
| HTTP bind host |
|
| HTTP port |
|
| MCP HTTP route |
|
| ISO two-letter region |
|
| Search relevance language |
|
|
|
|
| Default result count, maximum 10 |
|
| In-memory API response cache |
Verify
npm run checkSecurity 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 publishThe 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-mcpAutomated 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.
Available Tools
3 toolsyoutube_get_videoGet YouTube video detailsB
Get title, channel, duration, views, thumbnail, and playback URL for a YouTube video ID.
Inputs: videoId (required).
youtube_play_songFind and play a YouTube songB
Find the best matching song and return one playback-ready YouTube URL. Prefer this for direct voice commands such as 'play...'
Inputs: query (required), regionCode, officialOnly, relevanceLanguage.
youtube_search_songSearch YouTube songsA
Search YouTube Music-category videos and return playable YouTube URLs. Use this when the user asks to find or play a song.
Inputs: query (required), order, maxResults, regionCode, +3 more.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 3 tools
Tools are distinct: search returns multiple URLs, play returns one best match, get provides metadata. However, search and play both handle song queries, causing slight overlap, but descriptions clarify their usage.
All tools follow a consistent 'youtube_verb_noun' pattern (search_song, play_song, get_video), using underscores and clear action-object format.
Three tools is appropriate for a focused YouTube music MCP server, covering search, playback, and metadata without unnecessary bloat.
Covers core music workflows: searching songs, playing, and getting video details. Minor gaps like playlist or recommendation support exist but are outside stated scope.
Related MCP Connectors
YouTube MCP — wraps the YouTube Data API v3 (BYO API key)
YouTube discovery, transcripts, library search, and monitors with API keys or OAuth.
Search videos; read channels, playlists, comments and popular videos in YouTube.
YouTube search: find videos, fetch details and comments, pull full transcripts.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables searching for songs on YouTube and automatically playing them in a web browser using the official YouTube Data API v3. It supports cross-platform execution on Windows, macOS, and Linux with built-in input validation.MIT
- AlicenseAqualityDmaintenanceEnables YouTube search, video details, channels, playlists, and comments scraping via MCP, no API key required.1034 npm1MIT
- AlicenseAqualityDmaintenanceEnables YouTube video search and audio download via web scraping, requiring no API key.1MIT
- FlicenseNot gradedqualityDmaintenanceEnables searching and playing music from YouTube, returning top results or playable URLs, designed for XiaoZhi ESP32 robot.-