play_playlist
Start playback of a specified Spotify playlist by name, optionally directing it to a chosen device for immediate listening.
Instructions
Play a Spotify playlist by name
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| playlistName | Yes | Name of the playlist to play | |
| deviceId | No | Optional device ID to play on |
Implementation Reference
- src/tools/play.ts:3-19 (handler)The primary handler function for the 'play_playlist' tool. It locates a playlist by name using the SpotifyClient and initiates playback, returning success details.export async function playPlaylist(client: SpotifyClient, playlistName: string, deviceId?: string) { const playlist = await client.findPlaylistByName(playlistName); if (!playlist) { throw new Error(`Playlist "${playlistName}" not found`); } await client.playPlaylist(playlist.uri, deviceId); return { success: true, message: `Playing playlist: ${playlist.name}`, playlist: { id: playlist.id, name: playlist.name, }, }; }
- src/server.ts:52-68 (schema)The input schema and metadata (name, description) for the 'play_playlist' tool, defined in the ListTools response.name: 'play_playlist', description: 'Play a Spotify playlist by name', inputSchema: { type: 'object', properties: { playlistName: { type: 'string', description: 'Name of the playlist to play', }, deviceId: { type: 'string', description: 'Optional device ID to play on', }, }, required: ['playlistName'], }, },
- src/server.ts:222-236 (registration)Registration of the 'play_playlist' tool handler in the CallToolRequest switch statement, dispatching to the playTools.playPlaylist function.case 'play_playlist': const playlistResult = await playTools.playPlaylist( client, args?.playlistName as string, args?.deviceId as string | undefined ); return { content: [ { type: 'text', text: JSON.stringify(playlistResult, null, 2), }, ], };
- src/spotify/client.ts:105-111 (helper)Helper method in SpotifyClient that performs the actual Spotify API call to play a playlist URI.async playPlaylist(playlistUri: string, deviceId?: string) { const api = await this.getApi(); await api.play({ context_uri: playlistUri, device_id: deviceId, }); }
- src/spotify/client.ts:28-38 (helper)Helper method in SpotifyClient used by the handler to find a playlist by approximate name match.async findPlaylistByName(name: string): Promise<PlaylistInfo | null> { const playlists = await this.getCurrentUserPlaylists(); const normalizedName = name.toLowerCase().trim(); const playlist = playlists.find(p => p.name.toLowerCase().includes(normalizedName) || normalizedName.includes(p.name.toLowerCase()) ); return playlist || null; }