Connect your Spotify account to AI tools and automate your music experience with the Model Context Protocol (MCP).
The Spotify MCP Server implements the Model Context Protocol to bridge your Spotify account with AI-powered tools like Cursor, Claude, VS Code, and more. It enables AI models to search, analyze, and manage your Spotify music library, playlists, and playback through natural language instructions.
- π΅ Music Search & Discovery: Find tracks, albums, artists, playlists, shows, and episodes
- π Playlist Management: View, create, update, reorder, and manage playlists
- π User Library Access: Access and modify your saved tracks, albums, and shows
- π― Personalized Recommendations: Get music suggestions based on your taste
- π Audio Analysis: Retrieve audio features (danceability, energy, tempo, etc.) for tracks
- π§ Playback Control: (Premium only) Play, pause, skip, and control playback devices
- π User Insights: View your top tracks, artists, and listening history
- π Queue Management: Add tracks to your queue and view upcoming songs
- π± Device Management: Transfer playback between devices
- A Spotify account (Premium required for playback control)
- Spotify API credentials (see below)
- Node.js 18 or newer
- Go to the Spotify Developer Dashboard
- Create a new application
- Note your Client ID and Client Secret
- Set the Redirect URI to:
http://127.0.0.1:8000/callback
Create a .env file in your project root:
SPOTIFY_CLIENT_ID=your-client-id
SPOTIFY_CLIENT_SECRET=your-client-secret
SPOTIFY_REDIRECT_URI=http://127.0.0.1:8000/callbackNote: You no longer need to manually obtain access tokens! The server will handle the OAuth flow automatically.
# Install dependencies
npm install
# Build the server
npm run build
# Start the server
npm startAdd this configuration to your MCP-compatible application (example for Cursor):
{
"mcpServers": {
"spotify": {
"command": "npx",
"args": ["-y", "@tdp2003/spotify-mcp@latest"],
"env": {
"SPOTIFY_CLIENT_ID": "your-client-id",
"SPOTIFY_CLIENT_SECRET": "your-client-secret",
"SPOTIFY_REDIRECT_URI": "http://127.0.0.1:8000/callback"
}
}
}
}- Call the
get_initial_contexttool in your AI application - If not already authorized, you'll receive an authorization URL
- Open the URL in your browser and log in to Spotify
- Authorize the application - you'll be redirected automatically
- Call
get_initial_contextagain to confirm the connection
β οΈ Important: Always callget_initial_contextfirst to initialize your Spotify connection before using any other tools.
Required first step - Initializes your Spotify connection and provides usage instructions. This tool must be called before any other operations.
What it does:
- Validates your Spotify API credentials
- Initiates OAuth flow if needed
- Retrieves your user profile and account information
- Provides connection status and available features
- Returns usage instructions for the AI assistant
Retrieve playlists for the current user or a specific user.
Parameters:
limit(optional): Number of playlists to return (1-50, default: 20)offset(optional): Index of the first playlist to return (default: 0)userId(optional): User ID to get playlists for (defaults to current user)
Returns: Playlist metadata including name, description, track count, privacy settings, and owner information.
Create a new playlist with customizable settings.
Parameters:
name(required): Playlist namedescription(optional): Playlist descriptionpublic(optional): Whether playlist is public (default: false)collaborative(optional): Whether playlist is collaborative (default: false)userId(optional): User ID to create playlist for (defaults to current user)
Returns: Created playlist details including Spotify URI and ID.
Update playlist metadata including name, description, privacy settings, and collaborative status.
Parameters:
playlistId(required): Spotify playlist IDname(optional): New playlist namedescription(optional): New playlist descriptionpublic(optional): New public/private settingcollaborative(optional): New collaborative setting
Returns: Updated playlist details with change summary.
Add tracks to a playlist with precise position control.
Parameters:
playlistId(required): Spotify playlist IDuris(required): Array of Spotify track URIs (max 100)position(optional): Position to insert tracks (defaults to end)
Returns: Confirmation with snapshot ID and updated track count.
Remove tracks from a playlist with precision control.
Parameters:
playlistId(required): Spotify playlist IDtracks(required): Array of track objects with URIs and optional positionssnapshot_id(optional): Playlist snapshot ID for concurrency safety
Returns: Confirmation with snapshot ID and removal details.
Reorder tracks within a playlist by moving a range of tracks to a new position.
Parameters:
playlistId(required): Spotify playlist IDrange_start(required): Starting position of tracks to moverange_length(required): Number of tracks to moveinsert_before(required): Position to move tracks tosnapshot_id(optional): Playlist snapshot ID for concurrency safety
Returns: Confirmation with snapshot ID and reorder details.
Search Spotify's catalog for albums, artists, tracks, playlists, shows, and episodes.
Parameters:
query(required): Search query stringtype(optional): Content type filter (track, album, artist, playlist, show, episode)limit(optional): Number of results (1-50, default: 20)offset(optional): Result offset (default: 0)market(optional): Country code for market-specific results
Returns: Detailed metadata for each result type with pagination information.
Get new album releases available on Spotify.
Parameters:
limit(optional): Number of releases (1-50, default: 20)offset(optional): Result offset (default: 0)country(optional): Country code for regional releases
Returns: Recently released albums with artist information, release dates, and metadata.
Get featured playlists from Spotify's editorial team.
Parameters:
limit(optional): Number of playlists (1-50, default: 20)offset(optional): Result offset (default: 0)country(optional): Country code for regional contentlocale(optional): Language/locale for descriptions
Returns: Curated playlists prominently featured on Spotify with descriptions and metadata.
Get the current user's top artists or tracks based on calculated affinity.
Parameters:
type(required): Item type ('artists' or 'tracks')time_range(optional): Time range ('short_term' ~4 weeks, 'medium_term' ~6 months, 'long_term' ~1 year)limit(optional): Number of items (1-50, default: 20)offset(optional): Result offset (default: 0)
Returns: User's top items with popularity scores and metadata.
Note: These tools require a Spotify Premium account
Get current playing track and device information.
Returns: Current playback state including track, device, and queue information.
Control playback (play, pause, skip, volume).
Parameters:
action(required): Playback action (play, pause, next, previous, volume)device_id(optional): Target device IDvolume_percent(optional): Volume level (0-100, for volume action)
Returns: Confirmation of playback action.
Add tracks to queue and view upcoming tracks.
Parameters:
action(required): Queue action ('add' or 'get')uris(optional): Track URIs to add (for 'add' action)device_id(optional): Target device ID
Returns: Queue information or confirmation of track addition.
Transfer playback between devices.
Parameters:
device_id(required): Target device IDplay(optional): Whether to start playback on transfer (default: false)
Returns: Confirmation of device transfer.
Retrieve audio features for tracks.
Parameters:
track_ids(required): Array of Spotify track IDs
Returns: Audio features including:
- Danceability: How suitable for dancing (0.0-1.0)
- Energy: Intensity and power (0.0-1.0)
- Speechiness: Presence of spoken words (0.0-1.0)
- Acousticness: Whether track is acoustic (0.0-1.0)
- Instrumentalness: Whether track has no vocals (0.0-1.0)
- Liveness: Presence of audience (0.0-1.0)
- Valence: Musical positivity/happiness (0.0-1.0)
- Tempo: Speed in beats per minute (BPM)
| Variable | Description | Required |
|---|---|---|
| SPOTIFY_CLIENT_ID | Spotify client ID | β |
| SPOTIFY_CLIENT_SECRET | Spotify client secret | β |
| SPOTIFY_REDIRECT_URI | Spotify redirect URI (use http://127.0.0.1:8000/callback) | β |
| SPOTIFY_API_TOKEN | Spotify access token (obtained via OAuth) | β* |
| SPOTIFY_REFRESH_TOKEN | Spotify refresh token (obtained via OAuth) | β* |
| MAX_TOOL_TOKEN_OUTPUT | Max token output for tool responses (default 50000) | β |
*These tokens are automatically obtained through the OAuth flow when you first use the server.
- developer: Full access to all tools and features
- editor: Restricted to content-focused tools (no admin features)
Set the role in your MCP client configuration if supported.
If you use a Node version manager (nvm, mise, fnm, etc.), you may need to create symlinks so MCP servers can access Node.js:
sudo ln -sf "$(which node)" /usr/local/bin/node && sudo ln -sf "$(which npx)" /usr/local/bin/npxUpdate these symlinks if you change Node versions. Remove them with:
sudo rm /usr/local/bin/node /usr/local/bin/npxInstall dependencies:
npm installBuild and run in development mode:
npm run devBuild the server:
npm run buildRun the built server:
npm startYou can use the MCP inspector for debugging:
npx @modelcontextprotocol/inspector -e SPOTIFY_CLIENT_ID=... -e SPOTIFY_CLIENT_SECRET=... -e SPOTIFY_REDIRECT_URI=... -e SPOTIFY_API_TOKEN=... -e SPOTIFY_REFRESH_TOKEN=... node path/to/build/index.jsThis provides a web interface for inspecting and testing the available tools.
The OAuth flow has been improved with the following security and usability enhancements:
- State validation: Uses cryptographically secure random state parameters to prevent CSRF attacks
- Redirect URI validation: Ensures redirect URI uses localhost/127.0.0.1 for automatic token exchange
- Proper error handling: Comprehensive error handling for all OAuth failure scenarios
- Automatic browser opening: Automatically opens the authorization URL in your default browser
- Better user feedback: Clear error messages and status updates throughout the process
- Graceful server shutdown: Properly closes the OAuth callback server after completion
The oauth-helper.js script provides a standalone way to obtain Spotify tokens:
node src/utils/oauth-helper.jsThis will:
- Validate your environment configuration
- Start a local callback server
- Automatically open your browser to the Spotify authorization page
- Handle the callback and exchange the code for tokens
- Display the tokens for you to add to your
.envfile
Make sure your redirect URI is configured correctly:
SPOTIFY_REDIRECT_URI=http://127.0.0.1:8000/callbackThe redirect URI must use localhost or 127.0.0.1 for the automatic token exchange to work properly.
MIT