Spotify MCP Tool
A powerful tool that combines Spotify API with Google's Gemini AI to provide music insights, recommendations, and analysis.
Features
Spotify Data Access
- User profile information
- Playlists and tracks
- Top tracks and artists
- Recently played tracks
- New releases
AI-Powered Insights (Gemini)
- Comprehensive listening habit analysis
- Personalized track recommendations
- Playlist insights and analysis
- Question answering about playlists
- Music discovery suggestions
- Mood-based playlist generation
Installation
- Clone the repository:
git clone https://github.com/pradeepjung45/spotify_mcp.git
cd spotify_mcp
- Create a virtual environment and install dependencies:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
- Set up environment variables:
Create a
.envfile in the root directory with the following:
SPOTIFY_CLIENT_ID=your_spotify_client_id
SPOTIFY_CLIENT_SECRET=your_spotify_client_secret
SPOTIFY_REDIRECT_URI=http://127.0.0.1:8000/callback
GEMINI_API_KEY=your_gemini_api_key
Usage
CLI Tool
The project includes a command-line interface for interacting with Spotify and Gemini AI:
- Authenticate with Spotify:
python mcp_tools.py auth_url
This will provide a URL to open in your browser. After authorizing, you'll be redirected to a callback URL with a code parameter.
- Complete authentication with the code:
python mcp_tools.py auth_url --code YOUR_CODE_HERE
- Get your user profile:
python mcp_tools.py user_profile
- Get your playlists:
python mcp_tools.py playlists
- Get AI analysis of your listening habits:
python mcp_tools.py listening_analysis
- Get AI-powered track recommendations:
python mcp_tools.py track_recommendations
- Get insights about a specific playlist:
python mcp_tools.py playlist_insights --playlist-id YOUR_PLAYLIST_ID
- Ask a question about a playlist:
python mcp_tools.py playlist_question --playlist-id YOUR_PLAYLIST_ID --question "What is the overall mood of this playlist?"
- Get music discovery suggestions:
python mcp_tools.py music_discovery
- Get a mood-based playlist suggestion:
python mcp_tools.py mood_playlist --mood happy
FastAPI Server
The project also includes a FastAPI server for accessing the same functionality through a web interface:
- Start the server:
python -m uvicorn app.main:app --host 0.0.0.0 --port 8000
-
Open your browser and navigate to
http://localhost:8000 -
Click "Login with Spotify" to authenticate
-
Access various endpoints for Spotify data and AI insights
MCP Integration
This tool is designed to be used as an MCP (Model Context Protocol) tool with Claude Desktop. Once Claude Desktop is available, you can install the tool using:
mcp install mcp_tools.py
Project Structure
app/- FastAPI applicationrouters/- API route handlersservices/- Service classes for Spotify and Geminiconfig.py- Configuration settingsmain.py- FastAPI application entry point
mcp_tools.py- MCP tool and CLI interface
Requirements
- Python 3.8+
- Spotify Developer Account
- Google Gemini API Key
License
MIT
