Skip to main content
Glama
umsachde

ytmusic-mcp

by umsachde

ytmusic-mcp

M8ven Score

An MCP server that wraps ytmusicapi so Claude (or any MCP client) can search YouTube Music, manage your playlists, and read your listening history.

Tools

Tool

Description

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

Search YouTube Music. filter is one of songs, videos, albums, artists, playlists, community_playlists, featured_playlists, profiles, podcasts, episodes.

get_playlists(limit=None)

List your library playlists. Omit limit to fetch all of them.

get_playlist_tracks(playlist_id, limit=None)

Get the tracks in a playlist. Omit limit to fetch the entire playlist.

create_playlist(name, description="")

Create a new private playlist, returns its ID.

add_to_playlist(playlist_id, video_id)

Add a track to a playlist.

remove_from_playlist(playlist_id, video_id)

Remove every occurrence of a track from a playlist by video ID.

remove_playlist(playlist_id)

Permanently delete a playlist you own. Refuses to touch the auto playlists LM and SE.

get_history()

Get your recent play history.

get_watch_playlist(video_id, limit=25, radio=True)

Get the radio/autoplay queue for a song — one of two independent similarity signals.

get_song_related(browse_id)

Get "related content" sections for a song (the browse_id comes from get_watch_playlist's related field) — the other independent similarity signal.

get_lyrics(browse_id)

Get a song's lyrics (the browse_id comes from get_watch_playlist's lyrics field). Feeds re-com's lyric-based mood labelling.

get_artist(browse_id)

Get an artist's page: top songs, albums, related artists.

logout()

Delete the local auth file, revoking this server's stored YouTube Music authorization.

Other Claude Code projects on this machine (e.g. re-com) call these tools by spawning this server over MCP rather than talking to ytmusicapi/YouTube Music themselves — this is the only place YouTube Music credentials live.

Not included (v1): BPM-based recommendations. YouTube Music doesn't expose tempo data, so this would need a second data source (e.g. an audio analysis API) — a stretch goal for a future version, not part of this build.

Related MCP server: mcp-server-youtube

Setup

1. Install dependencies

python3 -m venv .venv
source .venv/bin/activate
pip install -e .

2. Authenticate

There's no official YouTube Music API, so ytmusicapi authenticates by reusing headers from your logged-in browser session. Both methods below write the same headers_auth.json file, so you can switch between them freely.

Reads your existing YouTube Music session cookies straight from your browser's local storage — no DevTools, no copy-pasting.

pip install -e ".[browser-auth]"
python scripts/setup_auth_from_browser.py --browser firefox   # or chrome, safari, edge, brave, opera, vivaldi, arc

Requires being logged into music.youtube.com in that browser. Omit --browser to try every installed browser and use the first one with a valid session.

Notes:

  • Chrome/Edge/Brave/Opera/Vivaldi/Arc encrypt their cookie store; on macOS this may trigger a one-time Keychain permission prompt.

  • Some browsers lock their cookie database while running — close the browser first if extraction fails.

Option B: Manual header paste (fallback)

