Skip to main content
Glama
marcelmarais

Spotify MCP Server

by marcelmarais

getAlbumTracks

Retrieve track listings from Spotify albums with pagination support to manage large collections systematically.

Instructions

Get tracks from a specific album with pagination support

Input Schema

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

Implementation Reference

  • The main handler function that fetches album tracks from Spotify API, handles pagination, formats track list with artists and durations, and returns formatted text response.
    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)
              }`,
            },
          ],
        };
      }
    },
  • Zod schema defining input parameters: albumId (required string), limit (optional 1-50), offset (optional >=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/albums.ts:299-304 (registration)
    Exports an array of album-related tools including getAlbumTracks, likely used for MCP tool registration.
    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