Skip to main content
Glama

Spotify MCP 服务器

一个基于 Node.js 的服务器,集成了 Spotify Web API 和模型上下文协议 (MCP),提供用于搜索、控制播放和管理 Spotify 内容的工具。它允许用户通过 stdio 传输上的标准化 MCP 接口,以编程方式与其 Spotify 帐户进行交互。


🧠 项目概述

名称: Spotify MCP 服务器
**描述:**一个可编程接口,将 Spotify Web API 与 MCP 标准连接起来,通过 stdio 使用基于 JSON 的工具实现搜索、播放控制和播放列表管理。
主要特点:

  • 🔍 在 Spotify 上搜索曲目

  • 🎵 检查当前播放状态

  • ▶️ 通过 URI 播放特定曲目

  • 📋 检索用户播放列表

  • ⏸ 暂停正在进行的播放

  • 🔐 使用 Spotify 进行 OAuth 身份验证

  • 📉 Spotify API 请求的速率限制处理


⚙️ 先决条件


📦安装步骤

# 1. Clone the repository git clone <repository-url> cd spotify-mcp # 2. Install dependencies npm install # 3. Create a .env file and add the following:
SPOTIFY_CLIENT_ID=your_spotify_client_id SPOTIFY_CLIENT_SECRET=your_spotify_client_secret SPOTIFY_REDIRECT_URI=http://localhost:8888/callback

**注意:**请将your_spotify_client_idyour_spotify_client_secret替换为您的 Spotify 开发者应用凭据。重定向 URI 必须与您的 Spotify 应用设置中设置的 URI 匹配。

# 4. Build npm run build # 5. Run the server npm start

这将打开浏览器进行 Spotify 身份验证并使用 stdio 传输启动服务器。


🔧 工具

1. search_tracks

  • **描述:**根据查询字符串在 Spotify 上搜索曲目。

  • 输入模式:

    • query (字符串,必需):搜索词(例如,艺术家姓名、歌曲标题)。

  • **输出:**最多 5 个曲目对象的 JSON 数组,包括nameartistalbumrelease_datepopularityiduri

  • 例子:

{ "name": "search_tracks", "arguments": {"query": "The Beatles"} }

2. get_playback_state

  • **描述:**检索用户 Spotify 帐户的当前播放状态。

  • **输入模式:**无

  • **输出:**包含当前曲目信息、播放状态和设备详细信息的 JSON 对象,如果没有播放任何内容,则输出“无活动播放”。

  • 例子:

{ "name": "get_playback_state", "arguments": {} }

3. play_track

  • **描述:**使用 Spotify URI 播放特定曲目。

  • 输入模式:

    • uri (字符串,必需):Spotify 曲目 URI(例如, spotify:track:xxx )。

  • **输出:**带有statusuri JSON 确认。

  • 例子:

{ "name": "play_track", "arguments": {"uri": "spotify:track:7KXjTSCq5nL1LoYtL7XAwS"} }

4. get_user_playlists

  • **描述:**从 Spotify 获取用户的播放列表。

  • 输入模式:

    • limit (数字,可选):返回的播放列表的最大数量(默认值:20)。

  • **输出:**具有nameidtrack_counturipublic状态的播放列表对象的 JSON 数组。

  • 例子:

{ "name": "get_user_playlists", "arguments": {"limit": 10} }

5. pause_playback

  • **描述:**暂停用户活动 Spotify 设备上的当前播放。

  • **输入模式:**无

  • 输出: JSON 确认“播放暂停”状态。

  • 例子:

{ "name": "pause_playback", "arguments": {} }

🌐 用例

  1. 音乐发现机器人:

    • 使用search_tracksplay_track实现基于心情的音乐聊天机器人。

  2. 播放列表管理工具:

    • 使用get_user_playlistssearch_tracks来预览和组织播放列表。

  3. 播放控制自动化:

    • 使用get_playback_stateplay_trackpause_playback自动执行播放操作。

  4. Spotify 仪表板:

    • 使用get_playback_stateget_user_playlistspause_playbackplay_track构建桌面小部件。

  5. 学习Spotify API:

    • 尝试使用所有工具来了解 Spotify Web API 的工作原理。


🔐 身份验证详细信息

  • 首次运行时,服务器会打开浏览器进行 Spotify OAuth 身份验证。

  • 通过http://localhost:8888/callback接收代码。

  • 交换访问和刷新令牌的代码。

  • 在到期后 5 分钟内自动刷新令牌。


⏱ 速率限制

  • 使用重试策略处理 Spotify API 速率限制:

    • 每次请求后有 10 秒的冷却时间。

    • 如果发生 429 请求过多错误,则需要等待 1 分钟。


📊 依赖项

npm install dotenv spotify-web-api-node @modelcontextprotocol/sdk open
  • dotenv :从.env加载环境变量。

  • spotify-web-api-node :Spotify API 客户端。

  • @modelcontextprotocol/sdk :实现 MCP 服务器。

  • httpurl :OAuth 重定向服务器的 Node.js 内置函数。

  • open :打开默认浏览器进行身份验证。


📁 开发信息

  • 入口点: index.js

  • 语言: JavaScript(带有 ES 模块的 Node.js)

  • 运行命令: node index.js

  • **调试:**检查控制台日志是否存在 MCP 或身份验证错误。


⚠️ 限制

  • 播放控制需要 Spotify Premium。

  • 仅支持 stdio 传输(不支持 HTTP、WebSocket 等)。

  • search_tracks最多返回 5 个结果。

  • 假设有一个活动设备用于播放。


🚀 贡献

欢迎随时提出问题或提交拉取请求至:

  • 添加新工具

  • 增强现有功能

  • 改进文档


✍️ 许可证

MIT 许可证 — 可免费使用、修改和分发用于个人或商业用途。


❤️ 页脚

由 Rakshitha C Devadiga 于 2025 年 3 月 17 日用 ❤️ 打造

-
security - not tested
F
license - not found
-
quality - not tested

Related MCP Servers

  • A
    security
    A
    license
    A
    quality
    Enables interaction with Spotify's music catalog via the Spotify Web API, supporting searches, artist information retrieval, playlist management, and automatic token handling.
    Last updated -
    547
    18
    MIT License
  • -
    security
    F
    license
    -
    quality
    Enables interaction with the Audius music platform API, supporting user, track, and playlist operations through the Model Context Protocol.
    Last updated -
    4
    • Apple
  • A
    security
    F
    license
    A
    quality
    A lightweight Model Context Protocol server that enables AI assistants like Cursor & Claude to control Spotify playback and manage playlists.
    Last updated -
    18
    186
  • -
    security
    F
    license
    -
    quality
    A Model Context Protocol server that enables AI assistants like Claude to interact with Spotify, allowing them to search for tracks, control playback, and manage playlists.
    Last updated -
    1
    • Apple

View all related MCP servers

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/rakshitha2207/spotify-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server