spotify-mcp

tianyoul/spotify-mcp

3.2

If you are the rightful owner of spotify-mcp and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

A Model Context Protocol (MCP) server that enables Claude Desktop to interact with Spotify, allowing users to manage their Spotify library using natural language.

Tools
5
Resources
0
Prompts
0

Spotify MCP Server

A Model Context Protocol (MCP) server that enables Claude Desktop to interact with Spotify. Create playlists, search for tracks, and manage your Spotify library using natural language.

Features

  • Search Tracks: Find songs by artist, album, genre, or natural language queries
  • Create Playlists: Generate new playlists with custom names and descriptions
  • Add Tracks: Add multiple tracks to playlists at once
  • View Playlists: List your existing Spotify playlists
  • Get Recommendations: Discover new music based on seeds (tracks, artists, or genres)

Prerequisites

  • Node.js (v18 or higher)
  • A Spotify account
  • Claude Desktop app
  • Spotify Developer App credentials

Setup Instructions

1. Clone the Repository

git clone https://github.com/tianyoul/spotify-mcp.git
cd spotify-mcp

2. Install Dependencies

npm install

3. Create Spotify App

  1. Go to Spotify Developer Dashboard
  2. Click "Create app"
  3. Fill in the details:
    • App name: Spotify MCP Server (or any name)
    • App description: MCP server for Claude Desktop
    • Redirect URI: http://127.0.0.1:8888/callback
  4. Save your app
  5. Copy your Client ID and Client Secret

4. Configure Environment Variables

Create a .env file in the project root:

SPOTIFY_CLIENT_ID=your_client_id_here
SPOTIFY_CLIENT_SECRET=your_client_secret_here
SPOTIFY_REDIRECT_URI=http://127.0.0.1:8888/callback

Replace your_client_id_here and your_client_secret_here with your actual Spotify credentials.

5. Build the Project

npm run build

6. Authenticate with Spotify

npm run auth

This will:

  • Open a browser window for Spotify authentication
  • Request necessary permissions
  • Save your access token locally

7. Configure Claude Desktop

Add the following to your Claude Desktop configuration file:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json

Windows: %APPDATA%\Claude\claude_desktop_config.json

Linux: ~/.config/Claude/claude_desktop_config.json

{
  "mcpServers": {
    "spotify": {
      "command": "node",
      "args": ["/ABSOLUTE/PATH/TO/spotify-mcp/dist/index.js"],
      "env": {
        "SPOTIFY_CLIENT_ID": "your_client_id_here",
        "SPOTIFY_CLIENT_SECRET": "your_client_secret_here",
        "SPOTIFY_REDIRECT_URI": "http://127.0.0.1:8888/callback"
      }
    }
  }
}

Important: Replace /ABSOLUTE/PATH/TO/spotify-mcp with the actual absolute path to your project directory.

8. Restart Claude Desktop

Close and reopen Claude Desktop. The Spotify MCP server should now be connected.

Usage Examples

Once configured, you can interact with Spotify through Claude using natural language:

Search for music:

"Find me some chill jazz music"

Create a playlist:

"Create a playlist called 'Road Trip' with upbeat rock songs"

Add tracks to a playlist:

"Search for Taylor Swift songs and add the top 5 to my Road Trip playlist"

View your playlists:

"Show me my Spotify playlists"

Get recommendations:

"Recommend songs similar to Bohemian Rhapsody"

Available Tools

The MCP server exposes the following tools to Claude:

  • search_tracks - Search for tracks on Spotify
  • create_playlist - Create a new playlist in your account
  • add_tracks_to_playlist - Add tracks to an existing playlist
  • get_user_playlists - List your playlists
  • get_recommendations - Get track recommendations based on seeds

Troubleshooting

Server disconnected error

If you see "Server disconnected" in Claude Desktop:

  1. Check the logs: ~/Library/Logs/Claude/mcp-server-spotify.log (macOS)
  2. Ensure the build completed successfully: npm run build
  3. Verify authentication: npm run auth
  4. Check that the path in claude_desktop_config.json is absolute and correct

Token expired

If you get a "Token expired" error:

npm run auth

This will refresh your Spotify authentication.

Cannot find module errors

Make sure all dependencies are installed:

npm install
npm run build

Development

Project Structure

spotify-mcp/
ā”œā”€ā”€ src/
│   ā”œā”€ā”€ index.ts      # Main MCP server implementation
│   └── auth.ts       # Spotify OAuth flow
ā”œā”€ā”€ dist/             # Compiled JavaScript (generated)
ā”œā”€ā”€ .env              # Environment variables (create this)
ā”œā”€ā”€ package.json
└── tsconfig.json

Scripts

  • npm run build - Compile TypeScript to JavaScript
  • npm run dev - Run in development mode
  • npm run auth - Authenticate with Spotify
  • npm start - Start the server (for testing)

Security Notes

  • Never commit your .env file or .spotify-token.json to version control
  • Keep your Spotify Client Secret private
  • The authentication token is stored locally in .spotify-token.json
  • Tokens are automatically refreshed when needed

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Links