Skip to main content
Glama
marcelmarais

Spotify MCP Server

by marcelmarais

getMyPlaylists

Retrieve your Spotify playlists to view and manage your music collections. Specify a limit to control how many playlists are returned.

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 that implements the tool logic: fetches the current user's playlists using the Spotify API, handles empty results, formats the playlist list with track counts and IDs, and returns a formatted text response.
      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}`,
            },
          ],
        };
      },
    };
  • Zod schema defining the optional 'limit' parameter for the number of playlists to fetch (1-50).
    schema: {
      limit: z
        .number()
        .min(1)
        .max(50)
        .optional()
        .describe('Maximum number of playlists to return (1-50)'),
    },
  • src/index.ts:12-14 (registration)
    Registration of all tools, including getMyPlaylists from readTools, with the MCP server using server.tool().
    [...readTools, ...playTools, ...albumTools].forEach((tool) => {
      server.tool(tool.name, tool.description, tool.schema, tool.handler);
    });
  • src/read.ts:603-612 (registration)
    The getMyPlaylists tool is included in the exported readTools array, which is imported and registered in index.ts.
    export const readTools = [
      searchSpotify,
      getNowPlaying,
      getMyPlaylists,
      getPlaylistTracks,
      getRecentlyPlayed,
      getUsersSavedTracks,
      getQueue,
      getAvailableDevices,
    ];

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