Skip to main content
Glama
umsachde

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. 打开开发者工具(Cmd+Option+I / F12)→ 网络 标签页 → 按 browse 过滤。

  3. 点击进入一个播放列表,或重新加载页面,以触发一个 browse POST 请求。

  4. 点击该请求 → 标头 标签页 → 切换 原始标头 → 选择并复制整个块。

  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.

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

ActivitySlowing
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