Spotify MCP 服务器

Spotify MCP Server 是一个连接 Claude 和 Spotify 的桥接服务,利用 Claude 的音乐知识和 Spotify 的曲库,为用户生成创意播放列表。

  • by WisetechySolutions
  • TypeScript
  • 本地部署
  • 2 星标
  • 更新于
在 GitHub 查看 WisetechySolutions/spotify-mcp-server

使用说明


Spotify MCP服务器

让克劳德成为世界上最有创意的DJ。

克劳德带来了深厚的音乐知识——流派、主题、歌词、文化联系、晦涩的引用。
Spotify带来了超过1亿首歌曲。这台服务器就是桥梁。

开始使用 · 示例 · npm


“给我制作一个关于往山上推巨石的歌曲播放列表——西西弗斯的氛围,徒劳的挣扎变得美丽。”

克劳德思考、搜索、创造。有 “美丽的徒劳” --从凯特·布什到安德鲁·伯德的20首曲目,秩序井然。

为什么存在

这与Spotify自己的推荐有何不同? Claude可以处理任何算法都无法处理的请求:

  • “引用希腊神话的歌曲”
  • “叙述者与过去的自己对话的歌曲”
  • “播放列表,告诉从第一次约会到分手的关系故事”
  • “爵士乐到电子管道——开始柔和,结束宇宙”
  • “在音乐争论中,两个对手会互相演奏的歌曲”

来自Spotify的数据。克劳德的味道。

快速开始

先决条件

  • Node.js 20+ — 下载
  • Spotify高级 -开发模式API访问所需
  • 克劳德代码 或 克劳德桌面版 --您将在何处使用服务器

1.克隆和构建

git clone https://github.com/WisetechySolutions/spotify-mcp-server.git
cd spotify-mcp-server
npm install && npm run build

2.创建Spotify应用程序

  1. 首选 Spotify开发者仪表板
  2. 点击 创建应用程序
  3. 将重定向URI设置为 http://127.0.0.1:8888/callback
  4. 复制您的 客户端ID (你不需要这个秘密——我们使用PKCE)

3.配置

cp .env.example .env
SPOTIFY_CLIENT_ID=your_client_id_here
SPOTIFY_REDIRECT_URI=http://127.0.0.1:8888/callback
TOKEN_ENCRYPTION_KEY=<generate: node -e "console.log(require('crypto').randomBytes(32).toString('hex'))">
TOKEN_STORAGE_PATH=~/.spotify-mcp/tokens.enc

4.添加到克劳德

添加到您的 .mcp.json 或 ~/.claude.json:

{
  "mcpServers": {
    "spotify": {
      "command": "node",
      "args": ["/path/to/spotify-mcp-server/dist/index.js"],
      "env": {
        "SPOTIFY_CLIENT_ID": "your_client_id",
        "SPOTIFY_REDIRECT_URI": "http://127.0.0.1:8888/callback",
        "TOKEN_ENCRYPTION_KEY": "your_64_char_hex_key",
        "TOKEN_STORAGE_PATH": "~/.spotify-mcp/tokens.enc"
      }
    }
  }
}

5.创建

"Make me a playlist of 90s songs that sound like they were written
by someone staring out a rain-covered window"

克劳德搜索Spotify,创建播放列表,添加曲目——所有这些都是自动完成的。

工具

工具 说明
search_tracks 使用丰富的查询语法搜索Spotify的目录(track:, artist:, genre:, year:)
create_playlist 使用创意名称和描述创建播放列表
add_tracks_to_playlist 按URI为每个呼叫添加最多100个曲目
remove_tracks_from_playlist 按URI删除曲目
get_playlist 获取播放列表详细信息和完整曲目列表
get_my_playlists 列出您的播放列表(分页)
disconnect_spotify 删除存储的令牌并断开连接

创意提示

指导Claude策划的内置提示模板:

