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.
README
MCP Claude Spotify
An integration that allows Claude Desktop to interact with Spotify using the Model Context Protocol (MCP).
Demo
<p> <a href="https://www.youtube.com/watch?v=d_L7MaqGbbI"> <img src="public/assets/preview.png" width="600" alt="Claude Spotify Integration Demo"> </a> </p>
Features
- Spotify authentication
- Search for tracks, albums, artists, and playlists
- Playback control (play, pause, next, previous)
- Create and manage playlists
- Get personalized recommendations
- Access user's top played tracks over different time periods
Requirements
- Node.js 16 or higher
- Spotify account
- Claude Desktop
- Spotify API credentials (Client ID and Client Secret)
Installation
- 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.
Setting up Spotify Credentials
To use this MCP, you need to obtain Spotify API credentials:
- Go to Spotify Developer Dashboard
- Log in with your Spotify account
- Click "Create App"
- Fill in your app information:
- App name: "MCP Claude Spotify" (or whatever you prefer)
- App description: "Spotify integration for Claude Desktop"
- Website: You can leave this blank or put any URL
- Redirect URI: Important - Add
http://127.0.0.1:8888/callback
- Accept the terms and conditions and click "Create"
- In your app dashboard, you'll see the "Client ID"
- Click "Show Client Secret" to reveal your "Client Secret"
Save these credentials as you'll need them for configuration.
Running the MCP Server
There are two ways to run the MCP server:
Option 1: Running manually (recommended for first-time setup and troubleshooting)
- Open a terminal or command prompt
- Navigate to the project directory
- Run the server directly:
node build/index.js
Keep this terminal window open while using Claude Desktop. The server will run until you close the terminal.
Option 2: Auto-starting with Claude Desktop (recommended for regular use)
The Claude Desktop can automatically start the MCP server when needed. To set this up:
Configuration
The Claude Desktop configuration file is located at:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_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_DIRECTORYwith the complete absolute path where you installed the MCP- macOS/Linux example:
/Users/username/mcp-claude-spotify - Windows example:
C:\\Users\\username\\mcp-claude-spotify
- macOS/Linux example:
your_client_id_herewith the Client ID you obtained from Spotifyyour_client_secret_herewith the Client Secret you obtained from Spotify
If you already have other MCPs configured, simply add the "spotify" section inside the "mcpServers" object.
Setting up auto-start scripts (Optional)
For a more reliable experience, you can set up auto-start scripts:
<details> <summary><b>Windows auto-start instructions</b></summary>
- Create a file named
start-spotify-mcp.batin the project directory with the following content:
@echo off
cd %~dp0
node build/index.js
- Create a shortcut to this BAT file
- Press
Win+R, typeshell:startupand press Enter - Move the shortcut to this folder to have it start with Windows </details>
<details> <summary><b>macOS auto-start instructions</b></summary>
- Create a file named
com.spotify.mcp.plistin~/Library/LaunchAgents/with the following content:
<?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>
- Replace the path and credentials with your actual values
- Load the agent with:
launchctl load ~/Library/LaunchAgents/com.spotify.mcp.plist</details>
<details> <summary><b>Linux auto-start instructions</b></summary>
- Create a file named
spotify-mcp.servicein~/.config/systemd/user/(create the directory if it doesn't exist):
[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
- Replace the path and credentials with your actual values
- Enable and start the service:
systemctl --user enable spotify-mcp.service
systemctl --user start spotify-mcp.service
- Check status with:
systemctl --user status spotify-mcp.service
</details>
Usage
- Restart Claude Desktop after modifying the configuration
- In Claude, use the
auth-spotifycommand to start the authentication process - A browser window will open for you to authorize the application
- Log in with your Spotify account and authorize the application
- Important: After successful authentication, restart Claude Desktop to properly initialize the MCP's tool registry and WebSocket session token cache
- After restarting, all Spotify MCP tools will be properly registered and available for use
The 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.
Available Tools
auth-spotify
Initiates the Spotify authentication process.
search-spotify
Searches for tracks, albums, artists, or playlists.
Parameters:
query: Search texttype: Type of search (track, album, artist, playlist)limit: Number of results (1-50)
play-track
Plays a specific track.
Parameters:
trackId: Spotify track IDdeviceId: (Optional) Spotify device ID to play on
get-current-playback
Gets information about the current playback.
pause-playback
Pauses the playback.
next-track
Skips to the next track.
previous-track
Returns to the previous track.
get-user-playlists
Gets the user's playlists.
create-playlist
Creates a new playlist.
Parameters:
name: Playlist namedescription: (Optional) Descriptionpublic: (Optional) Whether it's public or private
add-tracks-to-playlist
Adds tracks to a playlist.
Parameters:
playlistId: Playlist IDtrackIds: Array of track IDs
get-recommendations
Gets recommendations based on seeds.
Parameters:
seedTracks: (Optional) Array of track IDsseedArtists: (Optional) Array of artist IDsseedGenres: (Optional) Array of genreslimit: (Optional) Number of recommendations (1-100)
get-top-tracks
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 weeksmedium_term: Approximately last 6 months (default)long_term: Several years of data
Troubleshooting
"Server disconnected" error
If you see the error "MCP Spotify: Server disconnected" in Claude Desktop:
-
Verify the server is running:
- Open a terminal and manually run
node build/index.jsfrom the project directory - If the server starts successfully, use Claude while keeping this terminal open
- Open a terminal and manually run
-
Check your configuration:
- Ensure the absolute path in
claude_desktop_config.jsonis correct for your system - Double-check that you've used double backslashes (
\\) for Windows paths - Verify you're using the complete path from the root of your filesystem
- Ensure the absolute path in
-
Try the auto-start option:
- Set up the auto-start script for your operating system as described in the "Setting up auto-start scripts" section
- This ensures the server is always running when you need it
Browser doesn't open automatically
If the browser doesn't open automatically during authentication, manually visit:
http://127.0.0.1:8888/login
Authentication error
Make sure you've correctly configured the redirect URI in your Spotify Developer dashboard:
http://127.0.0.1:8888/callback
Server startup error
Verify that:
- Environment variables are correctly configured in your
claude_desktop_config.jsonor 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
Tools not appearing in Claude
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
Checking if the server is running
To check if the server is running:
- Windows: Open Task Manager, go to the "Details" tab, and look for "node.exe"
- macOS/Linux: Open Terminal and run
ps aux | grep node
If you don't see the server running, start it manually or use the auto-start method.
Testing
This project includes automated tests to ensure code quality and functionality. The test suite uses Jest with TypeScript support and covers:
- Zod schema validation - verifies all input schemas correctly validate data
- Spotify API interactions - tests API request handling and error handling
- MCP server functionality - ensures proper registration and execution of tools
Running Tests
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.
Test Structure
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 functionality
Adding New Tests
When adding new functionality, please include corresponding tests:
- For new schemas, add validation tests in
schemas.test.ts - For Spotify API functions, add tests in
spotify-api.test.ts - For MCP tools, add tests in
server.test.ts
All tests should be written using Jest and the ESM module format with TypeScript.
Security Notes
- Never share your Client ID and Client Secret
- Access token is now stored in the user's home directory at
~/.spotify-mcp/tokens.jsonto enable persistence between sessions and multiple instances - No user data is stored on disk
Revoking Application Access
For 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:
- Go to your Spotify Account page
- Navigate to "Apps" in the menu
- Find "MCP Claude Spotify" (or the name you chose for your app)
- Click "REMOVE 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.
Contributing
Contributions are welcome! Here are some guidelines to follow:
Development Workflow
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run tests to ensure they pass (
npm test) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Code Style Guidelines
This project follows these coding standards:
- Use TypeScript with strict type checking
- Follow ESM module format
- Use 2 spaces for indentation
- Use camelCase for variables and functions
- Use PascalCase for classes and interfaces
- Document functions with JSDoc comments
- Keep line length under 100 characters
Project Structure
The project follows this structure:
mcp-claude-spotify/
├── src/ # Source code
├── build/ # Compiled JavaScript
├── tests/ # Test files
├── public/ # Public assets
└── ...
Pull Request Process
- Ensure your code follows the style guidelines
- Update documentation if needed
- Add tests for new functionality
- Make sure all tests pass
- Your PR will be reviewed by maintainers
Related Links
License
This project is licensed under the Mozilla Public License 2.0 - see the LICENSE file for details.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。