spotify-mcp-server

spotify-mcp-server

Enables natural language control of Spotify, including search, playback, and device management, with robust error handling and automatic token refresh.

Category
访问服务器

README

Spotify MCP Server

Production-ready Model Context Protocol (MCP) server for Spotify with bulletproof error handling and token management.

Features

  • 🔐 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

Example Usage

Once set up, you can control Spotify using natural language prompts with Claude:

🎵 Search & Discovery

"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"

▶️ Playback Control

"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?"

🎚️ Advanced Controls

"Set volume to 50%"
"Turn on shuffle"
"Enable repeat"
"Set repeat to one song only"
"Turn off repeat"

📱 Device Management

"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.

Installation

BEFORE:

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.

Method 1: Prompt-Based Setup (Easiest)

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:

  1. Creating a Spotify app
  2. Running the authentication script
  3. Configuring credentials

See Prompt-Based Setup Guide below for details.

Method 2: Interactive Authentication (Stored Credentials)

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-server

See Claude CLI Setup Guide for complete instructions.

Method 3: Environment Variables (Advanced)

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-server

See Claude CLI Setup Guide for full environment variable setup.

Local Development

git clone https://github.com/thebigredgeek/spotify-mcp-server.git
cd spotify-mcp-server
npm install
npm run build
npm link

Setup

1. Create Spotify App

  1. Go to Spotify Developer Dashboard
  2. Create a new app
  3. Note your Client ID and Client Secret
  4. Add redirect URI: http://127.0.0.1:8888/callback

2. Authenticate

npm run auth

Follow the prompts to:

  • Enter your Client ID and Client Secret
  • Authorize in your browser
  • Credentials are saved to ~/.spotify-mcp/credentials.json

3. Configure MCP Client

Claude CLI / Claude Code (Recommended)

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}"
      }
    }
  }
}

Claude Desktop

Add to ~/Library/Application Support/Claude/claude_desktop_config.json:

{
  "mcpServers": {
    "spotify": {
      "command": "npx",
      "args": ["-y", "@tbrgeek/spotify-mcp-server"]
    }
  }
}

For local development:

{
  "mcpServers": {
    "spotify": {
      "command": "node",
      "args": ["/Users/YOUR_USERNAME/opensource/spotify-mcp-server/dist/index.js"]
    }
  }
}

Prompt-Based Setup Guide

The easiest way to set up the Spotify MCP server is to install it first, then let Claude guide you through authentication.

Step 1: Install the Server

# Install via Claude CLI
claude mcp add --transport stdio spotify -- npx -y @tbrgeek/spotify-mcp-server

# Restart Claude Code (fully quit and reopen)

Step 2: Ask Claude for Setup Instructions

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:

  1. Go to https://developer.spotify.com/dashboard
  2. Click "Create app"
  3. Fill in app name and redirect URI: http://127.0.0.1:8888/callback
  4. Save your Client ID and Client Secret

Running Authentication:

# Install globally
npm install -g @tbrgeek/spotify-mcp-server

# Run authentication
spotify-mcp-server auth

The 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!

Step 3: Verify

Ask Claude: "Check Spotify health"

You should see: ✅ Spotify MCP Server is authenticated and operational!

Manual Configuration

If you prefer to edit configuration files directly, here's how:

Option 1: Using Stored Credentials

  1. Run authentication to generate credentials:

    npm install -g @tbrgeek/spotify-mcp-server
    spotify-mcp-server auth
    
  2. Edit Claude Code config at ~/.claude/settings.local.json:

    {
      "mcpServers": {
        "spotify": {
          "type": "stdio",
          "command": "spotify-mcp-server"
        }
      }
    }
    
  3. Restart Claude Code - credentials are loaded from ~/.spotify-mcp/credentials.json

Option 2: Using Environment Variables

  1. Get your credentials (run authentication once to obtain refresh token):

    spotify-mcp-server auth
    cat ~/.spotify-mcp/credentials.json
    
  2. Set environment variables in your shell profile (~/.zshrc or ~/.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"
    
  3. 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}"
          }
        }
      }
    }
    
  4. Reload your shell and restart Claude Code:

    source ~/.zshrc  # or ~/.bashrc
    

Locating Config Files

Claude Code Config:

~/.claude/settings.local.json  # User-specific (not version-controlled)
~/.claude/settings.json         # Global defaults

Spotify Credentials:

~/.spotify-mcp/credentials.json  # Stored credentials (from auth script)

Editing Config:

# macOS/Linux
code ~/.claude/settings.local.json
# or
vim ~/.claude/settings.local.json

After editing any config:

  • Fully quit Claude Code (not just close window)
  • Reopen Claude Code to load new configuration

Architecture Highlights

Error Handling

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

Token Management

  • 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

Retry Logic

  • Exponential backoff: 1s → 2s → 4s delays (configurable)
  • Rate limit handling: Respects Retry-After headers
  • Smart retries: Up to 3 attempts for transient failures

Development

See DEVELOPMENT.md for local testing, debugging, and publishing workflows.

Build

npm run build

Test

npm test

Lint

npm run lint

Project Status

Current 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

License

MIT - see LICENSE

Author

Andrew Rhyne andrew.rhyne@shopify.com

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选