Skip to main content
Glama
spotify-mcp

spotify-mcp

by codebyotto

spotify-mcp

A FastMCP server that lets an AI agent search Spotify, read your listening history, and create or extend your playlists. It runs over stdio, so it works with Claude Code and other MCP clients.

It targets the Spotify Web API after the February 2026 Development Mode changes:

  • playlist items are at /playlists/{id}/items;

  • playlists are created with POST /me/playlists;

  • search returns at most 10 results per request;

  • batch GET /tracks no longer exists.

Tools

Tool

What it does

Annotations

search_tracks(query, limit=5, offset=0)

Searches the catalog. Returns unique, ranked, compact tracks. limit can be up to 30; the tool fetches Spotify's 10-result pages itself and removes duplicates.

read-only, idempotent, open-world

list_my_playlists(limit=20, offset=0)

Lists your playlists with id, item_count and a computed can_edit (owner or collaborative).

read-only, idempotent, open-world

get_recently_played(limit=50, before=null)

Lists your recently played tracks (Spotify keeps about the last 50).

read-only, idempotent, open-world

get_my_top_tracks(time_range="short_term", limit=50, offset=0)

Lists your most played tracks for about 4 weeks, 6 months or a year.

read-only, idempotent, open-world

create_playlist(name, description="", public=false)

Creates an empty playlist. Reads it back and reports what Spotify actually stored, with warnings if that differs from the request.

write, not destructive, not idempotent, open-world

add_tracks_to_playlist(playlist_id, track_uris, position=null, dry_run=true)

Previews (the default) or performs adding 1–20 tracks. Both modes first check that the playlist exists and is editable and that every track exists.

write, not destructive, not idempotent, open-world

Typical chain: search_tracks (or a history tool) → list_my_playlists or create_playlist → add_tracks_to_playlist(dry_run=true) → you confirm → the same call with dry_run=false.

Track uri values from the read tools go into add_tracks_to_playlist.track_uris. Playlist id values from list_my_playlists or create_playlist go into add_tracks_to_playlist.playlist_id.

Related MCP server: Spotify MCP Server

Requirements

  • uv and Python ≥ 3.12.

  • A Spotify Premium account. Since February 2026 the owner of a Development Mode app must have Premium, and the app allows at most 5 users.

Commands

What

Command

Install deps

uv sync

One-time Spotify login

uv run spotify-mcp-login

Check the stored login

uv run spotify-mcp-login --check

Start the server (stdio)

uv run spotify-mcp

Run the tests

uv run pytest

The tests are fully mocked with respx, so they need no network and no credentials.

Spotify setup (one time)

  1. Go to https://developer.spotify.com/dashboard and choose Create app.

    • Under Which API/SDKs are you planning to use?, tick Web API.

    • Add the redirect URI http://127.0.0.1:8888/callback. Spotify does not accept localhost; it must be the loopback IP.

  2. In the app's User Management tab, add the email of your Spotify account.

  3. cp .env.example .env and set SPOTIFY_CLIENT_ID. The client secret is not needed because the server uses PKCE.

  4. Run uv run spotify-mcp-login. A browser opens; approve the requested scopes.

    • The refresh token is stored in .spotify_token.json with mode 0600. The file is git-ignored.

    • The server refreshes access tokens from it automatically.

Requested scopes:

  • playlist-read-private and playlist-read-collaborative, to list your playlists.

  • playlist-modify-private and playlist-modify-public, to create playlists and add tracks.

  • user-read-private, for search and your profile.

  • user-read-recently-played and user-top-read, for your listening history.

Connect to Claude Code

  1. Copy .mcp.json.template to .mcp.json, in the directory where you start Claude Code. Or add the same entry to your user-level MCP config.

  2. Replace <ABSOLUTE_PATH_TO_REPO> with the path to this repository and <your-spotify-client-id> with your Client ID.

    • .mcp.json is git-ignored because it contains the Client ID.

    • If the env block is left out, the server falls back to this repository's .env.

  3. Start claude and approve the spotify server.

  4. /mcp should show spotify · connected with 6 tools.

Then you can ask things like: "Find five songs like my top tracks from the last month and put them in a new private playlist called Discoveries. Show me what you'll add first."

Design notes

  • Auth. OAuth Authorization Code with PKCE.

    • Only the public Client ID appears in config, so there is no client secret that could leak.

    • Login is a separate command, because a stdio server cannot run an interactive browser flow in the middle of a tool call.

    • The server refreshes the token before it expires, and on a 401 it refreshes once and retries. If Spotify returns a new refresh token, it is saved.

  • Errors. Every failure becomes CATEGORY (HTTP n): what failed. Retryable: yes/no [(after Ns)]. Next step: ….

    • Categories: INVALID_INPUT, AUTH_REQUIRED, CONFIG_ERROR, PERMISSION_DENIED, NOT_FOUND, RATE_LIMITED, QUOTA_EXCEEDED, UPSTREAM_UNAVAILABLE.

    • A 429 is not retried silently: the agent gets Retry-After and decides.

  • Inputs. Schema bounds and patterns reject wrong input before any API call: Spotify's real limit ranges, a 22-character playlist ID, spotify:track: URIs, and 1–20 tracks per call.

  • Outputs. Compact pydantic models keep only names and IDs; images, hrefs and markets are dropped.

  • Safety. Writes only add; nothing is removed or overwritten. add_tracks_to_playlist defaults to a dry run, and create_playlist reads the playlist back because Spotify can echo public=false for a playlist it stores as public.

