Skip to main content
Glama
makesh-kumar

Spotify MCP Server

by makesh-kumar

getPlaylistTracks

Retrieve track listings from Spotify playlists by specifying playlist ID, with options for pagination and result limits.

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 fetches tracks from the specified Spotify playlist using the playlists.getPlaylistItems API method, handles pagination with limit and offset, filters and formats track information (name, artists, duration, ID), and returns a markdown-formatted text response with the list of tracks.
    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 schema for input validation: requires playlistId (string), optional limit (1-50 number), optional offset (number >=0).
    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/read.ts:531-539 (registration)
    The getPlaylistTracks tool is included in the readTools export array, which collects read-related tools.
    export const readTools = [
      searchSpotify,
      getNowPlaying,
      getMyPlaylists,
      getPlaylistTracks,
      getRecentlyPlayed,
      getUsersSavedTracks,
      getQueue,
    ];
  • src/index.ts:12-14 (registration)
    All tools from readTools (including getPlaylistTracks), playTools, and albumTools are registered to the MCP server using server.tool() for each tool.
    [...readTools, ...playTools, ...albumTools].forEach((tool) => {
      server.tool(tool.name, tool.description, tool.schema, tool.handler);
    });
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool retrieves a list of tracks but omits critical details: whether it's paginated (implied by 'offset' parameter but not explained), rate limits, authentication requirements, or error handling. For a read operation with no annotation coverage, 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 front-loads the core purpose ('Get a list of tracks in a Spotify playlist'). There is no wasted language or redundancy, making it easy to parse quickly. Every word earns its place by directly 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?

Given the complexity of a read operation with pagination (implied by parameters), no annotations, and no output schema, the description is incomplete. It lacks information on authentication, rate limits, return format, error cases, and how pagination works. For a tool that interacts with an external API like Spotify, this omission could lead to incorrect usage by an agent.

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 schema description coverage is 100%, with clear descriptions for 'playlistId', 'limit', and 'offset'. The description adds no additional parameter semantics beyond what's in the schema (e.g., it doesn't explain playlist ID format or pagination behavior). This meets the baseline score of 3, as the schema adequately documents parameters without needing extra detail in the description.

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 of') and resource ('tracks in a Spotify playlist'), making the tool's purpose immediately understandable. It distinguishes itself from siblings like 'getAlbumTracks' by specifying playlist tracks rather than album tracks. However, it doesn't explicitly differentiate from 'getQueue' or 'getRecentlyPlayed', which also retrieve track lists, leaving some ambiguity.

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 prerequisites (e.g., needing a playlist ID), exclusions, or comparisons to siblings like 'getAlbumTracks' or 'getQueue'. The agent must infer usage from the name and context alone, which is insufficient for optimal tool selection.

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

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