danisss9/spotify-playlist-generator-mcp-server
If you are the rightful owner of spotify-playlist-generator-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
A Model Context Protocol (MCP) server that integrates with the Spotify Web API to facilitate music track searches and playlist management.
Spotify Playlist Generator MCP Server
A Model Context Protocol (MCP) server that enables AI applications to search for music tracks and manage playlists using the official Spotify Web API.
Features
- Search Music Tracks: Find music tracks on Spotify with customizable search parameters
- Get Track Details: Retrieve comprehensive information about specific tracks
- Get Playlist Tracks: List tracks from playlists
- Playlist Management: Complete playlist management including creating, editing, and managing playlists (requires OAuth setup)
Setup
Prerequisites
- Node.js 18 or higher
- A Spotify Developer Account
- Spotify App credentials (Client ID and Client Secret)
Installation
- Clone this repository:
git clone https://github.com/danisss9/spotify-playlist-generator-mcp-server
- Install dependencies:
npm install
-
Create a Spotify App:
- Go to the Spotify Developer Dashboard
- Create a new app
- Note down your Client ID and Client Secret
- Add
http://localhost:8888/callback
to your redirect URIs
-
Set up environment variables:
# Create a .env file
echo "SPOTIFY_CLIENT_ID=your_client_id_here" > .env
echo "SPOTIFY_CLIENT_SECRET=your_client_secret_here" >> .env
- Build the TypeScript code:
npm run build
Running the Server
For development with auto-rebuild:
npm run dev
For production:
npm start
Using with MCP Clients
This server uses the stdio transport, so it can be used with any MCP client that supports stdio.
Claude Desktop Configuration
Add to your Claude Desktop configuration file:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"spotify-playlist-generator": {
"command": "node",
"args": ["/absolute/path/to/spotify-playlist-generator/build/index.js"],
"env": {
"SPOTIFY_CLIENT_ID": "your_client_id_here",
"SPOTIFY_CLIENT_SECRET": "your_client_secret_here"
}
}
}
}
Visual Studio Code with GitHub Copilot Configuration
To use this MCP server with GitHub Copilot in Visual Studio Code, you need to configure it in your VS Code settings:
-
Open VS Code Settings: Press
Ctrl+,
(Windows/Linux) orCmd+,
(macOS) -
Search for MCP: Type "mcp" in the search bar
-
Add MCP Server Configuration: Add the following to your VS Code settings JSON:
{
"github.copilot.chat.mcp.servers": {
"spotify-playlist-generator": {
"command": "node",
"args": ["/absolute/path/to/spotify-playlist-generator/build/index.js"],
"env": {
"SPOTIFY_CLIENT_ID": "your_client_id_here",
"SPOTIFY_CLIENT_SECRET": "your_client_secret_here"
}
}
}
}
Alternative: Use Settings UI
- Go to File > Preferences > Settings (or use
Ctrl+,
) - Search for "GitHub Copilot MCP"
- Click "Edit in settings.json" next to "Github āŗ Copilot āŗ Chat: Mcp Servers"
- Add the server configuration as shown above
Environment Variables Setup
For security, you can also set environment variables system-wide instead of in the config:
Windows (PowerShell):
[Environment]::SetEnvironmentVariable("SPOTIFY_CLIENT_ID", "your_client_id_here", "User")
[Environment]::SetEnvironmentVariable("SPOTIFY_CLIENT_SECRET", "your_client_secret_here", "User")
Windows (Command Prompt):
setx SPOTIFY_CLIENT_ID "your_client_id_here"
setx SPOTIFY_CLIENT_SECRET "your_client_secret_here"
macOS/Linux:
export SPOTIFY_CLIENT_ID="your_client_id_here"
export SPOTIFY_CLIENT_SECRET="your_client_secret_here"
# Add to ~/.bashrc, ~/.zshrc, or ~/.profile to persist
echo 'export SPOTIFY_CLIENT_ID="your_client_id_here"' >> ~/.bashrc
echo 'export SPOTIFY_CLIENT_SECRET="your_client_secret_here"' >> ~/.bashrc
Then remove the env
section from the VS Code configuration:
{
"github.copilot.chat.mcp.servers": {
"spotify-playlist-generator": {
"command": "node",
"args": ["/absolute/path/to/spotify-playlist-generator/build/index.js"]
}
}
}
Usage in VS Code
Once configured, you can use the MCP server through GitHub Copilot Chat:
- Open Copilot Chat (
Ctrl+Alt+I
or click the chat icon) - Use natural language to interact with Spotify:
- "Search for jazz music tracks"
- "Create a new playlist called 'My Favorites'"
- "Add these tracks to my playlist"
- "Show me details about this Spotify track"
Available Tools
OAuth-Required Tools (All features require authentication)
authenticate_spotify
Authenticate with Spotify OAuth to enable music search and playlist management features.
Parameters:
getAuthUrl
(boolean, default: false): Set to true to get the authorization URLauthCode
(string, optional): Authorization code from OAuth flow
get_auth_status
Check current Spotify authentication status.
Parameters: None
search_tracks
Search Spotify for music tracks.
Parameters:
query
(string): Search query for trackslimit
(number, 1-50, default: 20): Maximum number of resultsmarket
(string, optional): ISO 3166-1 alpha-2 country code to filter results
get_track_details
Get detailed information about a specific Spotify track.
Parameters:
trackId
(string): Spotify track IDmarket
(string, optional): ISO 3166-1 alpha-2 country code for market
create_playlist
Create a new Spotify playlist (requires authentication).
Parameters:
name
(string): Playlist namedescription
(string, optional): Playlist descriptionpublic
(boolean, default: false): Whether the playlist should be publiccollaborative
(boolean, default: false): Whether the playlist should be collaborative
edit_playlist
Edit existing playlist information (requires authentication).
Parameters:
playlistId
(string): ID of the playlist to editname
(string, optional): New name for the playlistdescription
(string, optional): New description for the playlistpublic
(boolean, optional): New public settingcollaborative
(boolean, optional): New collaborative setting
Note: At least one field (name, description, public, or collaborative) must be provided to update.
add_to_playlist
Add tracks to a Spotify playlist (requires authentication).
Parameters:
playlistId
(string): Target playlist IDtrackUris
(array of strings): Array of Spotify track URIs to addposition
(number, optional): Position to insert tracks (0-based index)
list_playlists
List user's Spotify playlists (requires authentication).
Parameters:
limit
(number, 1-50, default: 20): Maximum number of playlistsoffset
(number, min: 0, default: 0): Index offset for pagination
get_playlist_tracks
Get tracks from a Spotify playlist (requires authentication).
Parameters:
playlistId
(string): ID of the playlist to get tracks fromlimit
(number, 1-100, default: 50): Maximum number of tracks to returnoffset
(number, min: 0, default: 0): Index offset for pagination
remove_from_playlist
Remove tracks from a Spotify playlist (requires authentication).
Parameters:
playlistId
(string): ID of the playlist to remove tracks fromtrackUris
(array of strings): Array of Spotify track URIs to removesnapshotId
(string, optional): Playlist snapshot ID for version control
OAuth Authentication Setup
For all functionality, you need to set up OAuth 2.0 with Spotify:
1. Spotify Developer Dashboard Setup
- Go to Spotify Developer Dashboard
- Log in with your Spotify account
- Click "Create an App"
- Fill in app name and description
- Add
http://localhost:8888/callback
to redirect URIs - Copy your Client ID and Client Secret
2. Environment Configuration
Add your OAuth credentials to the .env
file:
SPOTIFY_CLIENT_ID=your_client_id_here
SPOTIFY_CLIENT_SECRET=your_client_secret_here
3. Authentication Flow
- Use the
authenticate_spotify
tool withgetAuthUrl: true
- Open the provided URL in your browser
- Sign in to your Spotify account and grant permissions
- Copy the authorization code from the callback URL
- Use
authenticate_spotify
tool again with theauthCode
parameter
4. Using Authenticated Features
Once authenticated, you can:
- Search for music tracks
- Get detailed track information
- Create new playlists
- Edit existing playlist information (name, description, privacy)
- Add tracks to your playlists
- List your playlists
- Get tracks from playlists
- Remove tracks from playlists
API Limitations
- Rate Limiting: Spotify API has rate limits (varies by endpoint)
- OAuth Tokens: Access tokens expire after 1 hour and need refresh
- Market Restrictions: Some tracks may not be available in certain markets
- Permissions: OAuth scope determines available operations
Development
Building
npm run build
Development Mode
npm run dev
Project Structure
src/
āāā index.ts # Main server implementation
build/ # Compiled JavaScript output
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
License
MIT License - see LICENSE file for details
Troubleshooting
Common Issues
-
"SPOTIFY_CLIENT_ID and SPOTIFY_CLIENT_SECRET environment variables are required"
- Make sure you've set both environment variables
- Verify the credentials are valid from your Spotify app
-
"Authentication required" errors
- Use the
authenticate_spotify
tool to authenticate first - Check if your access token has expired and re-authenticate
- Use the
-
"Rate limit exceeded" errors
- Wait for the rate limit to reset
- Reduce the frequency of API calls
-
Build errors
- Make sure you have Node.js 18+ installed
- Run
npm install
to ensure all dependencies are installed - Check TypeScript compilation with
npm run build
-
"Track not available" errors
- Some tracks may not be available in your market
- Try specifying a different market parameter
Security Considerations
- Never commit API keys to version control
- Use environment variables for sensitive configuration
- Validate all user inputs
- Implement proper error handling and logging
- Be mindful of Spotify's API terms of service
This project was created using GitHub Copilot