spotify-mcp-server
by: marcelmarais
spotify mcp server
📌Overview
Purpose: To provide a lightweight Model Context Protocol (MCP) server that allows AI assistants like Cursor and Claude to control Spotify playback and manage playlists efficiently.
Overview: The Spotify MCP Server facilitates seamless integration between AI applications and Spotify, enabling users to control music playback and organize playlists through intuitive commands. This server acts as a bridge, allowing various interactions with Spotify’s features using the MCP framework.
Key Features:
-
Search Operations: Users can search for tracks, albums, artists, or playlists directly in Spotify using commands like
searchSpotify
, which returns detailed information based on specified parameters. -
Playback Control: Commands such as
playMusic
,pausePlayback
, andskipToNext
allow for real-time control of music playback, enabling a smooth user experience tailored to personal preferences. -
Playlist Management: Users can manage their Spotify playlists efficiently with features like
createPlaylist
for creating new playlists andaddTracksToPlaylist
for adding songs to existing playlists. -
Current Playback Information: The
getNowPlaying
command provides users with information about the currently playing track, enhancing situational awareness during playback. -
User-Friendly Setup: The server is easy to set up with clear installation instructions, prerequisites, and configuration steps to connect with Spotify's API, making it accessible to developers.
Spotify MCP Server
A lightweight Model Context Protocol (MCP) server that enables AI assistants like Cursor & Claude to control Spotify playback and manage playlists.
Contents
- Example Interactions
- Tools
- Read Operations
- Play / Create Operations
- Setup
- Prerequisites
- Installation
- Creating a Spotify Developer Application
- Spotify API Configuration
- Authentication Process
- Integrating with Claude Desktop, Cursor, and VsCode (Cline)
Example Interactions
- "Play Elvis's first song"
- "Create a Taylor Swift / Slipknot fusion playlist"
- "Copy all the techno tracks from my workout playlist to my work playlist"
Tools
Read Operations
-
searchSpotify
Search for tracks, albums, artists, or playlists on Spotify.- Parameters:
query
(string): The search termtype
(string): Type of item to search for (track, album, artist, playlist)limit
(number, optional): Max results (10-50)
- Returns: List of matching items with IDs, names, etc.
- Example:
searchSpotify("bohemian rhapsody", "track", 20)
- Parameters:
-
getNowPlaying
Get info about the currently playing track.- Parameters: None
- Returns: Track name, artist, album, playback progress, duration, and state
- Example:
getNowPlaying()
-
getMyPlaylists
Get current user's playlists.- Parameters:
limit
(number, optional, default 20)offset
(number, optional, default 0)
- Returns: Array of playlists with IDs, names, counts, public status
- Example:
getMyPlaylists(10, 0)
- Parameters:
-
getPlaylistTracks
Get tracks in a specific playlist.- Parameters:
playlistId
(string)limit
(number, optional, default 100)offset
(number, optional, default 0)
- Returns: Array of tracks with details
- Example:
getPlaylistTracks("37i9dQZEVXcJZyENOWUFo7")
- Parameters:
-
getRecentlyPlayed
Retrieves recently played tracks.- Parameters:
limit
(number, optional)
- Returns: Formatted list of recently played tracks or message if none found
- Example:
getRecentlyPlayed({ limit: 10 })
- Parameters:
Play / Create Operations
-
playMusic
Start playing a track, album, artist, or playlist.- Parameters:
uri
(string, optional)type
(string, optional)id
(string, optional)deviceId
(string, optional)
- Returns: Success status
- Example:
playMusic({ uri: "spotify:track:6rqhFgbbKwnb9MLmUQDhG6" })
- Alternative:
playMusic({ type: "track", id: "6rqhFgbbKwnb9MLmUQDhG6" })
- Parameters:
-
pausePlayback
Pause currently playing track.- Parameters:
deviceId
(string, optional)
- Returns: Success status
- Example:
pausePlayback()
- Parameters:
-
skipToNext
Skip to the next track.- Parameters:
deviceId
(string, optional)
- Returns: Success status
- Example:
skipToNext()
- Parameters:
-
skipToPrevious
Skip to the previous track.- Parameters:
deviceId
(string, optional)
- Returns: Success status
- Example:
skipToPrevious()
- Parameters:
-
createPlaylist
Create a new playlist.- Parameters:
name
(string)description
(string, optional)public
(boolean, optional, default false)
- Returns: Object with new playlist's ID and URL
- Example:
createPlaylist({ name: "Workout Mix", description: "Songs to get pumped up", public: false })
- Parameters:
-
addTracksToPlaylist
Add tracks to an existing playlist.- Parameters:
playlistId
(string)trackUris
(array)position
(number, optional)
- Returns: Success status and snapshot ID
- Example:
addTracksToPlaylist({ playlistId: "3cEYpjA9oz9GiPac4AsH4n", trackUris: ["spotify:track:4iV5W9uYEdYUVa79Axb7Rh"] })
- Parameters:
-
addToQueue
Add a track, album, artist or playlist to the playback queue.- Parameters:
uri
(string, optional)type
(string, optional)id
(string, optional)deviceId
(string, optional)
- Returns: Success status
- Example:
addToQueue({ uri: "spotify:track:6rqhFgbbKwnb9MLmUQDhG6" })
- Alternative:
addToQueue({ type: "track", id: "6rqhFgbbKwnb9MLmUQDhG6" })
- Parameters:
Setup
Prerequisites
- Node.js v16+
- A Spotify Premium account
- A registered Spotify Developer application
Installation
git clone https://github.com/marcelmarais/spotify-mcp-server.git
cd spotify-mcp-server
npm install
npm run build
Creating a Spotify Developer Application
- Go to the Spotify Developer Dashboard: https://developer.spotify.com/dashboard/
- Log in with your Spotify account
- Click "Create an App"
- Fill in the app name and description
- Accept Terms of Service and click "Create"
- Get your Client ID and Client Secret
- Add a Redirect URI (e.g.,
http://localhost:8888/callback
) in app settings
Spotify API Configuration
Copy the example config file and edit with your credentials:
cp spotify-config.example.json spotify-config.json
Example spotify-config.json
:
{
"clientId": "your-client-id",
"clientSecret": "your-client-secret",
"redirectUri": "http://localhost:8888/callback"
}
Authentication Process
Spotify uses OAuth 2.0. To authenticate:
- Run:
npm run auth
- Open the generated authorization URL in your browser.
- Log in and authorize your app.
- After redirect, the script exchanges code for access and refresh tokens.
- Tokens saved in
spotify-config.json
:
{
"clientId": "your-client-id",
"clientSecret": "your-client-secret",
"redirectUri": "http://localhost:8888/callback",
"accessToken": "BQAi9Pn...kKQ",
"refreshToken": "AQDQcj...7w",
"expiresAt": 1677889354671
}
- The server auto-refreshes tokens when needed.
Integrating with Claude Desktop, Cursor, and VsCode (Cline)
To use your MCP server with Claude Desktop, add it to your Claude config:
{
"mcpServers": {
"spotify": {
"command": "node",
"args": ["spotify-mcp-server/build/index.js"]
}
}
}
For Cursor:
- Open MCP tab in Cursor Settings (command + shift + J)
- Add a server with the command:
node path/to/spotify-mcp-server/build/index.js
For Cline, configure cline_mcp_settings.json
:
{
"mcpServers": {
"spotify": {
"command": "node",
"args": ["~/../spotify-mcp-server/build/index.js"],
"autoApprove": ["getListeningHistory", "getNowPlaying"]
}
}
}
Add additional tools to autoApprove
to enable automatic tool execution.