Spotify播放控制服务

Spotify MCP Server是一个通过Claude Desktop控制Spotify播放和管理播放列表的服务,支持播放、暂停、跳过曲目、调节音量、创建播放列表等功能。

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

使用说明

Spotify MCP服务器

概述

Claude Desktop的Spotify MCP服务器允许您使用模型上下文协议(MCP)直接从Claude Desktop控制Spotify播放和管理播放列表。支持的操作包括播放歌曲、暂停/恢复播放、跳过曲目、设置音量、创建播放列表、将歌曲添加到播放列表以及检索播放信息。

先决条件

  • 克劳德桌面:版本0.12.28或更高版本。
  • python:版本3.13或更高版本(安装于 C:\Users\anush\AppData\Local\Programs\Python\Python313\python.exe).
  • Spotify帐户:具有活动设备(例如Spotify桌面或移动应用程序)的Spotify帐户。
  • Spotify开发者证书:
    • 获得 client_id 和 client_secret 从Spotify开发者仪表板。
    • 确保Spotify应用程序配置了重定向URI: http://127.0.0.1:8080/callback.

安装

  1. 安装Python依赖项:

    • 打开命令提示符并导航到扩展目录:

      cd C:\Users\anush\AppData\Local\AnthropicClaude\app-0.12.28
      
    • 安装所需的Python包:

      C:\Users\anush\AppData\Local\Programs\Python\Python313\python.exe -m pip install fastapi uvicorn requests
      
  2. 设置扩展文件:

    • 创建扩展目录:

      mkdir C:\Users\anush\AppData\Local\AnthropicClaude\app-0.12.28\extensions\spotify
      
    • 将以下文件放入 C:\Users\anush\AppData\Local\AnthropicClaude\app-0.12.28\extensions\spotify:

      • main.py:主MCP服务器脚本(请参阅存储库或提供的代码)。
      • auth.py:处理Spotify OAuth身份验证。
      • spotify_api.py:与Spotify API互动。
      • utils.py:实用程序功能(例如,令牌刷新)。
      • token_store.py:管理用户身份验证令牌。
    • 创建 manifest.json 在同一目录中:

      {
        "name": "Spotify",
        "version": "1.0.0",
        "description": "Spotify control extension for Claude Desktop",
        "mcp_server": "spotify"
      }
      
  3. 配置Claude桌面:

    • 创建或编辑 C:\Users\anush\AppData\Roaming\Claude\claude_desktop_config.json:

      {
        "mcpServers": {
          "spotify": {
            "command": "C:\\Users\\anush\\AppData\\Local\\Programs\\Python\\Python313\\python.exe",
            "args": [
              "C:\\Users\\anush\\AppData\\Local\\AnthropicClaude\\app-0.12.28\\main.py",
              "--client-id",
              "your_client_id_here",
              "--client-secret",
              "your_client_secret_here"
            ],
            "env": {
              "PYTHONPATH": "C:\\Users\\anush\\AppData\\Local\\Programs\\Python\\Python313\\Lib\\site-packages"
            }
          }
        }
      }
      
      • 替换 your_client_id_here 和 your_client_secret_here 使用您的Spotify凭据。
      • 确保路径使用双反斜杠(\\)为了Windows兼容性。
      • 在JSONLint中验证JSON语法。
      • 通过限制访问来保护文件(右键单击>属性>安全>限制您的用户帐户)。

用法

  1. 启动克劳德桌面:

    • 启动克劳德桌面(版本0.12.28)。
    • 确保Spotify扩展已加载(检查输入框左下角的滑块图标)。
    • 验证 设置>开发人员>扩展 Spotify扩展已列出。
  2. 通过Spotify进行身份验证:

    • 如果不存在有效的令牌,请手动运行服务器以获取登录URL:

      cd C:\Users\anush\AppData\Local\AnthropicClaude\app-0.12.28
      C:\Users\anush\AppData\Local\Programs\Python\Python313\python.exe main.py --client-id your_client_id_here --client-secret your_client_secret_here
      
    • 在输出中查找身份验证URL:

      --- SPOTIFY AUTHENTICATION REQUIRED ---
      Please open this URL in your browser to log in to Spotify:
      https://accounts.spotify.com/authorize?client_id=...&response_type=code&redirect_uri=http%3A%2F%2F127.0.0.1%3A8080%2Fcallback&scope=...
      
    • 在浏览器中打开URL,登录Spotify,并授权该应用程序。

    • 回调将把令牌保存到 user_tokens.json.

  3. 控制Spotify:

    • 在Claude Desktop中,使用以下命令:
      • “播放歌曲Loverboy”
      • “暂停播放”
      • “创建一个名为Summer Hits的播放列表”
      • “在周末为夏季热门歌曲添加致盲灯光”
      • “将音量设置为50”
    • 确保Spotify在活动设备上运行。
  4. 通过命令行进行测试 (可选):

    cd C:\Users\anush\AppData\Local\AnthropicClaude\app-0.12.28
    echo '{"jsonrpc": "2.0", "method": "tools/call", "params": {"name": "play_song", "arguments": {"song_title": "Loverboy"}}, "id": 9}' | C:\Users\anush\AppData\Local\Programs\Python\Python313\python.exe main.py --client-id your_client_id_here --client-secret your_client_secret_here
    

支持的工具

  • play_song(song_title, artist?):播放歌曲(为准确起见,艺术家可选)。
  • pause_playback():暂停当前播放。
  • resume_playback():恢复暂停的播放。
  • skip_track():跳到下一首曲目。
  • previous_track():返回上一曲目。
  • set_volume(volume_percent):设置音量(0-100)。
  • create_playlist(playlist_name, public?):创建播放列表(公共默认为true)。
  • add_to_playlist(song_title, playlist_name, artist?):将歌曲添加到播放列表中。
  • get_current_playback_info():检索当前歌曲和播放状态。

支持

有关问题,请参阅MCP调试文档或分享:

  • mcp-server-Spotify.log (编辑敏感数据)。
  • 来自Claude Desktop或命令行的相关错误消息。