Use this if browser auto-extraction doesn't work for your setup.

  1. Open music.youtube.com in Firefox (recommended — its raw-header copy is more reliable than Chrome's) while logged in.

  2. Open DevTools (Cmd+Option+I / F12) → Network tab → filter by browse.

  3. Click into a playlist, or reload the page, to trigger a browse POST request.

  4. Click that request → Headers tab → toggle Raw headers → select and copy the whole block.

  5. Paste it into a new file named raw_headers.txt in the project root and save.

  6. Run:

    python scripts/setup_auth_from_file.py

    This writes headers_auth.json and deletes raw_headers.txt.

Alternatively, python scripts/setup_auth.py does the same thing via an interactive terminal prompt instead of a file, if you prefer to paste directly.


headers_auth.json is equivalent to your logged-in session — never commit it or share it. It's already gitignored.

Verify auth works before going further:

python scripts/test_search.py

These headers expire/rotate periodically. If tools start failing with an auth error, redo whichever setup option you used.

3. Add to 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 makes it available in any Claude Code session, not just this directory. Use absolute paths for the python interpreter, server.py, and YTMUSIC_AUTH_PATH since the server can be launched from any working directory.

For other MCP clients (Claude Desktop, etc.), point them at the same command and env var using their respective config format.

Testing

The unit test suite (tests/) runs against a hand-rolled fake YTMusic client — no network access or headers_auth.json needed:

pip install -e ".[dev]"
pytest

scripts/test_search.py is a separate real-account smoke test, not part of the unit suite.

Error handling

Tool calls translate common failure modes into clear messages instead of raw tracebacks:

  • Missing/expired/malformed auth → tells you to redo the authenticate step (scripts/setup_auth_from_browser.py or scripts/setup_auth_from_file.py).

  • Rate limiting (HTTP 429) → tells you to wait and retry.

  • Gated/restricted content → reported as unavailable rather than crashing.

  • Network errors → reported directly.

License

MIT — see LICENSE.

Available Tools

6 tools
add_to_playlistC

Add a track to a playlist by video ID.

ParametersJSON Schema
NameRequiredDescriptionDefault
video_idYes
playlist_idYes

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

C2.6/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description must disclose behavioral traits. It indicates a mutation (add) but omits critical details: idempotency, duplicate handling, error conditions (e.g., playlist not found), access requirements, or side effects. This is insufficient for safe agent invocation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single sentence, which is concise. However, conciseness comes at the cost of completeness; a slightly longer description including a prerequisite or behavioral note would improve utility without being verbose.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (mutation, two required params, no annotations, sibling tools), the description is insufficiently complete. It fails to cover execution context (e.g., playlist existence, authentication) and does not leverage the presence of an output schema to reduce burden. Significant gaps remain.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It adds minimal meaning by stating 'by video ID' (hinting that video_id is the identifier) but does not explain the format, constraints, or how to obtain valid values. No additional context for playlist_id.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action (add a track to a playlist) and the key identifier (by video ID). It distinguishes the tool from siblings like create_playlist (creation) and get_playlists (listing). However, it does not specify prerequisites such as playlist ownership or authentication, which slightly weakens clarity.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives. The sibling tools are listed but not referenced, and there is no mention of cases where another tool (e.g., search_music to find a video_id first) might be needed beforehand.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

create_playlistC

Create a new private playlist and return its playlist ID.

ParametersJSON Schema
NameRequiredDescriptionDefault
nameYes
descriptionNo

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

C2.6/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description must fully disclose behavioral traits. It states the tool creates a playlist and returns an ID, but omits important details: whether overwriting occurs for duplicate names, what happens on failure, authorization requirements, or if the playlist is truly private by default. The description leaves significant gaps for a mutation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single sentence of 9 words, front-loading the key action and output. It is concise and to the point, though it sacrifices some necessary detail. No filler or redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given 0% schema description coverage and no annotations, the description is far from complete. It does not explain return value contents beyond 'playlist ID' (output schema exists but description doesn't reference it), error cases, or side effects. For a tool creating a resource, this is insufficient.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, meaning the description adds no meaning to the two parameters—'name' and 'description' are listed but not explained. The description does not mention that 'name' is required or provide any guidance on format, length, or uniqueness. The baseline would be higher with good schema docs, but here description totally fails to compensate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Create'), the resource ('a new private playlist'), and the result ('return its playlist ID'). It distinguishes itself from siblings like add_to_playlist or search_music, but does not specify the playlist is private by default or that the name is required—though that is implied by the schema.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No explicit guidance is given on when to use this tool versus alternatives like get_playlists or add_to_playlist. It does not state prerequisites (e.g., must have account, must not exceed playlist limit) or when not to use it. The context of 'private' is a hint but insufficient for decision-making around usage.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

get_historyB

Get recent play history.

ParametersJSON Schema
NameRequiredDescriptionDefault

No parameters

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

B3.1/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It only implies a read operation with a temporal filter ('recent'), but does not disclose side effects, authentication needs, rate limits, or pagination behavior. The single sentence leaves many important behavioral gaps.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, front-loaded imperative sentence: 'Get recent play history.' It is concise with no wasted words. While it could benefit from slightly more detail, it is not overly sparse to the point of being cryptic. It earns its place by clearly stating the tool's primary action.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given that there are no parameters and an output schema exists to describe return values, the description is minimally acceptable. However, it lacks completeness regarding the definition of 'recent', any implicit limits, and how the results are ordered. The agent may still need to infer these details from the output schema, leaving some uncertainty.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 0 parameters and schema_description_coverage is 100% (trivially). According to the rubric, 0 parameters sets a baseline of 4. The description cannot add parameter meaning beyond the schema, but it does not need to because there are none. This score is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'Get' and the resource 'recent play history'. It distinguishes the tool from siblings like search_music and get_playlists, as none of them deal with history. However, the description could be more specific about the type of history (e.g., playback, search) and the scope of 'recent'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool vs its siblings. There is no mention of use cases, exclusions, or alternatives. The agent receives no contextual hints about selecting this tool over other retrieval or search tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

get_playlistsA

List your YouTube Music library playlists.

ParametersJSON Schema
NameRequiredDescriptionDefault

No parameters

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A3.6/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It only states 'List your YouTube Music library playlists', which is a minimal read operation. It does not mention authentication requirements, whether the list is paginated, or what happens if the library is empty. More transparency is needed for a tool with zero annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, front-loaded sentence of four words: 'List your YouTube Music library playlists.' Every word is meaningful, and there is no redundancy or wasted space. It is optimally concise.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's simplicity (zero parameters) and the presence of an output schema, the description is largely complete. It conveys the core action and scope. However, it could slightly improve by explicitly stating that it returns all playlists for the authenticated user, but this is not a critical gap.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has zero parameters, so schema coverage is effectively 100%. The description adds no parameter semantics (none needed). Baseline 3 applies as the description does not require additional parameter information, but it also does not add value beyond the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description uses a specific verb ('List') and resource ('your YouTube Music library playlists'), clearly distinguishing from siblings like 'create_playlist' or 'search_music'. It is unambiguous and directly states the tool's function.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies the tool is for retrieving all playlists, but it offers no explicit guidance on when to use this versus alternatives like 'get_playlist_tracks' (for a specific playlist's tracks) or 'search_music' (for searching beyond playlists). The purpose is clear, but the usage context is left inferred.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

get_playlist_tracksC

Get the tracks in a playlist.

ParametersJSON Schema
NameRequiredDescriptionDefault
playlist_idYes

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

C2.9/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description must disclose behavioral traits. It fails to mention whether the operation is read-only (likely), if authentication is required, or how it behaves with empty/paginated playlists. The one-line description does not add behavioral depth.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is very concise at one sentence. However, it could be slightly expanded to be more informative without losing brevity. As is, it is not verbose, but 'earns its place' only minimally.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given there is an output schema (providing some structure for results) and a single required parameter, the description still lacks completeness. It does not mention that the result likely includes track details, any sorting, or limits. For such a simple tool, the info gap is moderate.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description needs to compensate. However, it adds no meaning to the playlist_id parameter—no format, ownership context, or example. Given the small parameter count and that the schema provides a title, the description does not significantly enhance understanding.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('get') and the resource ('tracks in a playlist'). Although the name is somewhat self-explanatory, the description provides clarity without being vague. It distinguishes this tool from siblings like search_music or create_playlist, but does not explicitly highlight the distinction.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

There is no guidance on when to use this tool versus alternatives like search_music (which might return tracks based on criteria) or get_playlists. No context is given about prerequisites (e.g., does the playlist need to exist?) or limitations.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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.

ParametersJSON Schema
NameRequiredDescriptionDefault
limitNo
queryYes
filterNo

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

B3.4/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states 'Returns an empty list if there are no matches,' which is useful. However, it does not mention whether the operation is read-only, any rate limits, or side effects. For a search tool, read-only is implied but not confirmed.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise at two sentences plus a list of filter values. It front-loads the main action. However, the filter options are presented as a run-on sentence, which could be clearer with better formatting (e.g., bullet points). Still, it is efficient and avoids unnecessary words.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has 3 parameters, no schema descriptions, no annotations, and an output schema (not shown), the description covers the filter parameter and the empty return case. It does not explain the 'limit' parameter or pagination behavior. The query parameter is obvious. The description is adequate but not complete for a new user.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must add meaning. It explains the 'filter' parameter in detail, listing valid values and the default behavior. It does not explain 'query' (self-explanatory) or 'limit' (not explained). This partially compensates for the schema gap, but one parameter is left undocumented.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states 'Search YouTube Music' which is a clear verb+resource combination. It lists filter options, adding specificity. However, it does not explicitly distinguish from sibling tools, though the sibling tools are all about playlists and history, making the distinction implicit. The purpose is clear but not fully elaborated.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides guidance on the filter parameter ('Omit for a mixed search') but does not explain when to use this tool versus alternatives like get_playlists or get_history. The intended use case is implied by the name, but no explicit when-to-use or when-not-to-use guidance is given.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 6 tool updatesv0.1.0
    • First observedadd_to_playlist
    • First observedcreate_playlist
    • First observedget_history
    • First observedget_playlist_tracks
    • First observedget_playlists
    • First observedsearch_music

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.

Maintenance

ActivityMaintained
ResponsivenessNo issues

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
    C
    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