Skip to main content
Glama

play_playlist

Start playback of a Spotify playlist by specifying its name, with optional device selection for targeted audio output.

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 main handler function for the 'play_playlist' tool. Searches for a playlist by name using the Spotify client, then plays it on the specified device.
    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, }, }; }
  • Tool schema definition including name, description, and input schema for the 'play_playlist' tool, provided 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:260-274 (registration)
    Registration and dispatch logic in the CallToolRequestSchema handler: imports playTools and calls playPlaylist function with parsed arguments.
    case 'play_playlist': const playlistResult = await playTools.playPlaylist( client, args?.playlistName as string, deviceManager.getDevice(args?.deviceId as string | undefined) ); return { content: [ { type: 'text', text: JSON.stringify(playlistResult, null, 2), }, ], };
  • Low-level SpotifyClient helper method that actually starts playback of a playlist URI using the Spotify Web API.
    async playPlaylist(playlistUri: string, deviceId?: string) { const api = await this.getApi(); await api.play({ context_uri: playlistUri, device_id: deviceId, }); }
  • Helper method in SpotifyClient to find a user's playlist by approximate name match.
    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