An Model Context Protocol (MCP) server, enabling Claude Desktop as the MCP Client to interact with the Spotify and Reccobeats API.
Ensure the following are installed:
- Node.js (v22/LTS recommended)
-
Clone the repository:
git clone https://github.com/your-username/spotify-mcp.git cd spotify-mcp -
Install the dependencies:
npm install
This server requires Spotify API credentials and a refresh token to function. Follow these steps to set up your .env file:
-
Create a Spotify Developer Application:
- Go to the Spotify Developer Dashboard.
- Log in with your Spotify account.
- Click on "Create an app".
- Fill in the details (App name, App description) and agree to the terms.
- Once created, you will see your
Client IDandClient Secret.
-
Set up Redirect URI:
- In your Spotify application dashboard, click "Edit Settings".
- Under "Redirect URIs", add
http://localhost:4567/callback. - Save the changes.
-
Get a Spotify Refresh Token:
- Run the server (as described in "Running the Server" below).
- Open your web browser and navigate to
http://localhost:4567/login. - You will be redirected to Spotify to authorize the application. Log in if prompted.
- After authorization, you will be redirected back to
http://localhost:4567/callback. Check your server's console output for yourRefresh Token.
-
Create a
.envfile:- In the root directory of your
spotify-mcpproject, create a file named.env. - Add the following lines to the
.envfile, replacing the placeholders with your actual credentials and refresh token:
SPOTIFY_CLIENT_ID=your_spotify_client_id SPOTIFY_CLIENT_SECRET=your_spotify_client_secret SPOTIFY_REFRESH_TOKEN=your_spotify_refresh_token
- In the root directory of your
-
Build the TypeScript project:
npm run build
-
Start the server:
node build/server.js
The server will start and listen on
http://localhost:4567. IfSPOTIFY_REFRESH_TOKENis not set in your.envfile, it will also start an OAuth server for one-time authentication.
To connect this MCP server to Claude Desktop:
- Open Claude Desktop.
- Go to Settings.
- Navigate to the "Model Context Protocol" section.
- Add a new server and configure it to point to your running Spotify MCP server (e.g.,
http://localhost:4567). - Ensure the server is enabled in Claude Desktop.
Once connected, you can prompt Claude to use the available Spotify tools.
This server exposes the following tools:
-
get_user_playlists- Description: Gets a list of the user's Spotify playlists.
- Input:
page(optional, number): The page number to retrieve (defaults to 1).per_page(optional, number): The number of playlists per page (defaults to 15).
- Output: A JSON string representing an array of playlist objects, each with
idandname.
-
get_playlist_tracks- Description: Gets a paginated list of tracks from a user's specific playlist by name.
- Input:
playlist_name(string, required): The name of the playlist.page(optional, number): The page number to retrieve (defaults to 1).per_page(optional, number): The number of tracks per page (defaults to 15).
- Output: A JSON string representing an array of track objects, each with
id,name, andartist.
-
get_track_audio_features- Description: Gets the audio features for a single track, given its unique ID.
- Input:
track_id(string, required): The unique Spotify ID of the track.
- Output: A JSON object containing the audio features for the specified track.
-
Server not starting or
EPIPEerrors:- Ensure no other process is using port
4567. - Check your
.envfile for correct Spotify credentials.
- Ensure no other process is using port
-
/loginroute not working:- If
SPOTIFY_REFRESH_TOKENis already set in your.envfile, the OAuth server (including/login) will not start automatically. Unset the variable and restart the server to re-authenticate.
- If