Layout

src/spotify_mcp/
  server.py   FastMCP instance + the 6 tools; main() serves stdio
  client.py   async httpx wrapper: auth header, 401 refresh-retry, error mapping
  auth.py     PKCE login CLI, token store (0600), refresh
  errors.py   error categories + agent-facing messages
  models.py   compact output models + mappers
tests/        pytest tests; tools are called through MCP (fastmcp.Client), Spotify is mocked with respx

License

MIT

Available Tools

6 tools
add_tracks_to_playlistAdd tracks to a playlist (dry run by default)A

Preview (dry_run=true, the default) or perform adding tracks to one of the user's playlists.

Both modes check that the playlist exists, that the user can edit it, and that every track URI exists, and they return the resolved track names. A dry run changes nothing. With dry_run=false the tracks are added to the live playlist. This is not idempotent: repeating the call adds the tracks again as duplicates. Recommended flow: search_tracks -> list_my_playlists/create_playlist -> this tool with dry_run=true -> user confirms -> same arguments with dry_run=false.

Inputs: track_uris (required), playlist_id (required), dry_run, position. Returns: tracks, dry_run, message, playlist, +3 more

create_playlistCreate a Spotify playlistA

Create a new, empty playlist owned by the signed-in user.

WRITE: this changes the user's Spotify account immediately and cannot be undone by these tools. Calling it twice creates two playlists. Only call it when the user asked for a new playlist; to extend an existing one, use list_my_playlists instead. The returned id is the playlist_id for add_tracks_to_playlist. Check warnings and tell the user about them before adding tracks.

Inputs: name (required), public, description. Returns: id, name, owner, public, +3 more

get_my_top_tracksGet my top tracksA
Read-onlyIdempotent

List the signed-in user's most played tracks for a time range, ranked by Spotify.

Each uri can be passed to add_tracks_to_playlist.track_uris. Read-only.

Inputs: limit, offset, time_range. Returns: total, tracks, time_range, next_offset

get_recently_playedGet my recently played tracksA
Read-onlyIdempotent

List the signed-in user's recently played tracks (Spotify keeps only the last ~50 plays).

Each uri can be passed to add_tracks_to_playlist.track_uris. Read-only. For "what does the user listen to over the last weeks", prefer get_my_top_tracks.

Inputs: limit, before. Returns: before, tracks

list_my_playlistsList my Spotify playlistsA
Read-onlyIdempotent

List playlists in the signed-in user's library (owned, collaborative and followed).

Each playlist's id is the playlist_id for add_tracks_to_playlist. Only playlists with can_edit: true (owned by the user or collaborative) accept new tracks. Read-only.

Inputs: limit, offset. Returns: total, playlists, next_offset

search_tracksSearch Spotify tracksA
Read-onlyIdempotent

Search the Spotify catalog for tracks.

Returns unique, ranked, compact track entries. Each uri (spotify:track:…) can be passed directly to add_tracks_to_playlist.track_uris. Read-only; nothing in the user's account changes.

Inputs: query (required), limit, offset. Returns: query, total, tracks, next_offset, +1 more

Tool Schema Changelog

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

Loading tool schema changelog…

    TDQS

    A4.1/5.0

    Scored across 6 tools

    Disambiguation4/5

    Each tool targets a distinct resource+action: catalog search, playlist listing, recently played, top tracks, playlist creation, and track addition. The only potential confusion is between get_recently_played and get_my_top_tracks, but the descriptions explicitly cross-reference each other to steer selection.

    Naming Consistency4/5

    All names use a clear, readable snake_case verb_noun pattern (search_tracks, create_playlist, add_tracks_to_playlist). The only deviation is the inconsistent inclusion of 'my' in list_my_playlists and get_my_top_tracks versus the plain forms elsewhere, but this is minor and never ambiguous.

    Tool Count4/5

    Six tools is a tight, well-scoped set for a read-heavy Spotify integration with a single write path, and each tool clearly earns its place. It sits at the low end of the ideal 3-15 range but is not thin enough to hurt usability.

    Completeness3/5

    The create/search/add flow is well covered, but the surface has notable gaps: there is no way to read the contents of an existing playlist, remove or reorder tracks, or undo the warned-about non-idempotent add. An agent can build playlists but cannot inspect or clean them up afterward, creating dead ends.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables an AI agent to search, create, add, remove, reorder, dedupe and rename Spotify playlists and build lists from song titles, while auditing every write, supporting undo, and restricting changes to playlists the user owns.
      PolyForm Noncommercial 1.0.0