Claude Spotify 音乐助手
STDIO让Claude桌面端通过MCP控制Spotify
让Claude桌面端通过MCP控制Spotify
![]() | An integration that allows Claude Desktop to interact with Spotify using the Model Context Protocol (MCP). |
To install MCP Claude Spotify for Claude Desktop automatically via Smithery:
npx -y @smithery/cli install @imprvhub/mcp-claude-spotify --client claude
git clone https://github.com/imprvhub/mcp-claude-spotify cd claude-spotify-mcp
npm install
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%\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_DIRECTORY
with the complete absolute path where you installed the MCP
/Users/username/mcp-claude-spotify
C:\\Users\\username\\mcp-claude-spotify
your_client_id_here
with the Client ID you obtained from Spotifyyour_client_secret_here
with the Client Secret you obtained from SpotifyIf 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:
start-spotify-mcp.bat
in the project directory with the following content:@echo off
cd %~dp0
node build/index.js
Win+R
, type shell:startup
and press Entercom.spotify.mcp.plist
in ~/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>
launchctl load ~/Library/LaunchAgents/com.spotify.mcp.plist
spotify-mcp.service
in ~/.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
systemctl --user enable spotify-mcp.service systemctl --user start spotify-mcp.service
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 texttype
: Type of search (track, album, artist, playlist)limit
: Number of results (1-50)Plays a specific track.
Parameters:
trackId
: Spotify track IDdeviceId
: (Optional) Spotify device ID to play onGets 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 namedescription
: (Optional) Descriptionpublic
: (Optional) Whether it's public or privateAdds tracks to a playlist.
Parameters:
playlistId
: Playlist IDtrackIds
: Array of track IDsGets 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)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 dataIf you see the error "MCP Spotify: Server disconnected" in Claude Desktop:
Verify the server is running:
node build/index.js
from the project directoryCheck your configuration:
claude_desktop_config.json
is correct for your system\\
) for Windows pathsTry 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:
claude_desktop_config.json
or launch scriptIf the Spotify tools don't appear in Claude after authentication:
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:
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.