Skip to main content
Glama

play_album

Play a Spotify album by specifying its name, with optional artist name for accuracy and device selection for targeted playback.

Instructions

Play a Spotify album by name and optional artist

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
albumNameYesName of the album to play
artistNameNoOptional artist name to help find the album
deviceIdNoOptional device ID to play on

Implementation Reference

  • Main handler function for 'play_album' tool. Searches for album by name (with optional artist), plays it via SpotifyClient, returns formatted response.
    export async function playAlbum(client: SpotifyClient, albumName: string, artistName?: string, deviceId?: string) { const query = artistName ? `${albumName} artist:${artistName}` : albumName; const results = await client.searchAlbums(query, 1); if (results.length === 0) { throw new Error(`Album "${albumName}" not found`); } const album = results[0]; await client.playAlbum(album.uri, deviceId); return { success: true, message: `Playing album: ${album.name} by ${album.artist}`, album: { id: album.id, name: album.name, artist: album.artist, }, }; }
  • src/server.ts:237-252 (registration)
    Registration and dispatching of 'play_album' tool in the CallToolRequestSchema handler switch statement.
    case 'play_album': const albumResult = await playTools.playAlbum( client, args?.albumName as string, args?.artistName as string | undefined, args?.deviceId as string | undefined ); return { content: [ { type: 'text', text: JSON.stringify(albumResult, null, 2), }, ], };
  • Tool schema definition for 'play_album' in the ListToolsRequestSchema response, including input schema.
    name: 'play_album', description: 'Play a Spotify album by name and optional artist', inputSchema: { type: 'object', properties: { albumName: { type: 'string', description: 'Name of the album to play', }, artistName: { type: 'string', description: 'Optional artist name to help find the album', }, deviceId: { type: 'string', description: 'Optional device ID to play on', }, }, required: ['albumName'], }, },
  • SpotifyClient helper method that actually plays the album URI via Spotify Web API.
    async playAlbum(albumUri: string, deviceId?: string) { const api = await this.getApi(); await api.play({ context_uri: albumUri, device_id: deviceId, }); }
  • SpotifyClient searchAlbums method used by playAlbum handler to find the album.
    async searchAlbums(query: string, limit: number = 10) { const api = await this.getApi(); const data = await api.searchAlbums(query, { limit }); return data.body.albums?.items.map((album: any) => ({ id: album.id, name: album.name, artist: album.artists[0]?.name || 'Unknown', uri: album.uri, })) || []; }

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