Skip to main content
Glama
igorgarbuz

Spotify MCP Node Server

by igorgarbuz

getUserPlaylists

Retrieve a list of the current user's Spotify playlists, with optional limit control for managing large collections.

Instructions

Get a list of the current user's playlists on Spotify

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNoMaximum number of playlists to return (1-50)

Implementation Reference

  • The main handler function for the getUserPlaylists tool. Fetches the current user's playlists from Spotify API using handleSpotifyRequest, handles empty case, formats a numbered list with name, track count, and ID, returns as markdown text content.
      handler: async (args, extra: SpotifyHandlerExtra) => {
        const { limit = 50 } = args;
    
        const playlists = await handleSpotifyRequest(async (spotifyApi) => {
          return await spotifyApi.currentUser.playlists.playlists(
            limit as MaxInt<50>,
          );
        });
    
        if (playlists.items.length === 0) {
          return {
            content: [
              {
                type: 'text',
                text: "You don't have any playlists on Spotify",
              },
            ],
          };
        }
    
        const formattedPlaylists = playlists.items
          .map((playlist, i) => {
            const tracksTotal = playlist.tracks?.total ? playlist.tracks.total : 0;
            return `${i + 1}. "${playlist.name}" (${tracksTotal} tracks) - ID: ${
              playlist.id
            }`;
          })
          .join('\n');
    
        return {
          content: [
            {
              type: 'text',
              text: `# Your Spotify Playlists\n\n${formattedPlaylists}`,
            },
          ],
        };
      },
    };
  • Type definition for the tool parameters and Zod input schema defining optional 'limit' parameter between 1 and 50.
    const getUserPlaylists: tool<{
      limit: z.ZodOptional<z.ZodNumber>;
    }> = {
      name: 'getUserPlaylists',
      description: "Get a list of the current user's playlists on Spotify",
      schema: {
        limit: z
          .number()
          .min(1)
          .max(50)
          .optional()
          .describe('Maximum number of playlists to return (1-50)'),
      },
  • src/read.ts:521-529 (registration)
    The getUserPlaylists tool is included in the exported readTools array for further registration.
    export const readTools = [
      searchSpotify,
      getNowPlaying,
      getUserPlaylists,
      getPlaylistTracks,
      getRecentlyPlayed,
      getFollowedArtists,
      getUserTopItems,
    ];
  • src/index.ts:12-14 (registration)
    All tools from readTools (including getUserPlaylists) are registered to the MCP server instance using the server.tool method.
    [...playTools, ...readTools, ...writeTools].forEach((tool) => {
      server.tool(tool.name, tool.description, tool.schema, tool.handler);
    });

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