Spotify MCP Server
Integrates Spotify with Claude to enable voice-controlled music playback, playlist management, and personalized recommendations through conversational AI. It provides comprehensive tools for searching tracks, managing liked songs, and analyzing listening habits.
README
🎵 Spotify MCP Server
A Model Context Protocol (MCP) server that integrates Spotify with Claude, enabling voice-controlled music playback, playlist management, and personalized music recommendations directly through conversational AI.
✨ Features
🎵 Playback Control
- Get currently playing track with full details
- Play specific tracks by name or ID
- Pause/resume playback
- Skip to next/previous tracks
- Adjust volume levels
- Toggle shuffle mode
❤️ Library Management
- Like/unlike songs
- Add tracks to Liked Songs
- Remove tracks from Liked Songs
📝 Playlist Operations
- Create new playlists
- Add tracks to existing playlists
- Search and discover music
🔍 Discovery & Search
- Search for tracks, artists, albums, and playlists
- Get personalized recommendations
- View top tracks and artists (customizable time ranges)
📊 Analytics
- View your most played tracks
- See your top artists
- Analyze listening habits over different time periods
🚀 Prerequisites
- Node.js v18 or higher
- Claude Desktop
- Spotify Premium account (required for playback control)
- Spotify Developer account
📦 Installation
1. Create Spotify Developer App
- Go to Spotify Developer Dashboard
- Log in with your Spotify account
- Click "Create app"
- Fill in:
- App name:
Claude MCP Integration - App description:
MCP server for Claude AI - Redirect URI:
http://localhost:3000/callback⚠️ CRITICAL
- App name:
- Save and note your Client ID and Client Secret
2. Clone and Setup
# Clone the repository
git clone https://github.com/MadhurToshniwal/Spotify-MCP-Server.git
cd Spotify-MCP-Server
# Install dependencies
npm install
# Build the project
npm run build
3. Configure Environment Variables
Create a .env file in the project root:
SPOTIFY_CLIENT_ID=your_client_id_here
SPOTIFY_CLIENT_SECRET=your_client_secret_here
SPOTIFY_REFRESH_TOKEN=will_get_this_next
4. Authorize Your Spotify Account
Run the OAuth helper script:
npm run auth
This will:
- Start a local server on port 3000
- Open your browser to Spotify's authorization page
- After you authorize, display your refresh token
- Copy the refresh token and add it to your
.envfile
5. Configure Claude Desktop
Edit your Claude Desktop configuration file:
Windows: %APPDATA%\Claude\claude_desktop_config.json
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Add this configuration:
{
"mcpServers": {
"spotify": {
"command": "node",
"args": [
"/absolute/path/to/spotify-mcp-server/dist/index.js"
],
"env": {
"SPOTIFY_CLIENT_ID": "your_client_id",
"SPOTIFY_CLIENT_SECRET": "your_client_secret",
"SPOTIFY_REFRESH_TOKEN": "your_refresh_token"
}
}
}
}
Important for Windows users: Use double backslashes in paths:
"args": ["C:\\Users\\YourName\\Desktop\\spotify-mcp-server\\dist\\index.js"]
6. Restart Claude Desktop
Completely quit and restart Claude Desktop for changes to take effect.
🎮 Usage Examples
Once configured, you can ask Claude:
Playback Control
- "What song am I listening to?"
- "Pause the music"
- "Play the next song"
- "Set volume to 70%"
- "Turn shuffle on"
Search & Discovery
- "Search for songs by The Weeknd"
- "Find some jazz playlists"
- "Search for the album 'Abbey Road'"
Library Management
- "Add this song to my liked songs"
- "Unlike this track"
- "Create a playlist called 'Workout Mix'"
- "Add these 3 songs to my playlist"
Analytics
- "What are my top 10 songs this month?"
- "Show me my most played artists"
- "What have I been listening to recently?"
Advanced
- "Search for 'Bohemian Rhapsody' and play it"
- "Create a playlist called 'Study Music' and add 5 calm songs"
- "Find electronic music playlists and play the most popular one"
🛠️ Available Tools
| Tool | Description |
|---|---|
search_music |
Search for tracks, artists, albums, or playlists |
get_current_track |
Get the currently playing track |
play_track |
Play a specific track by URI or ID |
pause_playback |
Pause current playback |
resume_playback |
Resume playback |
skip_to_next |
Skip to next track |
skip_to_previous |
Skip to previous track |
like_track |
Add track to Liked Songs |
unlike_track |
Remove track from Liked Songs |
create_playlist |
Create a new playlist |
add_to_playlist |
Add tracks to a playlist |
get_top_tracks |
Get your top tracks |
get_top_artists |
Get your top artists |
set_volume |
Set playback volume (0-100) |
toggle_shuffle |
Enable/disable shuffle |
🔒 Security Notes
- Never commit your
.envfile to version control - Keep your Client Secret secure
- Refresh tokens are long-lived - store them safely
- The server uses OAuth 2.0 with automatic token refresh
📊 API Limits
Spotify Web API rate limits:
- Web API calls are rate-limited by Spotify
- Most endpoints allow several requests per second
- The server handles token refresh automatically
🐛 Troubleshooting
"No active device found"
Solution: Open Spotify on your device and play any song to activate a device.
"Invalid refresh token"
Solution: Run npm run auth again to get a new refresh token.
Tools not appearing in Claude
Solution:
- Verify the path in
claude_desktop_config.jsonis correct - Ensure all environment variables are set
- Restart Claude Desktop completely
"Premium required" errors
Solution: Some features (playback control) require Spotify Premium.
📁 Project Structure
spotify-mcp-server/
├── src/
│ ├── index.ts # Main MCP server
│ └── get-refresh-token.ts # OAuth helper script
├── dist/ # Compiled JavaScript
├── .env # Environment variables (not in repo)
├── package.json
├── tsconfig.json
└── README.md
🚀 Development
# Build the project
npm run build
# Run the OAuth helper
npm run auth
# Run in development
npm start
🧪 Technologies Used
- TypeScript: Type-safe development
- Model Context Protocol (MCP): Claude integration standard
- Spotify Web API: Music streaming service API
- OAuth 2.0: Secure authentication protocol
- Express.js: Web server for OAuth flow
- Axios: HTTP client for API requests
📜 License
MIT
👤 Author
Madhur Toshniwal
📧 Email: madhurtoshniwal03@gmail.com
🙏 Acknowledgments
- Spotify for their comprehensive Web API
- Anthropic for the Model Context Protocol
- Claude Desktop for AI integration
Built to showcase API integration, OAuth implementation, and modern development practices for campus placement interviews.
🎓 Learning Outcomes
This project demonstrates:
- OAuth 2.0 authentication flow implementation
- RESTful API integration and error handling
- Secure credential management
- Real-time data synchronization
- TypeScript for type-safe development
- MCP protocol implementation
- Asynchronous programming patterns
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。