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
| Name | Required | Description | Default |
|---|---|---|---|
| albumName | Yes | Name of the album to play | |
| artistName | No | Optional artist name to help find the album | |
| deviceId | No | Optional device ID to play on |
Implementation Reference
- src/tools/play.ts:21-41 (handler)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), }, ], };
- src/server.ts:70-90 (schema)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'], }, },
- src/spotify/client.ts:113-119 (helper)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, }); }
- src/spotify/client.ts:53-63 (helper)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, })) || []; }