play_album
Play a Spotify album by specifying its name and optionally the artist to start listening to full albums through the Spotify MCP Server.
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 implementing the play_album tool: constructs search query, finds album, plays it using SpotifyClient, and returns result.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:72-93 (registration)Registration of the 'play_album' tool in the MCP server's listTools response, including name, description, and 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/server.ts:275-289 (handler)Dispatch handler in MCP CallToolRequestSchema that invokes the playAlbum function with parsed arguments and device management.case 'play_album': const albumResult = await playTools.playAlbum( client, args?.albumName as string, args?.artistName as string | undefined, deviceManager.getDevice(args?.deviceId as string | undefined) ); return { content: [ { type: 'text', text: JSON.stringify(albumResult, null, 2), }, ], };
- src/spotify/client.ts:113-119 (helper)SpotifyClient helper method that calls the Spotify Web API to play an album by URI on specified device.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 helper method used by playAlbum to search for albums by query.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, })) || []; }