Skip to main content
Glama
README.md
# spotify-mcp

An [MCP](https://modelcontextprotocol.io) server that lets an AI assistant control Spotify: playback,
search, your library, and full playlist management. It is built against the Spotify Web API as it
stands after the [February 2026 changes](https://developer.spotify.com/documentation/web-api/references/changes/february-2026)
(`/me/library`, `/me/playlists`, `/playlists/{id}/items`), which broke most older Spotify MCP servers.

- Login uses OAuth PKCE: you only need a Client ID, no client secret.
- Everything it stores lives in one directory (`~/.spotify-mcp`), so removing it is one command.

## Tools

| Area      | Tools                                                                                                                                                                      |
| --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Login     | `authenticate`                                                                                                                                                             |
| Catalog   | `search`, `get_details`                                                                                                                                                    |
| Playback  | `play` (URI, search query, or list), `playback_control` (pause, resume, next, previous, seek, volume, shuffle, repeat), `now_playing`, `devices`, `queue_get`, `queue_add` |
| Library   | `library_list`, `library_save`, `library_remove`, `library_check`                                                                                                          |
| Playlists | `playlists_list`, `playlist_items`, `playlist_create`, `playlist_update`, `playlist_add`, `playlist_remove`, `playlist_reorder`, `playlist_replace`, `playlist_delete`     |
| Stats     | `recently_played`, `top_items`                                                                                                                                             |

Tools accept Spotify URIs (`spotify:track:…`) and `open.spotify.com` links interchangeably.

## Requirements

- Node.js 22.18 or newer
- Spotify Premium (Spotify requires it for playback control and for developer apps)
- A Spotify developer app (free, takes two minutes):
  1. Open the [developer dashboard](https://developer.spotify.com/dashboard) and create an app.
  2. Add the Redirect URI `http://127.0.0.1:8888/callback` exactly (Spotify rejects `localhost`).
  3. Tick **Web API**, save, and copy the **Client ID**.

## Setup

Add the server to your MCP client. It runs straight from GitHub; nothing is installed globally.

**Claude Code**

```sh
claude mcp add spotify -e SPOTIFY_CLIENT_ID=<your-client-id> -- npx -y github:coconutbird/spotify-mcp
```

**Claude Desktop, Cursor, and other clients**

```json
{
  "mcpServers": {
    "spotify": {
      "command": "npx",
      "args": ["-y", "github:coconutbird/spotify-mcp"],
      "env": { "SPOTIFY_CLIENT_ID": "<your-client-id>" }
    }
  }
}
```

Then ask the assistant to connect Spotify: the `authenticate` tool opens the browser for approval.
Alternatively, log in from a terminal first:

```sh
npx -y github:coconutbird/spotify-mcp auth --client-id <your-client-id>
```

### Configuration

| Variable               | Default                          | Purpose                                     |
| ---------------------- | -------------------------------- | ------------------------------------------- |
| `SPOTIFY_CLIENT_ID`    | stored by `auth --client-id`     | Client ID of your Spotify app               |
| `SPOTIFY_REDIRECT_URI` | `http://127.0.0.1:8888/callback` | Must match the URI registered for your app  |
| `SPOTIFY_MCP_HOME`     | `~/.spotify-mcp`                 | Where the config and the refresh token live |

## Removing it

1. Delete the stored token and config: `npx -y github:coconutbird/spotify-mcp reset`
   (or delete `~/.spotify-mcp`).
2. Remove the server from your client, e.g. `claude mcp remove spotify`.
3. Optionally delete the app in the Spotify dashboard, or revoke access under
   [Manage apps](https://www.spotify.com/account/apps/).

## CLI

```
spotify-mcp [serve]                 Run the MCP server on stdio (default)
spotify-mcp auth [--client-id ID]   Log in to Spotify in the browser
spotify-mcp status                  Show the configuration and login state
spotify-mcp logout                  Delete the stored token
spotify-mcp reset                   Delete all stored data
```

## Development

The repository pins its toolchain with [mise](https://mise.jdx.dev) (Node LTS).

```sh
mise install          # Node LTS
mise run install      # npm ci
mise run check        # typecheck, lint, format check, tests
mise run build        # compile to dist/
mise run fix          # eslint --fix and prettier
```

Layout:

```
src/
  index.ts             CLI entry point
  cli/commands.ts      serve, auth, status, logout, reset
  server.ts            MCP server: registers every tool group
  app-context.ts       composition root (storage, login flow, Spotify client)
  config/              settings resolution and validated JSON storage
  auth/                PKCE login flow, callback listener, token refresh
  spotify/
    api-client.ts      axios instance: auth header, retry on 401/429, error mapping
    services/          one service class per API area (*.service.ts)
    types.ts, uri.ts   response types, URI/URL parsing
  tools/               one module per tool group (*.tools.ts) plus shared params/resolvers
  format/              plain-text renderings returned to the model
test/                  unit suites (node:test, run directly from TypeScript)
  integration/         MCP client → server → services → axios → a local fake Spotify over HTTP
  support/             the fake Spotify server and the integration harness
```

## License

MIT