Spotify MCP Server: Unleashing AI-Powered Control Over Your Music
In the rapidly evolving landscape of artificial intelligence, the ability for AI models to interact with and control external services is becoming increasingly crucial. The Spotify MCP (Model-Context-Protocol) Server emerges as a groundbreaking solution, enabling AI assistants and other clients to seamlessly manage Spotify playback through a standardized protocol. Leveraging the MCP architecture, this project unlocks a new realm of possibilities for integrating AI with music streaming.
What is MCP?
At its core, the Model-Context-Protocol (MCP) is a framework designed to facilitate communication between AI models and external tools. It provides a standardized interface, allowing AI assistants and other clients to access and utilize various functionalities of external services like Spotify. By adhering to the MCP framework, the Spotify MCP Server ensures compatibility and ease of integration with any MCP-compatible client.
Use Cases: The Power of AI-Driven Music Control
The Spotify MCP Server opens up a wide array of use cases, transforming the way we interact with music:
- AI-Powered Music Assistants: Imagine an AI assistant that can respond to your voice commands to play your favorite songs, pause playback, skip tracks, and adjust the volume – all without you having to lift a finger. The Spotify MCP Server makes this a reality.
- Smart Home Integration: Integrate Spotify control into your smart home ecosystem. Use voice commands to play music in specific rooms, create personalized playlists based on your mood, or even automatically adjust the music based on the time of day.
- Automated Music Workflows: Automate music-related tasks with AI-powered workflows. For example, automatically create a playlist of songs based on your recent listening history or generate a workout playlist based on your preferred genre and tempo.
- Enhanced Accessibility: Provide individuals with disabilities with alternative ways to control Spotify playback, such as through voice commands or other assistive technologies.
- Interactive Music Experiences: Develop interactive music experiences that respond to user input in real-time. For example, create a game where the music changes based on the player’s actions or a virtual concert where the audience can influence the setlist.
Key Features: A Comprehensive Suite of Control Options
The Spotify MCP Server offers a comprehensive set of features, empowering AI clients with complete control over Spotify playback:
- Search: Seamlessly search for songs on Spotify using natural language queries.
- Play: Initiate playback of any song on your active Spotify device.
- Pause: Temporarily halt the music for a moment of peace.
- Next Track: Skip to the next track in your current playlist or queue.
- Previous Track: Rewind to the previous track and relive your favorite moments.
- Volume Control: Fine-tune the playback volume to your desired level.
- User Info: Access current user information for personalized experiences.
- Playlists: Explore your Spotify playlists and discover new music.
- Now Playing: Get real-time information about the currently playing track.
Getting Started: A Step-by-Step Guide
Setting up the Spotify MCP Server is a straightforward process. Follow these steps to unlock the power of AI-driven music control:
Prerequisites: Ensure you have Python 3.11 or higher, a Spotify Premium account, and Spotify Developer credentials.
Clone the Repository: Clone the Spotify MCP Server repository from GitHub using the following command:
bash git clone https://github.com/KaanCL/Spotify-MCP-Server.git cd Spotify-MCP-Server
Set up a Virtual Environment: Create a virtual environment to isolate the project’s dependencies:
bash uv venv
Install Dependencies: Install the required dependencies using the following command:
bash uv sync
Configuration: Create a Spotify application at the Spotify Developer Dashboard and obtain your Client ID and Client Secret. Create a
.env
file in the project root with your credentials:CLIENT_ID=your-spotify-client-id CLIENT_SECRET=your-spotify-client-secret REDIRECT_URI=http://localhost:8888/callback
Initialization & First Run: Run the MCP server for the first time. A browser window will open asking you to log in to your Spotify account and authorize the application. The server will then initialize and start listening for connections on port 8080.
Usage: Run the MCP server using the following command:
bash uv run mcp install main.py
Tool Documentation: A Deep Dive into Functionality
The Spotify MCP Server exposes a set of MCP tools, each designed to perform a specific task. These tools are implemented as Python functions decorated with @mcp.tool()
and are accessible as API endpoints. All tools return Python dictionaries or lists of dictionaries for easy JSON serialization and integration.
Here’s a detailed look at each tool:
- search(query: str) → dict: Searches for tracks on Spotify based on a query string. Returns up to 5 matching tracks, each with name, artist, album, URI, and Spotify URL.
- start_playback(track_name: str) → dict: Starts playback for a given track name. Searches for the track and initiates playback on the user’s active device.
- pause_playback() → dict: Pauses the current playback on the active device.
- resume_playback() → dict: Resumes playback if paused.
- next_track() → dict: Skips to the next track in the current playlist or queue.
- previous_track() → dict: Returns to the previous track.
- get_user_playlists() → dict: Retrieves the user’s playlists, including name, URL, ID, and track count.
- set_player_volume(volume: int) → dict: Sets the Spotify player’s volume (0-100).
- current_playback() → dict: Gets information about the currently playing track, including playback state, track name, artist, album, progress, and duration.
- get_current_user() → dict: Gets the current Spotify user’s profile information (display name, email, user ID).
MCP Client Example: Integrating with Your AI Assistant
Any MCP-compatible client can interact with the Spotify MCP Server. Here’s an example of how to use the mcp.client
library to interact with the server:
python from mcp.client import MCPClient
Connect to the MCP server
client = MCPClient(“http://localhost:8080”)
Search for a song
results = client.call(“search”, {“query”: “Money Trees”}) print(results)
Play a song
client.call(“start_playback”, {“track_name”: “Money Trees”})
Pause playback
client.call(“pause_playback”)
Get current playback info
playback_info = client.call(“current_playback”) print(playback_info)
Error Handling: Robust and Informative
The Spotify MCP Server provides robust error handling, ensuring that API responses are returned as JSON objects. If an error occurs, the response will include an "error"
key with a descriptive message. This allows clients to easily identify and handle errors gracefully.
Architecture: A Modular and Extensible Design
The Spotify MCP Server is built on a modular architecture, making it easy to extend and maintain. The server leverages the FastMCP framework for high performance and uses the Spotipy library to interact with the Spotify API. Each Spotify function is registered as an MCP tool with type hints and documentation, ensuring code clarity and maintainability.
mermaid graph TD A[MCP Client] – HTTP --> B[FastMCP Server] B – Python Call --> C[spotify.py] C – REST API --> D[Spotify Web API]
UBOS: Empowering AI Agent Development
UBOS is a full-stack AI Agent Development Platform designed to bring AI Agents to every business department. Our platform allows you to orchestrate AI Agents, connect them with your enterprise data, build custom AI Agents with your LLM model, and create Multi-Agent Systems. By integrating with the Spotify MCP Server, UBOS can provide users with even more powerful and versatile AI Agents that can control music playback and enhance their overall experience.
Conclusion: A New Era of Music Control
The Spotify MCP Server represents a significant step forward in the integration of AI with music streaming. By providing a standardized protocol for AI clients to control Spotify playback, this project unlocks a new world of possibilities for AI-powered music assistants, smart home integration, and automated music workflows. As the field of AI continues to evolve, the Spotify MCP Server will play an increasingly important role in shaping the future of music consumption.
Spotify Control Server
Project Details
- KaanCL/Spotify-MCP-Server
- Last Updated: 5/5/2025
Recomended MCP Servers
an MCP server providing tools for network incident response folks
pocketbase-mcp-server
MCP Interface for Video Jungle
This MCP server integrates with your Google Drive and Google Sheets, to enable creating and modifying spreadsheets.
Unofficial MCP to use BrianKnows API for DeFI knowledge
Projet RAG avec ChromaDB utilisant Docker
mem0 MCP Server: A modern memory system using mem0 for AI applications with model context protocl (MCP)...