spotify-mcp

spotify-mcp

MCP server for Spotify that enables searching, reading playlists, saved tracks, artist info, and recommendations, plus creating playlists and adding tracks, with no playback control.

Category
访问服务器

README

spotify-mcp

An MCP server that wraps spotipy so Claude (or any MCP client) can search Spotify and read playlists, saved tracks, artist catalogs, and discovery signals.

Built specifically as re-com's Spotify backend — read-heavy by design, not a playback-control server. It does support creating playlists and adding tracks to them (so a re-com recommendation list can become a real playlist), but there's no play/pause/queue control; look at one of the several playback-focused Spotify MCP servers already out there for that.

Tools

Tool Description
search_music(query, filter="track", limit=20) Search Spotify. filter is track or artist.
get_playlists(limit=None) List the current user's playlists. Omit limit to fetch all of them.
get_playlist_tracks(playlist_id, limit=None) Get the tracks in a playlist. Local files/episodes are skipped.
get_saved_tracks(limit=None) Get the user's saved ("Liked Songs") tracks.
get_track(track_id) Get a single track's metadata.
get_recommendations(seed_track_id, limit=25) Spotify's algorithmic recommendations from one seed track — the closest analog to YouTube Music's radio.
get_artist(artist_id) Get an artist's profile.
get_artist_top_tracks(artist_id) An artist's top tracks (Spotify caps this at ~10 — there's no full-catalog endpoint).
get_related_artists(artist_id) Artists related to the given one.
get_recently_played(limit=50) The user's recently played tracks.
create_playlist(name, public=False, description="") Create a new playlist owned by the current user.
add_tracks_to_playlist(playlist_id, track_ids) Add tracks (by ID or URI) to a playlist, chunked in batches of 100.
logout() Delete the cached OAuth token.

A real limitation, stated plainly: Spotify restricts /recommendations and artist_related_artists for API apps created after November 2024 that don't have "Extended Quota Mode" (a manual approval Spotify grants sparingly). If your app doesn't have it, get_recommendations and get_related_artists will 403 — handle_errors turns that into a clear message rather than a raw traceback, and re-com's spotify_client.py treats it as one signal being unavailable, not a fatal error. search_music, playlists, saved tracks, and artist top tracks are unaffected.

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

Setup

1. Register a Spotify app

  1. Go to the Spotify Developer Dashboard, create an app.
  2. Add a redirect URI matching SPOTIFY_REDIRECT_URI (default http://127.0.0.1:8888/callback — you don't need anything actually listening on that port; see step 3).
  3. Note the app's Client ID and Client Secret.

2. Install dependencies

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

3. Authenticate

export SPOTIFY_CLIENT_ID="..."
export SPOTIFY_CLIENT_SECRET="..."
python scripts/setup_auth_spotify.py

This prints an authorization URL, waits for you to log in and paste back the URL you're redirected to (works fine over SSH/headless — nothing needs to bind the redirect port), and writes the resulting token to .spotify_cache (path configurable via SPOTIFY_CACHE_PATH).

.spotify_cache is equivalent to your logged-in session — never commit it or share it. It's already gitignored. Tokens refresh automatically once cached; re-run this script only if refresh itself starts failing (e.g. the app's client secret was rotated, or you revoked access from your Spotify account settings), or if SCOPE in server.py gains new permissions (delete .spotify_cache first so the auth flow re-prompts for consent — a stale cached token won't pick up new scopes on its own).

4. Add to Claude Code

claude mcp add spotify -s user \
  -e SPOTIFY_CLIENT_ID="..." \
  -e SPOTIFY_CLIENT_SECRET="..." \
  -e SPOTIFY_CACHE_PATH="$(pwd)/.spotify_cache" \
  -- "$(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 SPOTIFY_CACHE_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 vars using their respective config format.

Testing

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

pip install -e ".[dev]"
pytest

Error handling

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

  • Missing/expired auth (401) → tells you to redo authenticate step.
  • Restricted/forbidden (403) → tells you it's likely a Spotify API access restriction (see the recommendations/related-artists caveat above) or a missing OAuth scope.
  • Rate limiting (429) → tells you to wait, including the Retry-After hint if Spotify sent one.
  • Any other API or OAuth error is reported directly rather than as a raw traceback.

License

MIT — see LICENSE.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选