Spotify MCP Server

Spotify MCP Server

Enables control of Spotify playback, search, and playlist management through MCP tools and Apple Shortcuts/Siri integration via HTTP bridge.

Category
访问服务器

README

Spotify MCP Server with Siri Integration

A Model Context Protocol (MCP) server that exposes Spotify functionality for seamless integration with Siri via Apple Shortcuts.

Features

  • Play Control: Play playlists, albums, and tracks
  • Search: Find music by song, artist, or album
  • Playback Control: Play, pause, skip, and adjust volume
  • Sleep Timer: Automatically pause playback after a specified duration
  • Siri Integration: HTTP bridge for Apple Shortcuts

Prerequisites

  • Node.js 18+
  • npm or yarn
  • Spotify Developer account
  • TypeScript 5.3+

Setup

1. Spotify Developer Setup

  1. Go to Spotify Developer Dashboard
  2. Create a new app
  3. Note your Client ID and Client Secret
  4. Add a redirect URI: http://localhost:3000/callback (or your preferred URI)

2. Project Setup

  1. Clone or download this repository

  2. Install dependencies:

    npm install
    
  3. Create a .env file in the root directory:

    SPOTIFY_CLIENT_ID=your_client_id_here
    SPOTIFY_CLIENT_SECRET=your_client_secret_here
    SPOTIFY_REDIRECT_URI=http://localhost:3000/callback
    HTTP_BRIDGE_PORT=3001
    HTTP_BRIDGE_API_KEY=your_optional_api_key_here
    
  4. Build the project:

    npm run build
    

3. Authentication

  1. Start the server:

    npm start
    
  2. The server will guide you through the OAuth flow if you're not authenticated

  3. Visit the provided authorization URL

  4. Authorize the app and copy the callback code

  5. The tokens will be saved automatically in tokens.json

Usage

MCP Server

The MCP server runs on stdio and can be used with MCP-compatible clients:

npm start

HTTP Bridge (for Siri/Shortcuts)

The HTTP bridge exposes REST endpoints for Apple Shortcuts:

npm run bridge

API Endpoints

All endpoints support optional API key authentication via:

  • Header: Authorization: Bearer <api_key>
  • Query parameter: ?apiKey=<api_key>

Play Endpoints

POST /play/playlist

{
  "playlistName": "My Playlist",
  "deviceId": "optional_device_id"
}

POST /play/album

{
  "albumName": "Album Name",
  "artistName": "Artist Name",
  "deviceId": "optional_device_id"
}

POST /play/track

{
  "trackName": "Song Name",
  "artistName": "Artist Name",
  "deviceId": "optional_device_id"
}

Search

GET /search?q=query&limit=10

Returns search results for tracks, albums, and artists.

Playback Control

POST /control

{
  "action": "play|pause|skip-next|skip-previous|volume",
  "value": 50,
  "deviceId": "optional_device_id"
}

GET /now-playing

Returns information about the currently playing track.

Timer

POST /timer/set

{
  "durationMinutes": 30
}

POST /timer/cancel

{
  "timerId": "optional_timer_id"
}

GET /timer/list

Returns all active timers.

Health

GET /health

Check server status and authentication state.

Apple Shortcuts Integration

Setting Up Shortcuts

  1. Open the Shortcuts app on your iPhone/iPad

  2. Create a new shortcut

  3. Add a "Get Contents of URL" action

  4. Configure:

    • Method: POST (or GET for search/now-playing)
    • URL: http://your-server-ip:3001/play/playlist
    • Headers:
      • Content-Type: application/json
      • Authorization: Bearer <your_api_key> (if using API key)
    • Request Body: JSON with required parameters
  5. Add a "Get Text from Input" action to parse the response

  6. Add "Speak Text" action to have Siri confirm the action

Example Shortcut: Play Playlist

  1. Create shortcut named "Play My Playlist"
  2. Add input action to get playlist name from Siri
  3. Add "Get Contents of URL":
    • URL: http://your-server-ip:3001/play/playlist
    • Method: POST
    • Body: {"playlistName": "[Shortcut Input]"}
  4. Add "Speak Text" to confirm

Example Voice Commands

  • "Hey Siri, play my workout playlist"
  • "Hey Siri, pause Spotify"
  • "Hey Siri, set a 30 minute sleep timer"
  • "Hey Siri, what's playing on Spotify?"
  • "Hey Siri, play [song name] by [artist]"

Running the Server for Shortcuts

For local network access:

  1. Find your Mac's IP address: ifconfig | grep "inet "
  2. Use that IP in Shortcuts: http://192.168.1.x:3001/...
  3. Ensure your Mac's firewall allows connections on port 3001

For internet access, deploy the server to a cloud provider.

MCP Tools

The server exposes the following MCP tools:

  • play_playlist - Play a playlist by name
  • play_album - Play an album by name
  • play_track - Play a track by name
  • search_music - Search for music
  • control_playback - Control playback (play, pause, skip, volume)
  • get_current_playing - Get currently playing track
  • set_sleep_timer - Set a sleep timer
  • cancel_sleep_timer - Cancel active timers
  • get_active_timers - List active timers

Development

# Development mode with auto-reload
npm run dev

# Build TypeScript
npm run build

# Run MCP server
npm start

# Run HTTP bridge
npm run bridge

Project Structure

src/
  server.ts              # MCP server entry point
  http-bridge.ts         # HTTP server for Shortcuts
  spotify/
    auth.ts             # OAuth authentication
    client.ts           # Spotify API client
  tools/
    play.ts             # Play operations
    search.ts           # Search operations
    playback.ts         # Playback control
    timer.ts            # Timer operations
  timer.ts              # Timer manager
  types.ts              # Type definitions

Troubleshooting

Authentication Issues

  • Ensure your redirect URI matches exactly in Spotify Dashboard
  • Check that tokens.json is created and contains valid tokens
  • Re-authenticate by deleting tokens.json and restarting

Device Not Found

  • Make sure a Spotify device is active (app open and playing)
  • Use the device selection in the Spotify app
  • Check device availability via Spotify API

Connection Issues

  • Verify the HTTP bridge port (default: 3001) is not blocked
  • Check firewall settings
  • Ensure the server is accessible on your network

License

MIT

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选