PeterAkande/spotify_mcp
If you are the rightful owner of spotify_mcp and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
The Spotify MCP Server is a comprehensive Model Context Protocol server designed for seamless Spotify operations, featuring 36 production-ready tools and FastMCP transport.
Spotify MCP Server
A comprehensive Model Context Protocol (MCP) server for Spotify operations with 36 production-ready tools and FastMCP transport.
🚀 Quick Start
Prerequisites
# Install uv (Python package manager)
curl -LsSf https://astral.sh/uv/install.sh | sh
Installation
# Clone and install dependencies
git clone <repository>
cd spotify_mcp
uv sync
Development Setup
# Copy environment template
cp .env.example .env
# Edit .env with your configuration (see Configuration section)
# Start development server (auto-reload)
uv run python start_server.py
# OR manually with custom port
uvicorn main:app --reload --port 8001
Features
Complete Spotify Integration
- 36 MCP Tools covering all Spotify operations
- OAuth 2.0 Authentication with Spotify token validation
- Type Safety with comprehensive Pydantic models
Tools available (36 Total)
🔍 Search & Discovery (3 tools)
search_music- Universal music search with filters and paginationget_categories- Browse available music categoriesget_new_releases- Get new album releases
📚 Library Management (8 tools)
get_saved_tracks- Get user's liked tracks with paginationget_saved_albums- Get user's saved albumsget_followed_artists- Get followed artistsget_recently_played- Get recently played tracksget_top_items- Get user's top tracks or artistssave_tracks- Add tracks to user's libraryremove_saved_tracks- Remove tracks from libraryfollow_artists- Follow or unfollow artists
🎼 Playlist Management (8 tools)
get_user_playlists- List user's playlists with paginationcreate_playlist- Create new playlistsget_playlist- Get playlist details and metadataget_playlist_tracks- Get tracks from a playlistadd_tracks_to_playlist- Add tracks to playlistsremove_tracks_from_playlist- Remove tracks from playlistsupdate_playlist_details- Update playlist name, description, etc.unfollow_playlist- Unfollow/delete playlists
🎮 Playback Control (12 tools)
get_current_playback- Get current playback stateget_devices- List available Spotify devicesstart_playback- Start/resume playback with optionspause_playback- Pause current playbacknext_track- Skip to next trackprevious_track- Skip to previous trackseek_track- Seek to specific positionset_volume- Control playback volumeset_repeat- Set repeat mode (track, context, off)set_shuffle- Toggle shuffle modetransfer_playback- Transfer playback between devicesadd_to_queue- Add tracks to playback queue
🔍 Music Analysis (6 tools)
get_track_audio_features- Get audio features for tracksget_audio_analysis- Get detailed audio analysisget_artists- Get artist informationget_artist_top_tracks- Get artist's most popular tracksget_artist_albums- Get artist's albumsget_album_tracks- Get tracks from an album
Configuration
Environment Variables (.env)
# Server Configuration
SERVER_HOST=0.0.0.0 # Server bind address
SERVER_PORT=8001 # Server port
DEBUG=false # Enable debug mode
# Spotify OAuth Configuration
SPOTIFY_CLIENT_ID=your_client_id # From Spotify Developer Dashboard
SPOTIFY_CLIENT_SECRET=your_secret # From Spotify Developer Dashboard
SPOTIFY_REDIRECT_URI=http://localhost:8080/callback
# Logging
LOG_LEVEL=INFO # DEBUG, INFO, WARNING, ERROR
Spotify OAuth Scopes
The server requires these Spotify scopes:
user-read-private- Read user profileuser-read-email- Read user emailuser-library-read- Read user's libraryuser-library-modify- Modify user's libraryplaylist-read-private- Read private playlistsplaylist-modify-public- Modify public playlistsplaylist-modify-private- Modify private playlistsuser-read-playback-state- Read playback stateuser-modify-playback-state- Control playbackuser-read-recently-played- Read recently playeduser-top-read- Read top tracks/artistsuser-follow-read- Read followed artistsuser-follow-modify- Follow/unfollow artists
Response Formats
The server supports multiple response formats for optimal performance:
COMPACT (Default)
- Best for: General music browsing and AI processing
- Contains: Essential metadata + track/artist info
- Use case: Most common operations
MINIMAL
- Best for: Listing and enumeration
- Contains: ID, name, basic info only
- Use case: High-volume operations
FULL
- Best for: Complete music data
- Contains: All available metadata and details
- Use case: Detailed music analysis
RAW
- Best for: Direct Spotify API response
- Contains: Unprocessed Spotify API data
- Use case: Advanced integrations
Pagination Support
Most tools support flexible pagination:
Standard Pagination
# Get first 20 tracks
get_saved_tracks(limit=20, offset=0)
# Get next 20 tracks
get_saved_tracks(limit=20, offset=20)
Examples
# Get user's top tracks from last 6 months
get_top_items(type="tracks", time_range="medium_term", limit=50)
# Search for Drake songs with pagination
search_music(query="Drake", type="track", limit=10, offset=0)
Architecture
MCP Server Design
- Transport: FastMCP with HTTP transport
- Authentication: Spotify OAuth 2.0 with token validation
- Format: JSON-based MCP protocol
- Streaming: Real-time response handling
OAuth Flow
┌─────────────────────┐ ┌──────────────────────┐ ┌─────────────────┐
│ MCP Client │ │ Spotify OAuth │ │ Spotify MCP │
│ │ │ (accounts.spotify) │ │ Server │
│ 1. Request with │────│ 2. Validates token │────│ 3. Spotify API │
│ Bearer token │ │ Returns user info │ │ operations │
│ │ │ │ │ │
└─────────────────────┘ └──────────────────────┘ └─────────────────┘
API Reference
Authentication
All endpoints require a valid Spotify OAuth token:
Authorization: Bearer <spotify_oauth_token>
Development
Project Setup
# Install dependencies
uv sync
# Setup environment
cp .env.example .env
# Edit .env file with your configuration
# Run tests
uv run python examples/test_functions.py
# Start development server with auto-reload
uv run python start_server.py
Development Commands
# Development server (auto-reload)
uv run python start_server.py
# Manual development with custom port
uvicorn main:app --reload --port 8001
# Production server
uvicorn main:app --host 0.0.0.0 --port 8001
# Run interactive tests
uv run python examples/test_functions.py
Testing Tools
The project includes examples/test_functions.py - an interactive test suite:
- Tests all 36 Spotify MCP functions
- Comprehensive debugging with error reporting
- Category-based testing (Search, Library, Playlists, Playback, Analysis)
Spotify OAuth Scopes
The server automatically configures these required scopes:
REQUIRED_SCOPES = [
"user-read-private",
"user-read-email",
"user-library-read",
"user-library-modify",
"playlist-read-private",
"playlist-modify-public",
"playlist-modify-private",
"user-read-playback-state",
"user-modify-playback-state",
"user-read-recently-played",
"user-top-read",
"user-follow-read",
"user-follow-modify"
]
🔐 Spotify OAuth Setup
-
Spotify Developer Dashboard
- Create project at developer.spotify.com
- Create a new app
- Add redirect URI:
http://localhost:8080/callback
-
OAuth Configuration
- Copy Client ID and Client Secret to
.envfile - Configure redirect URIs as needed for your OAuth flow
- Download credentials (not stored in this server)
- Copy Client ID and Client Secret to
-
Token Validation
- This server validates tokens with Spotify's
/v1/meendpoint - No credential storage - tokens validated per request
- For getting an access token for quick test, check
examples/get_access_token.py
- This server validates tokens with Spotify's
📝 License
MIT License - see LICENSE file for details.