youtubemusic-mcp

codeRisshi25/youtubemusic-mcp

3.2

If you are the rightful owner of youtubemusic-mcp and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.

The YouTube Music MCP Server connects YouTube Music to AI assistants like Claude, enabling music library access and management through natural language conversations.

Tools
7
Resources
0
Prompts
0

YouTube Music MCP Server

A production-grade Model Context Protocol (MCP) server that connects YouTube Music to AI assistants like Claude.
Implements the full MCP primitive set — Tools, Resources, and Prompts — for genuine agentic music experiences.

Python License MCP Tests CI

ArchitectureFeaturesInstallationAuthenticationUsageToolsResourcesPrompts


Architecture

┌────────────────────────────────────────────────────────────┐
│                    Claude / AI Assistant                   │
└──────────────────────┬─────────────────────────────────────┘
                       │  Model Context Protocol (stdio)
┌──────────────────────▼─────────────────────────────────────┐
│                 YouTube Music MCP Server v2                │
│                                                            │
│  ┌─────────────┐  ┌───────────────┐  ┌──────────────────┐  │
│  │  15 Tools   │  │  3 Resources  │  │    3 Prompts     │  │
│  │             │  │               │  │                  │  │
│  │ search      │  │library://     │  │weekly-discovery  │  │
│  │ stats       │  │  songs        │  │mood-based-       │  │
│  │ similar ★   │  │  artists      │  │  playlist        │  │
│  │ recommend ★ │  │  playlists    │  │artist-deep-dive  │  │
│  │ smart pl ★  │  └───────────────┘  └──────────────────┘  │
│  │ charts      │                                           │
│  │ insights    │  ┌───────────────────────────────────┐    │
│  │ moods       │  │  TTL Cache (5 min)  •  Async ★    │    │
│  │ ...         │  │  Custom Exceptions  •  Logging    │    │
│  └─────────────┘  └───────────────────────────────────┘    │
└──────────────────────┬─────────────────────────────────────┘
                       │  ytmusicapi
┌──────────────────────▼─────────────────────────────────────┐
│                   YouTube Music API                        │
└────────────────────────────────────────────────────────────┘
★ = Agentic / async feature

Features

15 Tools · 3 Resources · 3 Prompts — full MCP primitive coverage:

🛠️ Tools

ToolDescription
get_liked_songs_countTotal song count (bypasses YT display limit)
get_library_statsSongs, artists, playlists + detailed breakdown
search_musicSearch with type filter (songs/albums/artists/playlists/videos)
get_top_artistsRanked artists with visual progress bars
find_similar_songsReal YTMusic radio engine — not a fake artist search
get_recommendationsAsync-parallel fetch across top 5 artists
create_playlist_from_songsCreate & populate playlist from search queries
list_playlistsAll your playlists with IDs and song counts
get_playlist_songsBrowse songs in any playlist
add_songs_to_playlistAdd songs to existing playlist
build_smart_playlistAgentic 6-step pipeline: mood→category→tracks→filter→save
explore_moodsDiscover all YTMusic Moods & Genres categories
get_chartsGlobal or country-specific trending charts
get_listening_insightsHistory analysis: patterns, diversity score, insights
get_server_infoAuth method, cache state, version, capabilities

📦 Resources (passively readable by Claude)

Resource URIDescription
library://songsFull library as structured JSON
library://artistsArtist rankings with percentages
library://playlistsAll playlists as structured JSON

💬 Prompts (guided conversation starters)

PromptDescription
weekly-discovery-mixGuided weekly music discovery workflow
mood-based-playlistCollaborative mood → playlist session
artist-deep-diveFull artist exploration + listening plan

Installation

Prerequisites

  • Python 3.10 or higher
  • A YouTube Music account
  • Browser developer tools access (for authentication)

Setup

  1. Clone the repository
git clone https://github.com/codeRisshi25/youtubemusic-mcp.git
cd youtubemusic-mcp
  1. Create virtual environment
python3 -m venv venv
source venv/bin/activate  # Linux/macOS
# OR
venv\Scripts\activate     # Windows
  1. Install dependencies
pip install -e .

Authentication

Choose one authentication method:

Option A: Cookie File (Simplest — recommended)

  1. Visit music.youtube.com and log in
  2. Open Developer Tools (F12)
  3. Go to Network tab and refresh the page
  4. Click any request → Headers → copy the full cookie: value
  5. Paste it into a file named cookie.txt in the project directory
  6. Done! The server auto-generates browser.json on first startup
# Optional: validate cookies before starting the server
python update_auth.py

Note: Cookies typically last 6–24 months. When they expire, just paste fresh cookies into cookie.txt and restart.

Option B: OAuth (Long-term)

See for complete OAuth setup instructions.


Usage

Test with MCP Inspector

npx @modelcontextprotocol/inspector venv/bin/python server.py

Opens web interface at http://localhost:6274 to test all 15 tools, 3 resources, and 3 prompts.

Claude Desktop Integration

  1. Config file location:

    • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
    • Windows: %APPDATA%\Claude\claude_desktop_config.json
    • Linux: ~/.config/Claude/claude_desktop_config.json
  2. Add configuration:

{
  "mcpServers": {
    "youtube-music": {
      "command": "/path/to/venv/bin/python",
      "args": ["/path/to/server.py"]
    }
  }
}
  1. Restart Claude Desktop

See for detailed instructions.


Available Tools

See the Features section above for a full table of all 15 tools.

Agentic Highlights

build_smart_playlist — the centrepiece agentic tool. Runs a 6-step pipeline inside a single tool call:

Step 1: Fetch all Moods & Genres from YouTube Music
Step 2: Match your mood keyword to a real category
Step 3: Pull mood playlist pool from that category
Step 4: Sample tracks across multiple playlists
Step 5: Apply energy-level filter (high/medium/low)
Step 6: Optionally create & save to YouTube Music

find_similar_songs — uses get_watch_playlist(radio=True), the actual YTMusic similarity engine, not a fake artist search.

get_recommendations — fetches from 5 artists using asyncio.gather() for true parallel execution.


Running Tests

pip install -e ".[dev]"
pytest tests/ -v

51 tests covering auth, caching, all tools, resources, prompts, and routing — no network required (fully mocked).


Troubleshooting

Authentication Errors

If you get authentication errors after ~6 months:

  1. Your cookies have likely expired
  2. Follow the simple update process in
  3. You'll just need to paste fresh cookies from your browser

Server Not Detected in Claude

  • Use absolute paths in claude_desktop_config.json
  • Restart Claude Desktop after config changes
  • Check logs in Claude → Help → View Logs

Import Errors

  • Ensure virtual environment is activated
  • Run pip install -e . in the project directory

Server Crashes on Startup

  • Verify browser.json or oauth.json exists
  • Check file permissions
  • See for detailed troubleshooting

Contributing

See for contribution guidelines.


License

MIT License - see

Copyright (c) 2025 Risshi Raj Sen


Links


Built with ytmusicapiMCP

⭐ Star if useful!