Skip to main content
Glama
marcelmarais

Spotify MCP Server

by marcelmarais

getUsersSavedTracks

Retrieve tracks from your Spotify Liked Songs library with pagination support for managing saved music.

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

  • Complete definition of the getUsersSavedTracks tool including name, schema for limit and offset parameters, and the handler function that retrieves the user's saved tracks ("Liked Songs") from the Spotify API, formats the track list with artist names, duration, ID, and added date, handles pagination and empty results, and returns a formatted markdown text response.
    const getUsersSavedTracks: tool<{
      limit: z.ZodOptional<z.ZodNumber>;
      offset: z.ZodOptional<z.ZodNumber>;
    }> = {
      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)'),
      },
      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}`,
            },
          ],
        };
      },
    };
  • src/read.ts:603-612 (registration)
    The getUsersSavedTracks tool is registered by being included in the exported readTools array, likely used elsewhere to register all read-related MCP tools.
    export const readTools = [
      searchSpotify,
      getNowPlaying,
      getMyPlaylists,
      getPlaylistTracks,
      getRecentlyPlayed,
      getUsersSavedTracks,
      getQueue,
      getAvailableDevices,
    ];
  • Zod-based input schema for the tool, defining optional 'limit' (1-50) and 'offset' (min 0) parameters with descriptions.
    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)'),
    },
  • Helper function used in the handler to type-guard and validate if an item is a SpotifyTrack.
    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 the tool retrieves a list but omits critical details: whether it requires user authentication, how it handles pagination beyond the offset parameter, what the return format is, or any rate limits. This leaves significant gaps for an agent to understand operational behavior.

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 any redundant or unnecessary information. It is front-loaded and appropriately sized, with every word contributing to clarity.

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 tool's complexity (a read operation with pagination), lack of annotations, and no output schema, the description is incomplete. It fails to explain return values, authentication requirements, or error handling, leaving the agent with insufficient context for reliable invocation.

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%, with both parameters (limit and offset) fully documented in the schema. The description adds no additional parameter semantics beyond what the schema provides, such as default values or usage context. Baseline 3 is appropriate as the schema handles the heavy lifting.

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 specific action ('Get a list of tracks') and the precise resource ('saved in the user's "Liked Songs" library'), distinguishing it from sibling tools like getRecentlyPlayed or getAlbumTracks. It uses a concrete verb and identifies the exact playlist type, avoiding vagueness.

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 like getRecentlyPlayed or getMyPlaylists. It lacks explicit instructions on prerequisites, such as user authentication, or exclusions, such as not being suitable for retrieving non-liked tracks. Usage is implied but not articulated.

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