Model Context Protocol server for Spotify integration
Project description
Spotify MCP Server
A Model Context Protocol (MCP) server that provides Spotify integration, allowing AI assistants and applications to interact with Spotify's music streaming service.
Features
Artist Tools
- Search Artists - Search for artists by name
- Get Artist - Get detailed information about a specific artist
- Get Artist Albums - Get all albums for an artist
- Get Artist Top Tracks - Get an artist's most popular tracks
Album Tools
- Get Album - Get detailed information about a specific album
- Get Album Tracks - Get all tracks from an album
- Get New Releases - Get new album releases
Playlist Tools
- Create Playlist - Create new playlists
- Add Tracks to Playlist - Add tracks to existing playlists
- Get User Playlists - Get current user's playlists
User Tools
- Get User Top Artists - Get user's most listened to artists
- Get User Top Tracks - Get user's most listened to tracks
Installation
For Claude Desktop Users (Recommended)
The easiest way to use this server with Claude Desktop is via PyPI:
- Get your Spotify API credentials (see Spotify API Setup below)
- Add to your Claude Desktop config at
~/Library/Application Support/Claude/claude_desktop_config.json(macOS):
{
"mcpServers": {
"Spotify": {
"command": "uvx",
"args": ["spotify-mcp-server"],
"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"
}
}
}
}
- Restart Claude Desktop
- On first use, authenticate with Spotify when prompted
Development Setup
Prerequisites
- Python 3.10+
- Spotify Developer Account
- MCP Client (like Claude Desktop, Cursor, etc.)
Setup
1. Install Dependencies
# Using uv (recommended)
uv sync
# Or using pip
pip install -r requirements.txt
2. Spotify API Setup {#spotify-api-setup}
- Go to Spotify Developer Dashboard
- Create a new application
- Add
http://localhost:8888/callbackto your app's Redirect URIs - Copy your Client ID and Client Secret
3. Environment Configuration
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://localhost:8888/callback
4. Authentication
On first run, the server will open a browser window for Spotify authentication. Follow the OAuth flow to authorize the application.
Usage
Running the Server
# Development mode with inspector
mcp dev spotify_mcp_server.py
# Or run directly
python spotify_mcp_server.py
Available Tools
Artist Management
# Search for artists
search_artists(query="The Beatles", limit=10)
# Get artist details
get_artist(artist_id="3WrFJ7ztbogyGnTHbHJFl2")
# Get artist albums
get_artist_albums(artist_id="3WrFJ7ztbogyGnTHbHJFl2", include_groups="album,single")
# Get artist top tracks
get_artist_top_tracks(artist_id="3WrFJ7ztbogyGnTHbHJFl2", market="US")
Album Management
# Get album details
get_album(album_id="4aawyAB9vmqN3uQ7FjRGTy", market="US")
# Get album tracks
get_album_tracks(album_id="4aawyAB9vmqN3uQ7FjRGTy", limit=20)
# Get new releases
get_new_releases(country="US", limit=20)
Playlist Management
# Create a new playlist
create_playlist(name="My New Playlist", description="A great playlist", public=False)
# Add tracks to playlist
add_tracks_to_playlist(playlist_id="playlist_id", track_uris=["spotify:track:track_id"])
# Get user playlists
get_user_playlists()
User Data
# Get user's top artists
get_user_top_artists(time_range="medium_term", limit=20)
# Get user's top tracks
get_user_top_tracks(time_range="short_term", limit=10)
Project Structure
spotify-mcp/
├── spotify_mcp_server.py # Main MCP server
├── mcp_tools/ # Tool modules
│ ├── __init__.py
│ ├── artist_tools.py # Artist-related tools
│ ├── playlist_tools.py # Playlist-related tools
│ ├── albums.py # Album-related tools
│ └── user_tools.py # User-related tools
├── .env # Environment variables
├── .spotify_cache # Spotify OAuth cache
├── requirements.txt # Python dependencies
└── README.md # This file
API Reference
Artist Tools
search_artists
Search for artists on Spotify.
Parameters:
query(str): Search query for artist namelimit(int, optional): Maximum number of results (default: 10, max: 50)
Returns:
- List of artists with ID, name, popularity, followers, genres, and Spotify URL
get_artist
Get detailed information about an artist.
Parameters:
artist_id(str): Spotify artist ID
Returns:
- Detailed artist information including images, genres, and popularity
get_artist_albums
Get albums for an artist.
Parameters:
artist_id(str): Spotify artist IDinclude_groups(str, optional): Album types to include (default: "album,single")limit(int, optional): Maximum albums to return (default: 20, max: 50)
Returns:
- List of albums with details including release date, track count, and cover images
get_artist_top_tracks
Get top tracks for an artist.
Parameters:
artist_id(str): Spotify artist IDmarket(str, optional): Market/country code (default: "US")
Returns:
- List of top tracks with popularity, duration, and album information
Album Tools
get_album
Get detailed information about an album.
Parameters:
album_id(str): Spotify album IDmarket(str, optional): Market/country code (default: "US")
Returns:
- Detailed album information including artists, images, and genres
get_album_tracks
Get tracks from an album.
Parameters:
album_id(str): Spotify album IDmarket(str, optional): Market/country code (default: "US")limit(int, optional): Maximum tracks to return (default: 20, max: 50)offset(int, optional): Starting index (default: 0)
Returns:
- List of tracks with track number, duration, and artist information
get_new_releases
Get new album releases.
Parameters:
country(str, optional): Country code (default: "US")limit(int, optional): Maximum albums to return (default: 20, max: 50)offset(int, optional): Starting index (default: 0)
Returns:
- List of new release albums with artist and image information
Playlist Tools
create_playlist
Create a new Spotify playlist.
Parameters:
name(str): Name of the playlistdescription(str, optional): Description of the playlistpublic(bool, optional): Whether the playlist is public (default: False)collaborative(bool, optional): Whether the playlist is collaborative (default: False)
Returns:
- Playlist information including ID, name, and Spotify URL
add_tracks_to_playlist
Add tracks to an existing playlist.
Parameters:
playlist_id(str): Spotify playlist IDtrack_uris(List[str]): List of Spotify track URIs
Returns:
- Success status and number of tracks added
get_user_playlists
Get current user's playlists.
Parameters:
- None
Returns:
- List of user's playlists with details including track count and privacy settings
User Tools
get_user_top_artists
Get user's most listened to artists from Spotify.
Parameters:
time_range(str, optional): Time period for top artists (default: "medium_term")"short_term": Last 4 weeks"medium_term": Last 6 months"long_term": Several years
limit(int, optional): Maximum number of artists to return (default: 20, max: 50)offset(int, optional): Index of the first artist to return (default: 0)
Returns:
- List of top artists with ID, name, popularity, followers, genres, and Spotify URL
get_user_top_tracks
Get user's most listened to tracks from Spotify.
Parameters:
time_range(str, optional): Time period for top tracks (default: "medium_term")"short_term": Last 4 weeks"medium_term": Last 6 months"long_term": Several years
limit(int, optional): Maximum number of tracks to return (default: 20, max: 50)offset(int, optional): Index of the first track to return (default: 0)
Returns:
- List of top tracks with ID, name, album info, artists, popularity, duration, and Spotify URL
Development
Adding New Tools
- Create a new function in the appropriate tool module (
artist_tools.py,playlist_tools.py,albums.py, oruser_tools.py) - Add the function to the
__init__.pyexports - Create a wrapper function in
spotify_mcp_server.py - Copy the docstring and register the tool
Testing
# Run the server in development mode
mcp dev spotify_mcp_server.py
# The MCP Inspector will open at http://localhost:6274
# Use it to test your tools interactively
Troubleshooting
Authentication Issues
- Ensure your
.envfile has the correct Spotify credentials - Check that your redirect URI matches exactly:
http://localhost:8888/callback - Clear the
.spotify_cachefile if you encounter token issues
API Rate Limits
- Spotify has rate limits on API calls
- The server includes error handling for rate limit responses
- Consider implementing caching for frequently accessed data
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spotify_mcp_server-0.1.5.tar.gz.
File metadata
- Download URL: spotify_mcp_server-0.1.5.tar.gz
- Upload date:
- Size: 69.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8165fc1affffab1aa3cb67c2e2f07edda43b619b0fe76867c844d3dc86ef2180
|
|
| MD5 |
c757944f385157b63e90e916c087ae10
|
|
| BLAKE2b-256 |
2ec14953049c303dd83f14588048b9c2542b5ef789abbaa7a3d715bfed195edf
|
File details
Details for the file spotify_mcp_server-0.1.5-py3-none-any.whl.
File metadata
- Download URL: spotify_mcp_server-0.1.5-py3-none-any.whl
- Upload date:
- Size: 14.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
85192b9904ddc27c35f1c45d7faa46c04e04bf26834b3cf23d89b444cb8204dd
|
|
| MD5 |
5b2677df1c17f2186742d08d9b0b25b5
|
|
| BLAKE2b-256 |
6e673bda91878685929d08c46556b41e3eb849a5a505d288452c9dae753ba58c
|