Skip to main content
Glama
igorgarbuz

Spotify MCP Node Server

by igorgarbuz

getPlaylistTracks

Retrieve track listings from Spotify playlists by specifying playlist ID, with options to limit results and set offset for pagination.

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)
offsetNoThe index of the first item to return. Defaults to 0

Implementation Reference

  • Executes the tool logic: fetches playlist items from Spotify API using handleSpotifyRequest, validates tracks with isTrack, formats track info (name, artists, duration, ID), handles empty/removed/unknown items, returns formatted text response or no-tracks message.
      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 `${i + 1}. [Removed track]`;
    
            if (isTrack(track)) {
              const artists = track.artists.map((a) => a.name).join(', ');
              const duration = formatDuration(track.duration_ms);
              return `${i + 1}. "${track.name}" by ${artists} (${duration}) - ID: ${track.id}`;
            }
    
            return `${i + 1}. Unknown item`;
          })
          .join('\n');
    
        return {
          content: [
            {
              type: 'text',
              text: `# Tracks in Playlist\n\n${formattedTracks}`,
            },
          ],
        };
      },
    };
  • Input schema definition using Zod for validating playlistId (required string), optional limit (1-50), offset (0-1000).
    name: 'getPlaylistTracks',
    description: 'Get a list of tracks in a Spotify playlist',
    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)
        .max(1000)
        .optional()
        .describe('The index of the first item to return. Defaults to 0'),
    },
  • src/index.ts:12-14 (registration)
    Registers the getPlaylistTracks tool (along with others) with the MCP server by calling server.tool() with its name, description, schema, and handler from the readTools array.
    [...playTools, ...readTools, ...writeTools].forEach((tool) => {
      server.tool(tool.name, tool.description, tool.schema, tool.handler);
    });
  • Type guard helper function used in getPlaylistTracks handler to check if a playlist item is a valid SpotifyTrack.
    function isTrack(item: any): item is SpotifyTrack {
      return (
        item &&
        item.type === 'track' &&
        Array.isArray(item.artists) &&
        item.album &&
        typeof item.album.name === 'string'
      );
    }
  • src/read.ts:525-525 (registration)
    Includes getPlaylistTracks in the readTools export array, which is imported and registered in index.ts.
    getPlaylistTracks,
Behavior2/5

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

With no annotations provided, the description carries full burden but offers minimal behavioral insight. It doesn't disclose whether this is a read-only operation, if it requires specific permissions, rate limits, pagination behavior beyond the 'limit' and 'offset' parameters, or what the response format looks like.

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, clear sentence with no wasted words. It's front-loaded with the core purpose and efficiently communicates the essential action without unnecessary elaboration.

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 inadequate. It doesn't explain return values, error conditions, authentication requirements, or behavioral constraints. The schema handles parameters well, but the description fails to provide necessary context for effective use.

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?

Schema description coverage is 100%, so the schema fully documents all three parameters. The description adds no additional parameter semantics beyond what's in the schema, such as explaining playlist ID format or typical use cases for limit/offset. This meets the baseline for high schema coverage.

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 from sibling tools like 'getUserPlaylists' or 'getRecentlyPlayed' beyond the obvious resource difference, missing explicit sibling distinction.

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., authentication), compare to similar tools like 'getUserPlaylists' for finding playlists first, or specify use cases beyond the basic action.

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

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