Back to MCP directory
publicPublicdnsLocal runtime

spotify-mcp

一个基于MCP协议的Spotify服务端,允许通过Claude与Spotify账户交互,实现搜索歌曲、创建播放列表、获取推荐等功能。

article

README

🚀 Spotify MCP 服务器

这是一个简单的模型上下文协议(MCP)服务器,可让你通过 Claude 与 Spotify 进行交互。该服务器使 Claude 能够使用你的 Spotify 账户搜索歌曲、创建播放列表、获取推荐等。

✨ 主要特性

  • 在 Spotify 上搜索曲目
  • 查看你的 Spotify 个人资料
  • 创建播放列表
  • 向播放列表添加曲目
  • 获取个性化音乐推荐

📚 详细文档

可用工具

| 属性 | 详情 | | ---- | ---- | | 工具名称 | 描述 | | set-spotify-credentials | 设置你的 Spotify 认证凭证 | | check-credentials-status | 检查你的凭证是否有效以及当前登录的用户 | | search-tracks | 按名称、艺术家或关键词搜索曲目 | | get-current-user | 获取你的 Spotify 个人资料信息 | | create-playlist | 在你的账户上创建一个新的播放列表 | | add-tracks-to-playlist | 向现有播放列表添加曲目 | | get-recommendations | 根据种子曲目获取推荐 |

📦 安装指南

1. 前提条件

  • Node.js v16 或更高版本
  • npm
  • 一个 Spotify 账户
  • 一个已注册的 Spotify 开发者应用程序

2. 创建 Spotify 开发者应用

  1. 访问 Spotify 开发者控制台
  2. 使用你的 Spotify 账户登录
  3. 点击“创建应用”
  4. 填写应用名称和描述
  5. 添加 http://localhost:8888/callback 作为重定向 URI
  6. 记录你的客户端 ID 和客户端密钥

3. 安装项目

# 首先克隆或下载项目
cd spotify-mcp-server

# 安装依赖项
npm install

4. 获取你的 Spotify 令牌

编辑 spotify-auth.js 文件,包含你的客户端 ID 和客户端密钥:

// 用你的 Spotify 应用凭证替换这些内容
const CLIENT_ID = "your_client_id_here";
const CLIENT_SECRET = "your_client_secret_here";

然后运行认证脚本:

node spotify-auth.js

这将:

  1. 在你的浏览器中打开一个 URL
  2. 提示你登录 Spotify
  3. 请求你允许访问你的账户
  4. 将令牌保存到 secrets.json

5. 构建 MCP 服务器

npm run build

6. 配置 Claude 桌面应用

编辑你的 Claude 桌面应用配置文件:

  • 在 macOS 上:~/Library/Application Support/Claude/claude_desktop_config.json
  • 在 Windows 上:%APPDATA%\Claude\claude_desktop_config.json 添加以下配置:
{
  "mcpServers": {
    "spotify": {
      "command": "node",
      "args": ["/full/path/to/spotify-mcp-server/build/spotify-mcp-server.js"]
    }
  }
}

/full/path/to/spotify-mcp-server 替换为你项目目录的实际路径。

7. 重启 Claude 桌面应用

关闭并重新打开 Claude 桌面应用以加载新配置。

💻 使用示例

基础用法

当你开始与 Claude 对话时,你首先需要设置你的 Spotify 凭证:

  1. 查看你的 secrets.json 文件以获取凭证
  2. 使用 set-spotify-credentials 工具进行认证
  3. 然后使用任何其他 Spotify 工具

示例提示

设置凭证

我想连接到我的 Spotify 账户。以下是我从 secrets.json 中获取的凭证:

工具: set-spotify-credentials
参数:
{
  "clientId": "your_client_id",
  "clientSecret": "your_client_secret",
  "accessToken": "your_access_token",
  "refreshToken": "your_refresh_token"
}

基本命令

检查你的账户:

你能检查我在 Spotify 上以谁的身份登录吗?

工具: get-current-user
参数: {}

搜索曲目:

搜索 The Weeknd 的歌曲

工具: search-tracks
参数:
{
  "query": "Taylor Swift",
  "limit": 5
}

创建播放列表:

创建一个名为 "My Pretty pretty girlfriend" 的新播放列表

工具: create-playlist
参数:
{
  "name": "My Pretty pretty girlfriend",
  "description": "For my girlfriend. Created with Claude and the Spotify MCP server"
}

多步骤任务

创建一个包含歌曲的播放列表:

我想创建一个包含活力歌曲的健身播放列表。首先,搜索一些高能量的歌曲。然后创建一个名为 "Workout Mix" 的播放列表并将这些歌曲添加到其中。

根据喜爱的歌曲获取推荐:

我喜欢 The Weeknd 的歌曲 "Blinding Lights"。你能搜索这首歌,然后找到相似的歌曲,并创建一个包含这些推荐的播放列表吗?

🔧 技术细节

故障排除

  • 错误:没有可用的访问令牌:你需要首先使用 set-spotify-credentials 工具设置你的凭证
  • 认证失败:你的令牌可能已过期。再次运行认证脚本以获取新的令牌
  • 无效的凭证:仔细检查你使用的客户端 ID 和客户端密钥是否正确

注意事项

  • 服务器仅将凭证存储在内存中
  • 每次开始新对话时,你都需要设置凭证
  • 如果 Claude 桌面应用重启,你需要再次设置凭证
help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client