🎧 Spotify MCP Server

April 5, 2025 Β· View on GitHub

This is an MCP (Model Context Protocol) server that connects to the Spotify Web API and exposes a set of playback and search tools to AI clients like Claude Desktop.

Built using:

  • spotipy β€” lightweight Python wrapper for the Spotify Web API
  • mcp β€” for exposing tool functions over the Model Context Protocol
  • FastMCP β€” for rapid server implementation
  • .env and dotenv β€” for securely managing credentials

πŸš€ Features

This server exposes the following Spotify tools:

  • play β€” Start or resume playback
  • pause β€” Pause playback
  • next_track β€” Skip to the next song
  • previous_track β€” Go back to the previous song
  • search_track(query: str) β€” Search for a track by name
  • get_current_track() β€” Get info on the currently playing song
  • add_to_queue(uri: str) β€” Add a track to the queue using its Spotify URI

πŸ”§ Setup

1. Clone the Repo

git clone https://github.com/your-username/spotify_mcp.git
cd spotify_mcp

2. Create a virtual environment

Using uv (recommended):

uv venv
source .venv/bin/activate
uv pip install spotipy mcp[cli] python-dotenv

Or using standard venv and pip:

python3 -m venv venv
source venv/bin/activate
pip install spotipy mcp[cli] python-dotenv

3. Set up environment variables

Create a .env file in the root of your project:

SPOTIPY_CLIENT_ID=your_spotify_client_id
SPOTIPY_CLIENT_SECRET=your_spotify_client_secret
SPOTIPY_REDIRECT_URI=http://localhost:8888/callback

πŸ§ͺ Running the server

python main.py

πŸ€– Using with Claude Desktop

  1. Open your claude_desktop_config.json
  2. Add an MCP server entry like this:
{
  "mcpServers": {
    "spotify_mcp": {
      "command": "/absolute/path/to/venv/bin/python",
      "args": ["/absolute/path/to/main.py"]
    }
  }
}
  1. Restart Claude Desktop.
  2. You should now see β€œSpotify” as a tool in your Claude interface.