Spotify MCP

Spotify MCP

A FastMCP server that enables searching tracks, controlling playback (play, pause, skip), and retrieving currently playing content on Spotify via PKCE authentication.

Category
访问服务器

README

Spotify MCP

A minimal FastMCP server for Spotify with Authorization Code + PKCE auth.

Features

  • Search Spotify tracks with search_song
  • Control playback with play, pause, skip_forward, and skip_backwards
  • Read currently playing content with get_currently_playing
  • Create playlists with create_playlist
  • Add songs to playlists with add_songs_to_playlist
  • Build vibe playlists with create_vibe_playlist
  • PKCE login flow with local loopback callback
  • Tokens stored in the OS keyring
  • Automatic access-token refresh

Prerequisites

Spotify App Setup

  1. Create an app in the Spotify Developer Dashboard.
  2. Add this redirect URI:
    • http://127.0.0.1:8888/callback
  3. Do not use http://localhost.
  4. Copy your Client ID.

Local Setup

python -m venv .venv
.venv\Scripts\activate
pip install -e .
copy .env.example .env

Edit .env:

SPOTIFY_CLIENT_ID=your_client_id_here
SPOTIFY_REDIRECT_URI=http://127.0.0.1:8888/callback

Login (PKCE)

Run once before using the MCP tools:

python -m spotify_mcp.auth login

This opens your browser, completes Spotify authorization, and stores tokens in your OS keyring.

By default, login requests the minimum scopes needed by the current tools:

  • user-read-currently-playing
  • user-modify-playback-state
  • playlist-modify-private
  • playlist-modify-public

If you logged in before playback or playlist tools were added, run login again so Spotify grants the new scopes.

If login times out waiting for the callback:

  • Make sure the Spotify Developer Dashboard has the exact redirect URI http://127.0.0.1:8888/callback.
  • Complete the authorization page in the browser before the timeout.
  • Keep the terminal running until Spotify redirects back to 127.0.0.1.
  • If you need more time, run python -m spotify_mcp.auth login --timeout 600.

To remove stored tokens:

python -m spotify_mcp.auth logout

Run the MCP Server

python -m spotify_mcp.server

Or:

spotify-mcp

Cursor MCP Config

Add this to your Cursor MCP settings (.cursor/mcp.json or Cursor Settings > MCP):

{
  "mcpServers": {
    "spotify": {
      "command": "C:\\Users\\vihoh\\Coding Projects\\Spotify-MCP\\.venv\\Scripts\\python.exe",
      "args": ["-m", "spotify_mcp.server"],
      "cwd": "C:\\Users\\vihoh\\Coding Projects\\Spotify-MCP"
    }
  }
}

Adjust the Python path if your virtual environment lives elsewhere.

Tool: search_song

Searches Spotify tracks via GET /v1/search with type=track.

Parameters:

  • query (required): search text
  • limit (optional, default 5, range 0-10)
  • market (optional): ISO country code
  • offset (optional, default 0, range 0-1000)

Example prompt in Cursor:

Use search_song to find "Blinding Lights" by The Weeknd.

Playback Tools

Playback endpoints require a Spotify Premium account and an active Spotify device.

  • play(device_id: str | None = None): resume playback.
  • pause(device_id: str | None = None): pause playback.
  • skip_forward(device_id: str | None = None): skip to the next track.
  • skip_backwards(device_id: str | None = None): skip to the previous track.
  • get_currently_playing(market: str | None = None, additional_types: str | None = None): get the current track or episode.

Example prompts in Cursor:

Use get_currently_playing to tell me what's playing.
Pause Spotify.

Playlist Tools

Playlist endpoints use:

  • POST /v1/me/playlists to create playlists
  • POST /v1/playlists/{playlist_id}/items to add tracks
  • GET /v1/search with type=track to resolve song queries

Tools:

  • create_playlist(name, description=None, public=False, collaborative=False): create an empty playlist.
  • add_songs_to_playlist(playlist_id, song_queries, market=None): search for each query and add the best match.
  • create_vibe_playlist(name, vibe, song_queries, description=None, public=False, market=None): create a playlist and add matched songs for a vibe.

Vibe playlist workflow

The LLM should turn your vibe prompt into a list of song_queries, then call create_vibe_playlist.

Example prompt in Cursor:

Create a late-night rainy drive playlist with create_vibe_playlist.
Use a name like "Rainy Night Drive" and pick about 15 songs that fit the vibe.

The LLM might call:

create_vibe_playlist(
  name="Rainy Night Drive",
  vibe="late-night rainy drive, mellow and atmospheric",
  song_queries=[
    "The Weeknd Blinding Lights",
    "Frank Ocean Pink + White",
    "Tame Impala The Less I Know The Better"
  ],
  public=false
)

If some queries do not match, the tool returns unresolved_queries for the ones it could not find.

Notes

  • Search uses PKCE user auth even though catalog search is public data. This keeps auth ready for playlist and library tools.
  • Playback uses Spotify's documented Player endpoints.
  • Playlist tools request playlist-modify-private and playlist-modify-public.
  • This project does not use deprecated Spotify recommendation or audio-features endpoints for vibe playlists.
  • If auth expires or is revoked, run python -m spotify_mcp.auth login again.
  • Spotify content is attributed in tool responses and not cached beyond immediate use.

Project Layout

src/spotify_mcp/
  auth.py           # PKCE login, token storage, refresh helpers
  spotify_client.py # Spotify API requests and error handling
  server.py         # FastMCP server and tools

License

Use in compliance with the Spotify Developer Terms.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选