MCP HubMCP Hub
marcelmarais

spotify-mcp-server

by: marcelmarais

spotify mcp server

44created 19/03/2025
Visit
spotify
music

📌Overview

Purpose: To provide a lightweight Model Context Protocol (MCP) server that allows AI assistants like Cursor and Claude to control Spotify playback and manage playlists efficiently.

Overview: The Spotify MCP Server facilitates seamless integration between AI applications and Spotify, enabling users to control music playback and organize playlists through intuitive commands. This server acts as a bridge, allowing various interactions with Spotify’s features using the MCP framework.

Key Features:

  • Search Operations: Users can search for tracks, albums, artists, or playlists directly in Spotify using commands like searchSpotify, which returns detailed information based on specified parameters.

  • Playback Control: Commands such as playMusic, pausePlayback, and skipToNext allow for real-time control of music playback, enabling a smooth user experience tailored to personal preferences.

  • Playlist Management: Users can manage their Spotify playlists efficiently with features like createPlaylist for creating new playlists and addTracksToPlaylist for adding songs to existing playlists.

  • Current Playback Information: The getNowPlaying command provides users with information about the currently playing track, enhancing situational awareness during playback.

  • User-Friendly Setup: The server is easy to set up with clear installation instructions, prerequisites, and configuration steps to connect with Spotify's API, making it accessible to developers.


Spotify MCP Server

A lightweight Model Context Protocol (MCP) server that enables AI assistants like Cursor and Claude to control Spotify playback and manage playlists.

Contents

Example Interactions

  • "Play Elvis's first song"
  • "Create a Taylor Swift / Slipknot fusion playlist"
  • "Copy all the techno tracks from my workout playlist to my work playlist"

Tools

Read Operations

  1. searchSpotify

    • Description: Search for tracks, albums, artists, or playlists on Spotify
    • Parameters:
      • query (string): The search term
      • type (string): Type of item to search for (track, album, artist, playlist)
      • limit (number, optional): Maximum number of results to return (10-50)
    • Example: searchSpotify("bohemian rhapsody", "track", 20)
  2. getNowPlaying

    • Description: Get information about the currently playing track on Spotify
    • Returns: Object containing track details
    • Example: getNowPlaying()
  3. getMyPlaylists

    • Description: Get a list of the current user's playlists on Spotify
    • Parameters:
      • limit (number, optional): Maximum number of playlists to return (default: 20)
      • offset (number, optional): Index of the first playlist to return (default: 0)
    • Example: getMyPlaylists(10, 0)
  4. getPlaylistTracks

    • Description: Get a list of tracks in a specific Spotify playlist
    • Parameters:
      • playlistId (string): The Spotify ID of the playlist
      • limit (number, optional): Maximum number of tracks to return (default: 100)
    • Example: getPlaylistTracks("37i9dQZEVXcJZyENOWUFo7")

Play / Create Operations

  1. playMusic

    • Description: Start playing a track, album, artist, or playlist on Spotify
    • Parameters:
      • uri (string, optional): Spotify URI of the item to play
    • Example: playMusic({ uri: "spotify:track:6rqhFgbbKwnb9MLmUQDhG6" })
  2. pausePlayback

    • Description: Pause the currently playing track on Spotify
    • Example: pausePlayback()
  3. skipToNext

    • Description: Skip to the next track in the current playback queue
    • Example: skipToNext()
  4. skipToPrevious

    • Description: Skip to the previous track in the current playback queue
    • Example: skipToPrevious()
  5. createPlaylist

    • Description: Create a new playlist on Spotify
    • Parameters:
      • name (string): Name for the new playlist
    • Example: createPlaylist({ name: "Workout Mix" })
  6. addTracksToPlaylist

    • Description: Add tracks to an existing Spotify playlist
    • Parameters:
      • playlistId (string): ID of the playlist
      • trackUris (array): Array of track URIs or IDs to add
    • Example: addTracksToPlaylist({ playlistId: "3cEYpjA9oz9GiPac4AsH4n", trackUris: ["spotify:track:4iV5W9uYEdYUVa79Axb7Rh"] })

Setup

Prerequisites

  • Node.js v16+
  • A Spotify Premium account
  • A registered Spotify Developer application

Installation

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

Creating a Spotify Developer Application

  1. Go to the Spotify Developer Dashboard
  2. Log in and create a new app.
  3. Note your Client ID and Client Secret.
  4. Add a Redirect URI (e.g., http://localhost:8888/callback).

Spotify API Configuration

Create a spotify-config.json file in the project root:

cp spotify-config.example.json spotify-config.json

Edit the file with your credentials:

{
  "clientId": "your-client-id",
  "clientSecret": "your-client-secret",
  "redirectUri": "http://localhost:8888/callback"
}

Authentication Process

  1. Run the authentication script:
npm run auth
  1. Follow the on-screen instructions to authorize your application.

Integrating with Claude Desktop and Cursor

To integrate with Claude, add your MCP server to the configuration:

{
  "mcpServers": {
    "spotify": {
      "command": "node",
      "args": ["spotify-mcp-server/build/index.js"]
    }
  }
}

For Cursor, use the command:

node path/to/spotify-mcp-server/build/index.js