ytmusic-mcp
ytmusic-mcp
MCP サーバーであり、ytmusicapi をラップして、Claude(または任意の MCP クライアント)が YouTube Music の検索、プレイリストの管理、リスニング履歴の読み取りを行えるようにします。
ツール
ツール | 説明 |
| YouTube Music を検索します。 |
| ライブラリのプレイリストを一覧表示します。 |
| プレイリスト内のトラックを取得します。 |
| 新しいプライベートプレイリストを作成し、その ID を返します。 |
| トラックをプレイリストに追加します。 |
| 最近の再生履歴を取得します。 |
含まれていません(v1): BPM ベースのレコメンデーション。YouTube Music はテンポデータを公開していないため、これには別のデータソース(例:オーディオ分析 API)が必要になります。これは将来のバージョンでのストレッチゴールであり、今回のビルドには含まれていません。
Related MCP server: mcp-server-youtube
セットアップ
1. 依存関係のインストール
python3 -m venv .venv
source .venv/bin/activate
pip install -e .2. 認証
公式の YouTube Music API は存在しないため、ytmusicapi はログイン済みのブラウザセッションのヘッダーを再利用して認証を行います。
ログインした状態で Firefox(推奨 – 生ヘッダーのコピーが Chrome よりも信頼性が高い)で music.youtube.com を開きます。
DevTools(
Cmd+Option+I/F12)→ Network タブ →browseでフィルタリングします。プレイリストをクリックするか、ページをリロードして、
browsePOST リクエストをトリガーします。そのリクエストをクリック → Headers タブ → Raw headers に切り替え → ブロック全体を選択してコピーします。
それをプロジェクトルートに
raw_headers.txtという名前の新しいファイルに貼り付けて保存します。以下を実行します:
python scripts/setup_auth_from_file.pyこれにより、
headers_auth.jsonが書き込まれ、raw_headers.txtが削除されます。
または、python scripts/setup_auth.py は、ファイルの代わりにインタラクティブなターミナルプロンプトを介して同じことを行います(直接貼り付けたい場合に便利です)。
headers_auth.json はログイン済みセッションと同等です – これをコミットしたり共有したりしないでください。 すでに gitignore されています。
先に進む前に認証が機能することを確認してください:
python scripts/test_search.pyこれらのヘッダーは定期的に期限切れ/ローテーションします。認証エラーでツールが失敗し始めた場合は、この手順をやり直してください。
3. Claude Code に追加
claude mcp add ytmusic -s user \
-e YTMUSIC_AUTH_PATH="$(pwd)/headers_auth.json" \
-- "$(pwd)/.venv/bin/python" "$(pwd)/server.py"-s user を指定すると、このディレクトリだけでなく、任意の Claude Code セッションで使用できるようになります。サーバーは任意の作業ディレクトリから起動できるため、python インタプリタ、server.py、YTMUSIC_AUTH_PATH には絶対パスを使用してください。
他の MCP クライアント(Claude Desktop など)の場合は、それぞれの設定形式を使用して、同じコマンドと環境変数を指定します。
エラーハンドリング
ツールコールは、一般的な障害モードを生のトレースバックではなく、明確なメッセージに変換します:
認証情報の欠落/期限切れ/不正 →
scripts/setup_auth_from_file.pyを再実行するように指示します。レート制限(HTTP 429) → 待ってから再試行するように指示します。
ゲート/制限付きコンテンツ → クラッシュする代わりに利用不可として報告します。
ネットワークエラー → 直接報告します。
ライセンス
MIT – LICENSE を参照してください。
Available Tools
6 toolsadd_to_playlistC
Add a track to a playlist by video ID.
Inputs: video_id (required), playlist_id (required). Returns: result
create_playlistC
Create a new private playlist and return its playlist ID.
Inputs: name (required), description. Returns: result
get_historyB
Get recent play history.
Inputs: no named parameters. Returns: result
get_playlistsA
List your YouTube Music library playlists.
Inputs: no named parameters. Returns: result
get_playlist_tracksC
Get the tracks in a playlist.
Inputs: playlist_id (required). Returns: result
search_musicB
Search YouTube Music.
filter: one of songs, videos, albums, artists, playlists, community_playlists, featured_playlists, profiles, podcasts, episodes. Omit for a mixed search. Returns an empty list if there are no matches.
Inputs: query (required), limit, filter. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 6 tools
Each tool targets a distinct action or resource: search, library playlists, playlist tracks, playlist creation, playlist modification, and history. No two tools have overlapping purposes, making selection unambiguous.
Tool names follow a consistent verb_noun pattern (search_music, get_playlists, get_playlist_tracks, create_playlist, add_to_playlist, get_history). The only minor deviation is 'add_to_playlist' instead of 'add_track_to_playlist', but the pattern is still clear.
With 6 tools, the number is well-scoped for a YouTube Music server that focuses on search, playlist management, and history. Each tool earns its place without being overwhelming or too sparse.
The set covers search, playlist CRUD (create, read tracks, add to), and history, but lacks tools for removing tracks from playlists, updating playlist metadata, or managing likes/ratings. This leaves some common music management workflows incomplete.
Related MCP Connectors
Search YouTube videos, read transcripts and get public video information in your AI assistant.
YouTube transcripts, search, channel/playlist listings and upload tracking for AI agents.
Fetch YouTube transcripts, monitor channels and track keyword matches from your AI assistant.
YouTube transcripts, search, and channel and playlist listings for any AI app. Hosted.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceEnables users to search the YouTube Music catalog and manage playlists using natural language. It provides tools for searching songs, albums, and artists, as well as performing playlist operations like creating, adding, and deleting tracks.-
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to search videos, read channels, browse playlists, fetch comments, and get transcripts from YouTube using the YouTube Data API v3 and InnerTube API for captions.2GPL 3.0
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to search videos, channels, and playlists, retrieve video metadata, transcripts, and comments via the YouTube Data API v3.33 PyPI68MIT
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to search YouTube Music, manage playlists, and create smart recommendations using natural language.15MIT