Skip to main content
Glama

getAlbumTracks

Retrieve tracks from a Spotify album using album ID. Supports pagination with limit and offset for efficient track listing.

Instructions

Get tracks from a specific album with pagination support

Input Schema

NameRequiredDescriptionDefault
albumIdYesThe Spotify ID of the album
limitNoMaximum number of tracks to return (1-50)
offsetNoOffset for pagination (0-based index)

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "albumId": { "description": "The Spotify ID of the album", "type": "string" }, "limit": { "description": "Maximum number of tracks to return (1-50)", "maximum": 50, "minimum": 1, "type": "number" }, "offset": { "description": "Offset for pagination (0-based index)", "minimum": 0, "type": "number" } }, "required": [ "albumId" ], "type": "object" }

Implementation Reference

  • The handler function that implements the core logic of fetching tracks from a Spotify album using pagination, formatting the track list with artists and durations, and returning a structured markdown response or error.
    handler: async (args, _extra: SpotifyHandlerExtra) => { const { albumId, limit = 20, offset = 0 } = args; try { const tracks = await handleSpotifyRequest(async (spotifyApi) => { return await spotifyApi.albums.tracks( albumId, undefined, limit as MaxInt<50>, offset, ); }); if (tracks.items.length === 0) { return { content: [ { type: 'text', text: 'No tracks found in this album', }, ], }; } const formattedTracks = tracks.items .map((track, i) => { if (!track) return `${i + 1}. [Track not found]`; const artists = track.artists.map((a) => a.name).join(', '); const duration = formatDuration(track.duration_ms); return `${offset + i + 1}. "${track.name}" by ${artists} (${duration}) - ID: ${track.id}`; }) .join('\n'); return { content: [ { type: 'text', text: `# Album Tracks (${offset + 1}-${offset + tracks.items.length} of ${tracks.total})\n\n${formattedTracks}`, }, ], }; } catch (error) { return { content: [ { type: 'text', text: `Error getting album tracks: ${ error instanceof Error ? error.message : String(error) }`, }, ], }; } },
  • Input schema using Zod for validating tool parameters: albumId (string), optional limit (1-50), optional offset (>=0).
    schema: { albumId: z.string().describe('The Spotify ID of the album'), limit: z .number() .min(1) .max(50) .optional() .describe('Maximum number of tracks to return (1-50)'), offset: z .number() .min(0) .optional() .describe('Offset for pagination (0-based index)'), },
  • src/index.ts:12-14 (registration)
    Registers the getAlbumTracks tool (via albumTools array) with the MCP server by calling server.tool for each tool in the combined array.
    [...readTools, ...playTools, ...albumTools].forEach((tool) => { server.tool(tool.name, tool.description, tool.schema, tool.handler); });
  • src/albums.ts:299-304 (registration)
    Exports the array of album-related tools, including getAlbumTracks, which is later imported and registered in index.ts.
    export const albumTools = [ getAlbums, getAlbumTracks, saveOrRemoveAlbumForUser, checkUsersSavedAlbums, ];

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/marcelmarais/spotify-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server