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'
      );
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 action but lacks details on permissions, rate limits, response format, or pagination behavior. For a read operation with no annotation coverage, this is a significant gap in transparency.

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 directly states the tool's purpose without unnecessary words. It is front-loaded and appropriately sized, making it easy to parse quickly.

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?

Given the tool's moderate complexity (retrieving a list with pagination), no annotations, and no output schema, the description is incomplete. It lacks details on return values, error handling, or behavioral traits, but it at least specifies the resource clearly, making it minimally adequate.

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 input schema fully documents the 'limit' and 'offset' parameters. The description doesn't add any meaning beyond this, such as explaining default values or usage context, but it doesn't need to compensate for gaps, so it meets the baseline.

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 verb 'Get' and the resource 'list of tracks saved in the user's "Liked Songs" library', making the purpose specific and understandable. However, it doesn't explicitly differentiate from sibling tools like 'getRecentlyPlayed' or 'getPlaylistTracks', which also retrieve tracks but from different sources, so it doesn't reach the highest score.

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 context, prerequisites, or exclusions, such as comparing to 'getRecentlyPlayed' for recent tracks or 'getPlaylistTracks' for playlist content, leaving the agent without usage direction.

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