spotify-mcp-server

spotify-mcp-server

0

This project is a Flask-based server that acts as an MCP server integrating with Spotify. It features AI-powered natural language processing for music commands using Google's Gemini AI and provides REST API endpoints for music management.

Spotify MCP Server with AI Integration

A Flask-based MCP (Modular Control Protocol) server that integrates with Spotify and uses Google's Gemini AI for natural language processing of music commands.

Features

  • 🎵 Spotify integration for playlist management
  • 🤖 AI-powered natural language processing
  • 🔒 OAuth2 authentication flow
  • 📜 MCP protocol compliance
  • 🚀 REST API endpoints for:
    • Track searching
    • Playlist creation
    • Playlist modification
    • AI-assisted command processing

Prerequisites

  • Python 3.9+
  • Spotify Developer Account
  • Google Gemini API Key
  • Basic command line knowledge

Installation

  1. Clone the repository:
git clone https://github.com/yourusername/spotify-mcp-server.git
cd spotify-mcp-server
  1. Create and activate virtual environment:
python -m venv venv
source venv/bin/activate  # Linux/MacOS
venv\Scripts\activate  # Windows
  1. Install dependencies:
pip install -r requirements.txt

Configuration

  1. Create .env file:
SPOTIPY_CLIENT_ID=your_spotify_client_id
SPOTIPY_CLIENT_SECRET=your_spotify_secret
SPOTIPY_REDIRECT_URI=http://localhost:5001/callback
SPOTIPY_SCOPE=playlist-modify-public playlist-modify-private
GEMINI_API_KEY=your_gemini_api_key
  1. Get credentials:

Usage

  1. Start the server:
python app.py
  1. Authenticate with Spotify:

  2. Use the API endpoints:

AI-Powered Command

curl -X POST http://localhost:5001/mcp/chat \
  -H "Content-Type: application/json" \
  -d '{"prompt": "Create a workout playlist with rock songs"}'

Direct API Calls

# Search track
curl -X POST http://localhost:5001/mcp/execute \
  -H "Content-Type: application/json" \
  -d '{"action": "search_track", "parameters": {"query": "Thriller Michael Jackson"}}'

API Endpoints

EndpointMethodDescription
/authGETInitiate Spotify authentication
/mcp/statusGETServer health check
/mcp/actionsGETList available actions
/mcp/executePOSTExecute direct commands
/mcp/chatPOSTProcess natural language requests

Examples

Create Playlist with AI

curl -X POST http://localhost:5001/mcp/chat \
  -H "Content-Type: application/json" \
  -d '{"prompt": "Make a jazz playlist with Miles Davis and John Coltrane"}'

Sample Response:

{
  "result": {
    "id": "3jJ5VR3RJNA",
    "name": "Cool Jazz Night",
    "url": "https://open.spotify.com/playlist/3jJ5VR3RJNA"
  }
}

Troubleshooting

Invalid Access Token

rm -rf .spotify_cache  # Clear cached credentials
# Re-authenticate via /auth endpoint

Port Conflicts

# Edit app.py and change port number
app.run(host='0.0.0.0', port=5001)  # Modify this line

API Errors

  • Verify .env credentials
  • Check Spotify developer dashboard settings
  • Ensure proper OAuth scopes

License

MIT License - See for details


.