Production-ready Model Context Protocol (MCP) server for Spotify with bulletproof error handling and token management.
- 🔐 One-time OAuth authentication - Authenticate once, use forever (like spotifyd)
- 🛡️ Bulletproof error handling - Never invalidates tokens on transient failures
- 🔄 Automatic token refresh - Seamless refresh with concurrent request deduplication
- 💾 Atomic credential storage - Prevents corruption on process crash
- ⚡ Smart retry logic - Exponential backoff with rate limit handling
- 🎯 Conservative token management - Only clears credentials when provably invalid
Once set up, you can control Spotify using natural language prompts with Claude:
"Search for AC/DC songs"
"Find albums by The Beatles"
"Search for rock playlists"
"Find tech podcasts"
"Search for The Beatles - show me tracks, albums, and playlists"
"Play Back in Black by AC/DC"
"Play the album Highway to Hell"
"Play my Discover Weekly playlist"
"Pause the music"
"Skip to the next song"
"Go back to the previous track"
"What's currently playing?"
"Set volume to 50%"
"Turn on shuffle"
"Enable repeat"
"Set repeat to one song only"
"Turn off repeat"
"Show my Spotify devices"
"Switch playback to my phone"
"Transfer playback to my speaker"
All these operations work seamlessly with automatic token refresh, rate limiting, and error recovery.
You need to set up a Spotify developer app to get a client id and secret. This will be used to authenticate the MCP server.
Install via Claude CLI and let Claude guide you through setup:
# Install the MCP server
claude mcp add --transport stdio spotify -- npx -y @tbrgeek/spotify-mcp-server
# Restart Claude Code
# (Fully quit and reopen)The server starts without credentials and provides setup instructions when you need them. Simply ask Claude:
- "Authenticate the spotify mcp server"
Claude will provide step-by-step setup instructions including:
- Creating a Spotify app
- Running the authentication script
- Configuring credentials
See Prompt-Based Setup Guide below for details.
For persistent credentials that survive restarts:
# Install globally
npm install -g @tbrgeek/spotify-mcp-server
# Run authentication
spotify-mcp-server auth
# Add to Claude Code config
claude mcp add --transport stdio spotify -- spotify-mcp-serverSee Claude CLI Setup Guide for complete instructions.
For shared configurations or CI/CD:
# Set environment variables (see docs/CLAUDE_CLI_SETUP.md)
export SPOTIFY_CLIENT_ID="your_client_id"
export SPOTIFY_CLIENT_SECRET="your_client_secret"
export SPOTIFY_REFRESH_TOKEN="your_refresh_token"
export SPOTIFY_ACCESS_TOKEN="your_access_token"
# Install with environment variables
claude mcp add --transport stdio spotify -- npx -y @tbrgeek/spotify-mcp-serverSee Claude CLI Setup Guide for full environment variable setup.
git clone https://github.com/thebigredgeek/spotify-mcp-server.git
cd spotify-mcp-server
npm install
npm run build
npm link- Go to Spotify Developer Dashboard
- Create a new app
- Note your Client ID and Client Secret
- Add redirect URI:
http://127.0.0.1:8888/callback
npm run authFollow the prompts to:
- Enter your Client ID and Client Secret
- Authorize in your browser
- Credentials are saved to
~/.spotify-mcp/credentials.json
Edit ~/.claude/settings.local.json:
{
"mcpServers": {
"spotify": {
"type": "stdio",
"command": "spotify-mcp-server"
}
}
}Or use environment variables (see Claude CLI Setup Guide):
{
"mcpServers": {
"spotify": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@tbrgeek/spotify-mcp-server"],
"env": {
"SPOTIFY_CLIENT_ID": "${SPOTIFY_CLIENT_ID}",
"SPOTIFY_CLIENT_SECRET": "${SPOTIFY_CLIENT_SECRET}",
"SPOTIFY_ACCESS_TOKEN": "${SPOTIFY_ACCESS_TOKEN}",
"SPOTIFY_REFRESH_TOKEN": "${SPOTIFY_REFRESH_TOKEN}"
}
}
}
}Add to ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"spotify": {
"command": "npx",
"args": ["-y", "@tbrgeek/spotify-mcp-server"]
}
}
}{
"mcpServers": {
"spotify": {
"command": "node",
"args": ["/Users/YOUR_USERNAME/opensource/spotify-mcp-server/dist/index.js"]
}
}
}The easiest way to set up the Spotify MCP server is to install it first, then let Claude guide you through authentication.
# Install via Claude CLI
claude mcp add --transport stdio spotify -- npx -y @tbrgeek/spotify-mcp-server
# Restart Claude Code (fully quit and reopen)After restarting, ask Claude any of these questions:
- "How do I set up Spotify?"
- "Check Spotify health"
- "Get Spotify authentication status"
Claude will respond with detailed setup instructions, including:
Creating a Spotify App:
- Go to https://developer.spotify.com/dashboard
- Click "Create app"
- Fill in app name and redirect URI:
http://127.0.0.1:8888/callback - Save your Client ID and Client Secret
Running Authentication:
# Install globally
npm install -g @tbrgeek/spotify-mcp-server
# Run authentication
spotify-mcp-server authThe auth script will:
- Prompt for your Client ID and Secret
- Open your browser for authorization
- Save credentials to
~/.spotify-mcp/credentials.json
Restart Claude Code - credentials are now loaded automatically!
Ask Claude: "Check Spotify health"
You should see: ✅ Spotify MCP Server is authenticated and operational!
If you prefer to edit configuration files directly, here's how:
-
Run authentication to generate credentials:
npm install -g @tbrgeek/spotify-mcp-server spotify-mcp-server auth
-
Edit Claude Code config at
~/.claude/settings.local.json:{ "mcpServers": { "spotify": { "type": "stdio", "command": "spotify-mcp-server" } } } -
Restart Claude Code - credentials are loaded from
~/.spotify-mcp/credentials.json
-
Get your credentials (run authentication once to obtain refresh token):
spotify-mcp-server auth cat ~/.spotify-mcp/credentials.json -
Set environment variables in your shell profile (
~/.zshrcor~/.bashrc):export SPOTIFY_CLIENT_ID="your_client_id_here" export SPOTIFY_CLIENT_SECRET="your_client_secret_here" export SPOTIFY_ACCESS_TOKEN="your_access_token_here" export SPOTIFY_REFRESH_TOKEN="your_refresh_token_here"
-
Edit Claude Code config at
~/.claude/settings.local.json:{ "mcpServers": { "spotify": { "type": "stdio", "command": "npx", "args": ["-y", "@tbrgeek/spotify-mcp-server"], "env": { "SPOTIFY_CLIENT_ID": "${SPOTIFY_CLIENT_ID}", "SPOTIFY_CLIENT_SECRET": "${SPOTIFY_CLIENT_SECRET}", "SPOTIFY_ACCESS_TOKEN": "${SPOTIFY_ACCESS_TOKEN}", "SPOTIFY_REFRESH_TOKEN": "${SPOTIFY_REFRESH_TOKEN}" } } } } -
Reload your shell and restart Claude Code:
source ~/.zshrc # or ~/.bashrc
Claude Code Config:
~/.claude/settings.local.json # User-specific (not version-controlled)
~/.claude/settings.json # Global defaultsSpotify Credentials:
~/.spotify-mcp/credentials.json # Stored credentials (from auth script)Editing Config:
# macOS/Linux
code ~/.claude/settings.local.json
# or
vim ~/.claude/settings.local.jsonAfter editing any config:
- Fully quit Claude Code (not just close window)
- Reopen Claude Code to load new configuration
The server implements a sophisticated error classification system that never invalidates tokens unless absolutely necessary:
- ✅ Never clears tokens for: 500/502/503, 429 (rate limit), network errors, timeouts
- ✅ Retries transient errors: 403 errors (Spotify bug), network failures
- ✅ Only clears tokens when: Refresh token returns
invalid_grant
- Concurrent refresh deduplication: Multiple simultaneous API calls trigger only one token refresh
- Refresh token preservation: Keeps existing refresh token if new one not returned (Spotify behavior)
- 5-minute expiry buffer: Refreshes tokens before they expire
- Atomic writes: Credentials written to temp file, then atomically renamed
- Exponential backoff: 1s → 2s → 4s delays (configurable)
- Rate limit handling: Respects
Retry-Afterheaders - Smart retries: Up to 3 attempts for transient failures
See DEVELOPMENT.md for local testing, debugging, and publishing workflows.
npm run buildnpm testnpm run lintCurrent Version: Fully functional Spotify control with comprehensive search and playback capabilities
✅ Implemented Features:
- Core infrastructure with bulletproof error handling and token management
- Comprehensive search (tracks, albums, playlists, podcasts)
- Full playback control (play, pause, next, previous, volume)
- Advanced playback features (shuffle, repeat modes, device management)
- Multi-device support with transfer capabilities
- Real-time playback state monitoring
🚀 Future Enhancements:
- User library management (saved tracks, albums, playlists)
- Playlist creation and editing
- Recently played tracks
- User top tracks and artists
MIT - see LICENSE
Andrew Rhyne andrew.rhyne@shopify.com