Skip to main content
Glama
ytmusic-mcp

ytmusic-mcp

by umsachde

ytmusic-mcp

MCP サーバーであり、ytmusicapi をラップして、Claude(または任意の MCP クライアント)が YouTube Music の検索、プレイリストの管理、リスニング履歴の読み取りを行えるようにします。

ツール

ツール

説明

search_music(query, filter=None, limit=20)

YouTube Music を検索します。filter は songs、videos、albums、artists、playlists、community_playlists、featured_playlists、profiles、podcasts、episodes のいずれかです。

get_playlists()

ライブラリのプレイリストを一覧表示します。

get_playlist_tracks(playlist_id)

プレイリスト内のトラックを取得します。

create_playlist(name, description="")

新しいプライベートプレイリストを作成し、その ID を返します。

add_to_playlist(playlist_id, video_id)

トラックをプレイリストに追加します。

get_history()

最近の再生履歴を取得します。

含まれていません(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 はログイン済みのブラウザセッションのヘッダーを再利用して認証を行います。

  1. ログインした状態で Firefox(推奨 – 生ヘッダーのコピーが Chrome よりも信頼性が高い)で music.youtube.com を開きます。

  2. DevTools(Cmd+Option+I / F12)→ Network タブ → browse でフィルタリングします。

  3. プレイリストをクリックするか、ページをリロードして、browse POST リクエストをトリガーします。

  4. そのリクエストをクリック → Headers タブ → Raw headers に切り替え → ブロック全体を選択してコピーします。

  5. それをプロジェクトルートに raw_headers.txt という名前の新しいファイルに貼り付けて保存します。

  6. 以下を実行します:

    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 tools
add_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

    B3.2/5.0

    Scored across 6 tools

    Disambiguation5/5

    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.

    Naming Consistency4/5

    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.

    Tool Count5/5

    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.

    Completeness3/5

    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

    Related MCP Servers

    • F
      license
      Not graded
      quality
      D
      maintenance
      Enables 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.
      -
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables 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.
      2
      GPL 3.0