Skip to main content
Glama

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

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