Spotify音乐控制服务器

基于Spotify OAuth和MCP协议的Python服务器,提供Spotify音乐播放控制和管理功能。

  • by EvansLR
  • Python
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 EvansLR/spotify-mcp

使用说明

Spotify MCP Server

A Python server based on Spotify OAuth and MCP protocols, providing Spotify music control functionality.

Features

  • ✅ Spotify OAuth Authentication
  • ✅ Get the current playback status
  • ✅ Play/Pause Control
  • ✅ Previous/Next Switch
  • ✅ Volume Control
  • ✅ Play position jump
  • ✅ Equipment Management

install

  1. Installation dependencies:
pip install -e .
  1. Configure Spotify OAuth credentials:

    • visit Spotify Developer Dashboard
    • Create an application and obtain it Client ID and Client Secret
    • Set the redirect URI to http://127.0.0.1:8000/callback
  2. Set environment variables:

export SPOTIFY_CLIENT_ID="your_client_id"
export SPOTIFY_CLIENT_SECRET="your_client_secret"
export SPOTIFY_REDIRECT_URI="http://127.0.0.1:8000/callback"  # 可选,默认值

Instructions for use

1. Start MCP server

The server communicates through STDio and is usually automatically started by MCP clients (such as Claude Desktop).

2. First certification

  1. invoke spotify_get_auth_url Tool to obtain authorization URL
  2. Accessing the URL in the browser and completing authorization
  3. Extract authorization code from callback URL(codeParameters)
  4. invoke spotify_authenticate Tool, pass in authorization code to complete authentication

The authentication information will be saved in ~/.spotify_mcp_token.jsonSubsequent use will automatically refresh the token.

3. Use control functions

After successful authentication, the following tools can be used:

  • spotify_get_current_playback -Get the current playback status
  • spotify_pause -Pause playback
  • spotify_next -Next song
  • spotify_previous -Previous song
  • spotify_set_volume -Set volume (0-100)
  • spotify_seek -Jump to the specified location
  • spotify_get_devices -Get the list of available devices
  • spotify_play_artist -Search and play the top 10 tracks of a specified artist, such as' Taylor Swift's songs'
  • spotify_play_song -Play songs based on the singer and song title. For example, playing Taylor Swift's Love Story

MCP client configuration

Add:

{
  "mcpServers": {
    "spotify-mcp": {
      "command": "python",
      "args": ["-m", "spotify_mcp"],
      "env": {
        "SPOTIFY_CLIENT_ID": "your_client_id",
        "SPOTIFY_CLIENT_SECRET": "your_client_secret",
        "SPOTIFY_REDIRECT_URI"="http://127.0.0.1:8000/callback"
      }
    }
  }
}

Or use UV

{
  "mcpServers": {
    "spotify-mcp": {
      "command": "uv",
      "args": ["run", "-m", "spotify_mcp"],
      "env": {
        "SPOTIFY_CLIENT_ID": "your_client_id",
        "SPOTIFY_CLIENT_SECRET": "your_client_secret",
        "SPOTIFY_REDIRECT_URI"="http://127.0.0.1:8000/callback"

      }
    }
  }
}

Precautions

  • Ensure that the Spotify app is turned on and playing music
  • Some features require a Spotify Premium account
  • Token will automatically refresh, no need to manually re authenticate
  • The device ID parameter is optional, and if not specified, the current active device will be used

license

MIT