Skip to main content
Glama
marcelmarais

Spotify MCP Server

by marcelmarais

getPlaylistTracks

Retrieve tracks from a Spotify playlist using its ID, with options for pagination and limiting results.

Instructions

Get a list of tracks in a Spotify playlist

Input Schema

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

Implementation Reference

  • The handler function that implements the core logic of the getPlaylistTracks tool. It takes playlistId, optional limit and offset, fetches the tracks using Spotify API via handleSpotifyRequest, validates tracks with isTrack, formats a numbered list with artist, duration, and ID, and returns a markdown-formatted text response with pagination info.
    handler: async (args, _extra: SpotifyHandlerExtra) => {
      const { playlistId, limit = 50, offset = 0 } = args;
    
      const playlistTracks = await handleSpotifyRequest(async (spotifyApi) => {
        return await spotifyApi.playlists.getPlaylistItems(
          playlistId,
          undefined,
          undefined,
          limit as MaxInt<50>,
          offset,
        );
      });
    
      if ((playlistTracks.items?.length ?? 0) === 0) {
        return {
          content: [
            {
              type: 'text',
              text: "This playlist doesn't have any tracks",
            },
          ],
        };
      }
    
      const formattedTracks = playlistTracks.items
        .map((item, i) => {
          const { track } = item;
          if (!track) return `${offset + i + 1}. [Removed track]`;
    
          if (isTrack(track)) {
            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}`;
          }
    
          return `${offset + i + 1}. Unknown item`;
        })
        .join('\n');
    
      return {
        content: [
          {
            type: 'text',
            text: `# Tracks in Playlist (${offset + 1}-${offset + playlistTracks.items.length} of ${playlistTracks.total})\n\n${formattedTracks}`,
          },
        ],
      };
    },
  • Zod input schema defining parameters for the tool: playlistId (string, required), limit (number 1-50, optional), offset (number >=0, optional). Used for validation.
    schema: {
      playlistId: z.string().describe('The Spotify ID of the playlist'),
      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)
    Final registration of the getPlaylistTracks tool with the MCP server. readTools (containing getPlaylistTracks) is spread into the array and each tool is registered via server.tool().
    [...readTools, ...playTools, ...albumTools].forEach((tool) => {
      server.tool(tool.name, tool.description, tool.schema, tool.handler);
    });
  • src/read.ts:603-612 (registration)
    getPlaylistTracks is included in the readTools array, which is exported from read.ts, imported into index.ts, and registered with the MCP server.
    export const readTools = [
      searchSpotify,
      getNowPlaying,
      getMyPlaylists,
      getPlaylistTracks,
      getRecentlyPlayed,
      getUsersSavedTracks,
      getQueue,
      getAvailableDevices,
    ];
  • Helper function used in the handler to validate if an item is a SpotifyTrack before formatting.
    function isTrack(item: any): item is SpotifyTrack {
      return (
        item &&
        item.type === 'track' &&
        Array.isArray(item.artists) &&
        item.album &&
        typeof item.album.name === 'string'
      );
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states this is a read operation ('Get'), but doesn't mention authentication requirements, rate limits, pagination behavior beyond the offset parameter, error conditions, or what the return format looks like. For a tool with 3 parameters and no output schema, this leaves significant gaps in understanding how the tool behaves.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that states the core purpose without unnecessary words. It's appropriately sized for a straightforward retrieval tool and front-loads the essential information. Every word earns its place in conveying the tool's function.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with 3 parameters, no annotations, and no output schema, the description is insufficiently complete. It doesn't address authentication needs, rate limits, pagination strategy beyond mentioning offset, error handling, or what the return data structure contains. The agent would need to guess about many behavioral aspects when invoking this tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description doesn't add any parameter information beyond what's already in the schema (which has 100% coverage). It mentions 'playlist' which relates to the playlistId parameter, but doesn't explain parameter interactions, default values, or provide examples. With complete schema coverage, the baseline score of 3 is appropriate since the schema already documents all parameters thoroughly.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Get a list') and resource ('tracks in a Spotify playlist'), making the purpose immediately understandable. However, it doesn't differentiate this tool from similar siblings like 'getAlbumTracks' or 'getUsersSavedTracks' by specifying it's specifically for playlist tracks rather than album tracks or saved tracks.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention when this tool is appropriate (e.g., for retrieving playlist contents) versus when to use siblings like 'getMyPlaylists' (for playlist metadata) or 'searchSpotify' (for finding tracks). No exclusions or prerequisites are stated.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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