Generates Spotify playlists based on sentiment analysis of user prompts, combining user listening history with Spotify's recommendation API to create personalized playlists with OAuth authentication support
Designed for integration with WhatsApp bots to enable playlist generation through messaging interactions, providing natural language playlist creation capabilities
🎵 Spotify AI Playlist Generator
An intelligent MCP (Model Context Protocol) server that generates personalized Spotify playlists using AI. This project combines the power of Google's Gemini AI with Spotify's extensive music catalog to create curated playlists based on natural language prompts.
✨ Features
AI-Powered Curation: Uses Google Gemini to generate intelligent search queries and curate track selections
Spotify Integration: Full integration with Spotify's API for authentication, search, and playlist creation
Personalized Recommendations: Analyzes user's listening history for better recommendations
Natural Language Processing: Create playlists using simple prompts like "upbeat workout music" or "chill sunday morning vibes"
Flexible Duration: Specify playlist length from 1 to 300 minutes
MCP Server: Runs as a Model Context Protocol server for easy integration with AI assistants
Health Monitoring: Built-in health checks and logging
🚀 Quick Start
Prerequisites
Python 3.8+
Spotify Premium account (recommended)
Spotify Developer App credentials
Google Gemini API key
Installation
Clone the repository
git clone <your-repo-url> cd spotify-playlist-generatorInstall dependencies
pip install -r requirements.txtSet up environment variables
cp .env.example .env # Edit .env with your credentialsRun the server
python main.py
The server will start on http://127.0.0.1:10000
by default.
🔧 Configuration
Environment Variables
Create a .env
file in the project root with the following variables:
Spotify Developer Setup
Create a new app
Note your Client ID and Client Secret
Add redirect URI:
http://127.0.0.1:10000/callback
Add the required scopes (handled automatically by the app)
Google Gemini API Setup
Go to Google AI Studio
Create a new API key
Add the key to your
.env
file
📖 Usage
1. Health Check
2. Authenticate with Spotify
The server will provide an authentication URL. Visit it to authorize the application.
3. Fetch User Data
After authentication, fetch your Spotify listening history for personalized recommendations.
4. Generate Playlists
Create playlists using natural language prompts:
"Energetic workout music for 45 minutes"
"Chill indie songs for studying"
"90s rock hits for a road trip"
"Emotional ballads for a rainy day"
🛠️ API Endpoints
MCP Tools
The server exposes the following MCP tools:
health
: Check server health statusvalidate
: Validate configurationauthenticate
: Get Spotify authentication URLfetch_data
: Fetch and store user's Spotify datagenerate_playlist
: Generate AI-curated playlist
Generate Playlist Parameters
🏗️ Architecture
Components
Main Server (: FastMCP server handling HTTP requests and routing
Spotify Handler (: Spotify API integration using Tekore
Playlist Generator (: AI-powered playlist curation using Gemini
Data Flow
User provides natural language prompt
Gemini AI generates relevant search queries
Spotify API searches for matching tracks
System fetches additional recommendations based on user history
Gemini AI curates the final track selection
Spotify playlist is created and populated
File Structure
📊 Data Storage
The application creates local JSON files for:
User Data:
user_data_YYYYMMDD_HHMMSS.json
- Spotify listening historyPlaylist Data:
playlist_YYYYMMDD_HHMMSS.json
- Generated playlist metadata
These files are used to improve recommendations and provide playlist history.
🔍 Logging
The application provides comprehensive logging:
INFO: General application flow and successful operations
WARNING: Non-critical issues (e.g., fallback to simple mode)
ERROR: Critical errors and failures
Logs are output to console with timestamps and log levels.
⚙️ Fallback Modes
Without Gemini API
If the Gemini API is unavailable, the system falls back to:
Simple keyword-based search query generation
Popularity-based track selection with randomization
Without User Authentication
The system can still:
Search for tracks using Spotify's public API
Create playlists based on search results (with limited personalization)
🚨 Error Handling
The application includes robust error handling for:
Authentication failures: Clear error messages and retry mechanisms
API rate limits: Graceful degradation and retries
Network issues: Timeout handling and fallback options
Invalid inputs: Input validation and user-friendly error messages
🔒 Privacy & Security
No persistent storage: User tokens are only kept in memory during the session
Local data: All user data is stored locally on your machine
Minimal scopes: Only requests necessary Spotify permissions
Environment variables: Sensitive credentials stored in environment variables
📋 Requirements
Python Dependencies
System Requirements
Memory: 512MB RAM minimum
Storage: 100MB for application and data files
Network: Stable internet connection for API calls
🐛 Troubleshooting
Common Issues
Authentication Error
Check Spotify credentials in
.env
Verify redirect URI in Spotify app settings
Ensure all required scopes are enabled
No Tracks Found
Try more specific or different prompts
Check internet connection
Verify Spotify API access
Gemini API Errors
Verify API key is correct
Check API quota limits
System will fallback to simple mode if needed
Port Already in Use
Change PORT in
.env
fileKill existing processes on the port
Debug Mode
Enable debug logging by modifying the logging level in main.py
:
🤝 Contributing
Fork the repository
Create a feature branch (
git checkout -b feature/amazing-feature
)Commit your changes (
git commit -m 'Add amazing feature'
)Push to the branch (
git push origin feature/amazing-feature
)Open a Pull Request
📜 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
Spotify Web API for music data and playlist management
Google Gemini for AI-powered curation
Tekore for elegant Spotify API integration
FastMCP for MCP server implementation
📞 Support
For questions, issues, or feature requests:
Check the Issues page
Create a new issue with detailed information
Include logs and error messages when reporting bugs
Made with ❤️ for music lovers and AI enthusiasts
This server cannot be installed
remote-capable server
The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.
Generates personalized music playlists based on mood analysis using AI sentiment detection and emoji understanding. Integrates with Last.fm API to create playlists with multi-language support and provides streaming links for Spotify, Apple Music, and YouTube.
Related MCP Servers
- AsecurityAlicenseAqualityEnables interaction with Spotify's music catalog via the Spotify Web API, supporting searches, artist information retrieval, playlist management, and automatic token handling.Last updated -54714MIT License
- -securityFlicense-qualityIntegrates with Spotify Web API through the Model Context Protocol, allowing users to search tracks, control playback, and manage playlists programmatically.Last updated -
- AsecurityAlicenseAqualityEnables creating Spotify playlists based on text descriptions by connecting Cursor editor to Spotify's API through OAuth authentication.Last updated -32MIT License
- AsecurityAlicenseAqualityA server that lets you get customized music recommendations from TIDAL based on your specific criteria, allowing you to create new playlists directly in your TIDAL account.Last updated -723MIT License