Skip to main content
Glama
makesh-kumar

Spotify MCP Server

by makesh-kumar

getUsersSavedTracks

Retrieve tracks saved in your Spotify Liked Songs library with pagination controls for managing large collections.

Instructions

Get a list of tracks saved in the user's "Liked Songs" library

Input Schema

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

Implementation Reference

  • The core handler function that executes the tool logic: fetches user's saved tracks ("Liked Songs") via Spotify API with pagination (limit/offset), handles empty results, formats track details (name, artists, duration, ID, added date) using helpers like isTrack and formatDuration, and returns a formatted text response.
    handler: async (args, _extra: SpotifyHandlerExtra) => {
      const { limit = 50, offset = 0 } = args;
    
      const savedTracks = await handleSpotifyRequest(async (spotifyApi) => {
        return await spotifyApi.currentUser.tracks.savedTracks(
          limit as MaxInt<50>,
          offset,
        );
      });
    
      if (savedTracks.items.length === 0) {
        return {
          content: [
            {
              type: 'text',
              text: "You don't have any saved tracks in your Liked Songs",
            },
          ],
        };
      }
    
      const formattedTracks = savedTracks.items
        .map((item, i) => {
          const track = item.track;
          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);
            const addedDate = new Date(item.added_at).toLocaleDateString();
            return `${offset + i + 1}. "${track.name}" by ${artists} (${duration}) - ID: ${track.id} - Added: ${addedDate}`;
          }
    
          return `${i + 1}. Unknown item`;
        })
        .join('\n');
    
      return {
        content: [
          {
            type: 'text',
            text: `# Your Liked Songs (${offset + 1}-${offset + savedTracks.items.length} of ${savedTracks.total})\n\n${formattedTracks}`,
          },
        ],
      };
    },
  • Input schema definition using Zod for validation: optional limit (1-50) and offset (>=0). Includes tool name and description.
    name: 'getUsersSavedTracks',
    description:
      'Get a list of tracks saved in the user\'s "Liked Songs" library',
    schema: {
      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)
    Local registration: getUsersSavedTracks is added to the readTools array alongside other read-related tools for collective export.
    export const readTools = [
      searchSpotify,
      getNowPlaying,
      getMyPlaylists,
      getPlaylistTracks,
      getRecentlyPlayed,
      getUsersSavedTracks,
      getQueue,
    ];
  • src/index.ts:12-14 (registration)
    Global registration: All tools from readTools (including getUsersSavedTracks) are looped over and registered with the MCP server using server.tool().
    [...readTools, ...playTools, ...albumTools].forEach((tool) => {
      server.tool(tool.name, tool.description, tool.schema, tool.handler);
    });
  • Supporting helper function used in the handler to type-guard and validate Spotify track items 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'
      );

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

A3.7/5.0
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 only says 'Get a list', which implies read-only behavior, but it does not mention pagination, authentication, or what happens if there are no saved tracks. Minimal behavioral context is added beyond the verb itself.

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 sentence of 11 words, extremely concise and front-loaded with the action and object. It contains no filler, repetition, or unnecessary detail.

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

Completeness3/5

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

For a simple read tool with two optional numeric parameters, the description is adequate but lacks behavioral nuances such as pagination behavior and output structure. Since there is no output schema and no annotations, additional context about the returned list or pagination would make it more complete.

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 input schema fully describes both parameters (limit and offset) with clear descriptions and constraints, achieving 100% schema description coverage. The description adds no additional parameter semantics, so the baseline score of 3 is appropriate.

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

Purpose5/5

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

The description clearly states the verb 'Get' and the specific resource 'tracks saved in the user's 'Liked Songs' library', which unambiguously distinguishes it from sibling tools like getAlbumTracks or getPlaylistTracks. It immediately conveys the tool's function without any ambiguity.

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

Usage Guidelines4/5

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

The description provides clear context by identifying the 'Liked Songs' library, making it easy to infer when this tool should be used instead of other track-retrieval tools. However, it does not explicitly mention exclusions or alternative tools, lacking the 'when-not' guidance that would push it to a 5.

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