提示 它做什么
create_mood_playlist 捕捉精确的情感纹理: “忧郁但充满希望”
create_thematic_playlist 文学、概念联系: “引用西西弗斯的歌曲”
discover_similar 克劳德的品味图,而不是Spotify的算法
create_narrative_playlist 有表演、高潮、决心的配乐
create_era_blend 连接两个音乐世界: “20世纪60年代摩城×20世纪20年代超级跑车”

运作原理

You → "Make me a playlist of songs about Sisyphus"
       │
       ▼
Claude (its own music knowledge):
  → Thinks of songs about futile struggle, endless repetition,
    finding meaning in the attempt
  → Kate Bush, Andrew Bird, Miley Cyrus, Emmylou Harris...
       │
       ▼
MCP Server:
  → search_tracks("track:Running Up That Hill artist:Kate Bush")
  → create_playlist("The Beautiful Futility", ...)
  → add_tracks_to_playlist(playlist_id, [...uris])
       │
       ▼
Your Spotify → New playlist with 20 perfectly curated tracks

关键设计决策: 克劳德根据自己的知识推荐。Spotify仅用于搜索和创建。没有反馈Spotify数据来告知克劳德的选择——这既是一个功能(克劳德的知识 是 值)和合规要求。

安全

  • PKCE OAuth --不需要或存储客户端机密
  • AES-256-GCM --使用您的密钥在静止时加密的令牌
  • 无数据缓存 -API响应是短暂的
  • 完整数据删除 — disconnect_spotify 删除所有令牌
  • 零生产漏洞 --通过验证 npm audit

看 安全.md 用于漏洞报告。

Spotify合规性

旨在遵守Spotify的开发者条款(2026年2月):

  • Spotify数据上没有人工智能培训 --克劳德的知识是源泉
  • 无内容缓存 --仅保留加密的身份验证令牌
  • 无流媒体或音频播放 --仅创建播放列表
  • 无DJ/混音或音频操作
  • 用途 /items 端点 -符合当前API
  • Spotify归因 --根据 品牌指南

开发模式限制

  • 需要Spotify Premium
  • 每个应用程序限制为5个测试用户
  • 每个查询的搜索结果上限为10个
  • 每个开发人员1个客户端ID

建筑

src/
├── index.ts                  # McpServer + StdioServerTransport
├── auth/
│   ├── pkce.ts               # PKCE verifier/challenge, token exchange
│   ├── token-store.ts        # AES-256-GCM encrypted token persistence
│   └── callback-server.ts    # Ephemeral localhost OAuth redirect handler
├── spotify/
│   ├── client.ts             # Auth-aware fetch wrapper, auto-refresh
│   ├── search.ts             # search_tracks implementation
│   ├── playlists.ts          # create/get/list playlists
│   └── playlist-items.ts     # add/remove tracks (uses /items)
├── tools/
│   ├── registry.ts           # MCP tool registration
│   └── schemas.ts            # Zod input validation
├── prompts/
│   └── registry.ts           # Creative playlist prompt templates
├── resources/
│   └── registry.ts           # User profile, auth status resources
└── utils/
    ├── config.ts             # Environment validation
    ├── crypto.ts             # AES-256-GCM encrypt/decrypt
    ├── error-handler.ts      # Spotify → MCP error mapping
    └── rate-limiter.ts       # Adaptive sliding window

发展

npm run build        # Compile TypeScript
npm run dev          # Watch mode
npm test             # Run 99 tests
npm run inspect      # Test with MCP Inspector

贡献

欢迎投稿!请阅读 贡献.md 在提交PR之前。

许可证

麻省理工学院 --免费用于个人和商业用途。

免责声明

本项目与Spotify AB或Anthropic PBC没有附属关系、认可或关联。“Spotify”是Spotify AB的注册商标。所有Spotify数据均通过官方网站访问 Spotify Web API 根据他们的开发者服务条款。


与 模型上下文协议 和那个 Spotify Web API

智慧解决方案