spotify-mcp
by duffey
README.md
# spotify-mcp
An unofficial, personal Spotify MCP server. It keeps a local copy of your playlists and Liked Songs,
so it knows every one of them (your own, collaborative and followed), and it can edit playlists,
search and browse Spotify, and control playback.
This is an independent project, not affiliated with or endorsed by Spotify.
## Setup
You need [uv](https://docs.astral.sh/uv/) and a Spotify Premium account.
1. Create an app at <https://developer.spotify.com/dashboard>. Spotify requires Premium for this.
2. Give the app the redirect URI `http://127.0.0.1:8888/callback` and select the Web API.
3. Copy the app's client ID. No client secret is used.
4. Log in and make the first copy of your library:
```
uvx --from git+https://github.com/duffey/spotify-mcp spotify-mcp sync
```
This asks for the client ID, then opens Spotify's login page in your browser.
5. Register the server with your MCP host. For Claude Code:
```
claude mcp add --scope user spotify -- uvx --from git+https://github.com/duffey/spotify-mcp spotify-mcp
```
For Claude Desktop, in `claude_desktop_config.json`:
```json
{
"mcpServers": {
"spotify": {
"command": "uvx",
"args": ["--from", "git+https://github.com/duffey/spotify-mcp", "spotify-mcp"]
}
}
}
```
Use the absolute path to `uvx` if the host cannot find it.
`uvx` fetches the code from GitHub the first time and reuses it afterwards; add `--refresh` after
`uvx` to pick up a newer version.
To work on the code instead, clone the repository and use `uv run spotify-mcp` in place of the
`uvx --from ... spotify-mcp` part.
## Sync
```
uvx --from git+https://github.com/duffey/spotify-mcp spotify-mcp sync
```
The first run asks for the client ID, then opens Spotify's login page in your browser. Later runs
reuse the saved login. The server's `sync_library` tool does the same from inside a chat.
Sync copies every playlist in your library, and your Liked Songs, into a local SQLite database. A
playlist's tracks are fetched again only when the playlist has changed, and Liked Songs only when
they have, so repeat syncs are quick. `--full` fetches everything again.
## Tools
### Your library
| Tool | What it does |
|---|---|
| `list_playlists` | Every playlist in your library with owner, track count, description and link, plus Liked Songs and when the copy was last synced. Optional word filter. |
| `get_playlist` | One playlist by name, id, URI or link, or `Liked Songs`: its details and tracks in order, paged. |
| `search_tracks` | Tracks across all playlists and Liked Songs by words, artist, album or playlist, each with the playlists it is in. Ignores case and accents. |
| `get_library` | Saved albums, podcast shows and episodes, and followed artists. |
| `get_listening_history` | The last tracks played, or your most played tracks or artists over about 4 weeks, 6 months or a year. |
| `sync_library` | Runs the sync from inside the server, using the login saved by the sync command. |
### All of Spotify
| Tool | What it does |
|---|---|
| `search_spotify` | Searches Spotify for tracks, albums, artists or playlists, and marks tracks already in your playlists. |
| `browse_spotify` | Opens an album (its tracks), an artist (their releases) or a podcast show (its episodes). |
### Changing things
| Tool | What it does |
|---|---|
| `create_playlist` | Creates a playlist, optionally filled with tracks. |
| `add_to_playlist` | Adds tracks at the end or at a position, skipping ones the playlist already has. With `Liked Songs`, likes them. |
| `remove_from_playlist` | Removes tracks from a playlist. With `Liked Songs`, unlikes them. |
| `move_playlist_tracks` | Moves a track, or a run of tracks in a row, to a new position. |
| `update_playlist` | Changes a playlist's name, description, public or collaborative setting. |
| `set_playlist_cover` | Replaces a playlist's cover with a picture from a file on this computer or an https link, converted and shrunk to fit Spotify's limit. |
| `delete_playlist` | Deletes one of your playlists, or unfollows someone else's. |
| `save_to_library` | Likes tracks, saves albums and podcasts, follows playlists. |
| `remove_from_library` | Unlikes tracks, removes saved albums and podcasts. |
These update the local copy as they go, so no sync is needed afterwards.
### Playback
| Tool | What it does |
|---|---|
| `get_playback` | What is playing, on which device, with shuffle and repeat, every available device, and optionally the queue. |
| `play` | Plays tracks, a playlist from your library by name, Liked Songs, or any album, artist or playlist; with nothing given, resumes. |
| `control_playback` | Pause, resume, next, previous. |
| `set_playback` | Volume, shuffle, repeat and position in the track. |
| `add_to_queue` | Queues tracks after the current one. |
| `transfer_playback` | Moves playback to another device. |
Playback needs Spotify open on some device. When no device is active and exactly one is available,
that one is used; otherwise name the device.
## What Spotify does not allow
- **Tracks of playlists you only follow.** Spotify shares contents only for playlists you own or
collaborate on. The others are stored with their name and details but without tracks.
- **Private playlists.** Spotify makes playlists created through its API public whatever is asked,
and ignores a later request to make them private. The tools report what Spotify applied.
- **Following artists.** Followed artists can be listed, not followed or unfollowed.
- **Removing one copy of a duplicate.** Removal is by track, so every copy in the playlist goes.
- **Editing the queue.** Tracks can be added, not removed or reordered.
- **Search results.** At most 10 of each kind per request.
## Layout
- `spotify_mcp/server.py`: the entry point. `app.py` holds the server object and the instructions
it gives the model.
- `spotify_mcp/tools/`: the tools, one module per thing they work on (`playlists`, `library`,
`catalog`, `playback`, `history`), with what they share in `common.py`.
- `spotify_mcp/api.py`: the Spotify Web API client. `auth.py` is the login, `refs.py` reads URIs
and links, `cover.py` prepares cover pictures.
- `spotify_mcp/store.py`, `queries.py`, `sync.py`: the local database (schema and writes, reads,
and copying from Spotify).
- `spotify_mcp/describe.py`: the compact descriptions tools return.
- `tests/`: pytest suite against a fake Spotify (`fakes.py`); no network.
## Where things are kept
The client ID, login token and database live in your per-user data folder
(`%LOCALAPPDATA%\spotify-mcp` on Windows), never in this repository. Set `SPOTIFY_MCP_HOME` to use
another folder, and `SPOTIFY_CLIENT_ID` to supply the client ID from the environment.
## Tests
```
uv run pytest
```
## License
[MIT No Attribution](LICENSE): do anything with it, no credit needed, no warranty.
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues