使用说明
Spotify MCP Server
A Python server based on Spotify OAuth and MCP protocols, providing Spotify music control functionality.
Features
- ✅ Spotify OAuth Authentication
- ✅ Get the current playback status
- ✅ Play/Pause Control
- ✅ Previous/Next Switch
- ✅ Volume Control
- ✅ Play position jump
- ✅ Equipment Management
install
- Installation dependencies:
pip install -e .
-
Configure Spotify OAuth credentials:
- visit Spotify Developer Dashboard
- Create an application and obtain it
Client IDandClient Secret - Set the redirect URI to
http://127.0.0.1:8000/callback
-
Set environment variables:
export SPOTIFY_CLIENT_ID="your_client_id"
export SPOTIFY_CLIENT_SECRET="your_client_secret"
export SPOTIFY_REDIRECT_URI="http://127.0.0.1:8000/callback" # 可选,默认值
Instructions for use
1. Start MCP server
The server communicates through STDio and is usually automatically started by MCP clients (such as Claude Desktop).
2. First certification
- invoke
spotify_get_auth_urlTool to obtain authorization URL - Accessing the URL in the browser and completing authorization
- Extract authorization code from callback URL(
codeParameters) - invoke
spotify_authenticateTool, pass in authorization code to complete authentication
The authentication information will be saved in ~/.spotify_mcp_token.jsonSubsequent use will automatically refresh the token.
3. Use control functions
After successful authentication, the following tools can be used:
spotify_get_current_playback-Get the current playback statusspotify_pause-Pause playbackspotify_next-Next songspotify_previous-Previous songspotify_set_volume-Set volume (0-100)spotify_seek-Jump to the specified locationspotify_get_devices-Get the list of available devicesspotify_play_artist-Search and play the top 10 tracks of a specified artist, such as' Taylor Swift's songs'spotify_play_song-Play songs based on the singer and song title. For example, playing Taylor Swift's Love Story
MCP client configuration
Add:
{
"mcpServers": {
"spotify-mcp": {
"command": "python",
"args": ["-m", "spotify_mcp"],
"env": {
"SPOTIFY_CLIENT_ID": "your_client_id",
"SPOTIFY_CLIENT_SECRET": "your_client_secret",
"SPOTIFY_REDIRECT_URI"="http://127.0.0.1:8000/callback"
}
}
}
}
Or use UV
{
"mcpServers": {
"spotify-mcp": {
"command": "uv",
"args": ["run", "-m", "spotify_mcp"],
"env": {
"SPOTIFY_CLIENT_ID": "your_client_id",
"SPOTIFY_CLIENT_SECRET": "your_client_secret",
"SPOTIFY_REDIRECT_URI"="http://127.0.0.1:8000/callback"
}
}
}
}
Precautions
- Ensure that the Spotify app is turned on and playing music
- Some features require a Spotify Premium account
- Token will automatically refresh, no need to manually re authenticate
- The device ID parameter is optional, and if not specified, the current active device will be used
license
MIT