Skip to main content
Glama

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
NameRequiredDescriptionDefault
playlistNameYesName of the playlist to play
deviceIdNoOptional device ID to play on

Implementation Reference

  • 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, }, }; }
  • 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), }, ], };
  • 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, }); }
  • 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; }

Latest Blog Posts

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/Ackberry/spotify_mcp'

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