mcp claude spotify
An integration that allows Claude Desktop to interact with Spotify, enabling users to control playback, search music, manage playlists, and get recommendations through natural language commands.
An integration that allows Claude Desktop to interact with Spotify, enabling users to control playback, search music, manage playlists, and get recommendations through natural language commands.
An integration that allows Claude Desktop to interact with Spotify using the Model Context Protocol (MCP). |
Clone or download this repository:
git clone https://github.com/imprvhub/mcp-claude-spotify
cd claude-spotify-mcp
Install dependencies:
npm install
Build the project (if you want to modify the source code):
npm run build
The repository already includes pre-built files in the build
directory, so you can skip step 3 if you don't plan to modify the source code.
To use this MCP, you need to obtain Spotify API credentials:
http://127.0.0.1:8888/callback
Save these credentials as you'll need them for configuration.
There are two ways to run the MCP server:
node build/index.js
Keep this terminal window open while using Claude Desktop. The server will run until you close the terminal.
The Claude Desktop can automatically start the MCP server when needed. To set this up:
The Claude Desktop configuration file is located at:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%Claudeclaude_desktop_config.json
Edit this file to add the Spotify MCP configuration. If the file doesn't exist, create it:
{
"mcpServers": {
"spotify": {
"command": "node",
"args": ["ABSOLUTE_PATH_TO_DIRECTORY/mcp-claude-spotify/build/index.js"],
"env": {
"SPOTIFY_CLIENT_ID": "your_client_id_here",
"SPOTIFY_CLIENT_SECRET": "your_client_secret_here"
}
}
}
}
Important: Replace:
- ABSOLUTE_PATH_TO_DIRECTORY
with the complete absolute path where you installed the MCP
- macOS/Linux example: /Users/username/mcp-claude-spotify
- Windows example: C:Usersusernamemcp-claude-spotify
- your_client_id_here
with the Client ID you obtained from Spotify
- your_client_secret_here
with the Client Secret you obtained from Spotify
If you already have other MCPs configured, simply add the "spotify" section inside the "mcpServers" object.
For a more reliable experience, you can set up auto-start scripts:
@echo off
cd %~dp0
node build/index.js
2. Create a shortcut to this BAT file
3. Press `Win+R`, type `shell:startup` and press Enter
4. Move the shortcut to this folder to have it start with Windows
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.spotify.mcp</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/node</string>
<string>ABSOLUTE_PATH_TO_DIRECTORY/mcp-claude-spotify/build/index.js</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardErrorPath</key>
<string>/tmp/spotify-mcp.err</string>
<key>StandardOutPath</key>
<string>/tmp/spotify-mcp.out</string>
<key>EnvironmentVariables</key>
<dict>
<key>SPOTIFY_CLIENT_ID</key>
<string>your_client_id_here</string>
<key>SPOTIFY_CLIENT_SECRET</key>
<string>your_client_secret_here</string>
</dict>
</dict>
</plist>
2. Replace the path and credentials with your actual values
3. Load the agent with: `launchctl load ~/Library/LaunchAgents/com.spotify.mcp.plist`
[Unit]
Description=Spotify MCP Server for Claude Desktop
After=network.target
[Service]
Type=simple
ExecStart=/usr/bin/node ABSOLUTE_PATH_TO_DIRECTORY/mcp-claude-spotify/build/index.js
Restart=on-failure
Environment="SPOTIFY_CLIENT_ID=your_client_id_here"
Environment="SPOTIFY_CLIENT_SECRET=your_client_secret_here"
[Install]
WantedBy=default.target
2. Replace the path and credentials with your actual values
3. Enable and start the service:
systemctl --user enable spotify-mcp.service
systemctl --user start spotify-mcp.service
4. Check status with:
systemctl --user status spotify-mcp.service
auth-spotify
command to start the authentication processThe MCP server runs as a child process managed by Claude Desktop. When Claude is running, it automatically starts and manages the Node.js server process based on the configuration in claude_desktop_config.json
.
Initiates the Spotify authentication process.
Searches for tracks, albums, artists, or playlists.
Parameters:
- query
: Search text
- type
: Type of search (track, album, artist, playlist)
- limit
: Number of results (1-50)
Plays a specific track.
Parameters:
- trackId
: Spotify track ID
- deviceId
: (Optional) Spotify device ID to play on
Gets information about the current playback.
Pauses the playback.
Skips to the next track.
Returns to the previous track.
Gets the user's playlists.
Creates a new playlist.
Parameters:
- name
: Playlist name
- description
: (Optional) Description
- public
: (Optional) Whether it's public or private
Adds tracks to a playlist.
Parameters:
- playlistId
: Playlist ID
- trackIds
: Array of track IDs
Gets recommendations based on seeds.
Parameters:
- seedTracks
: (Optional) Array of track IDs
- seedArtists
: (Optional) Array of artist IDs
- seedGenres
: (Optional) Array of genres
- limit
: (Optional) Number of recommendations (1-100)
Gets the user's most played tracks over a specified time range.
Parameters:
- limit
: (Optional) Number of tracks to return (1-50, default: 20)
- offset
: (Optional) Index of the first track to return (default: 0)
- time_range
: (Optional) Time frame for calculating affinity:
- short_term
: Approximately last 4 weeks
- medium_term
: Approximately last 6 months (default)
- long_term
: Several years of data
If you see the error "MCP Spotify: Server disconnected" in Claude Desktop:
node build/index.js
from the project directoryIf the server starts successfully, use Claude while keeping this terminal open
Check your configuration:
claude_desktop_config.json
is correct for your system
) for Windows pathsVerify you're using the complete path from the root of your filesystem
Try the auto-start option:
If the browser doesn't open automatically during authentication, manually visit:
http://127.0.0.1:8888/login
Make sure you've correctly configured the redirect URI in your Spotify Developer dashboard:
http://127.0.0.1:8888/callback
Verify that:
- Environment variables are correctly configured in your claude_desktop_config.json
or launch script
- Node.js is installed and compatible (v16+)
- Required ports (8888) are available and not blocked by firewall
- You have permission to run the script in the specified location
If the Spotify tools don't appear in Claude after authentication: - Make sure you've restarted Claude Desktop after successful authentication - Check the Claude Desktop logs for any MCP communication errors - Ensure the MCP server process is running (run it manually to confirm) - Verify that the MCP server is correctly registered in the Claude Desktop MCP registry
To check if the server is running:
ps aux | grep node
If you don't see the server running, start it manually or use the auto-start method.
This project includes automated tests to ensure code quality and functionality. The test suite uses Jest with TypeScript support and covers:
First, make sure all development dependencies are installed:
npm install
To run all tests:
npm test
To run a specific test file:
npm test -- --testMatch="**/tests/schemas.test.ts"
If you encounter issues with ESM modules, make sure you're using Node.js v16 or higher and that the NODE_OPTIONS environment variable includes the --experimental-vm-modules
flag as configured in the package.json.
tests/schemas.test.ts
: Tests for input validation schemastests/spotify-api.test.ts
: Tests for Spotify API interactionstests/server.test.ts
: Tests for MCP server functionalityWhen adding new functionality, please include corresponding tests:
schemas.test.ts
spotify-api.test.ts
server.test.ts
All tests should be written using Jest and the ESM module format with TypeScript.
~/.spotify-mcp/tokens.json
to enable persistence between sessions and multiple instancesFor security reasons, you may want to revoke the application's access to your Spotify account when: - You no longer use this integration - You suspect unauthorized access - You're troubleshooting authentication issues
To revoke access:
This immediately invalidates all access and refresh tokens. The next time you use the auth-spotify
command, you'll need to authorize the application again.
Contributions are welcome! Here are some guidelines to follow:
git checkout -b feature/amazing-feature
)npm test
)git commit -m 'Add some amazing feature'
)git push origin feature/amazing-feature
)This project follows these coding standards:
The project follows this structure:
mcp-claude-spotify/
├── src/ # Source code
├── build/ # Compiled JavaScript
├── tests/ # Test files
├── public/ # Public assets
└── ...
This project is licensed under the Mozilla Public License 2.0 - see the LICENSE file for details.