Skip to main content
Glama
makesh-kumar

Spotify MCP Server

by makesh-kumar

getMyPlaylists

Retrieve your Spotify playlists to view, manage, or organize your music collection. 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

  • Full implementation of the getMyPlaylists tool, including schema, description, and handler function that retrieves and formats the user's Spotify playlists using the Spotify API.
    const getMyPlaylists: tool<{
      limit: z.ZodOptional<z.ZodNumber>;
    }> = {
      name: 'getMyPlaylists',
      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)'),
      },
      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}`,
            },
          ],
        };
      },
    };
  • src/read.ts:531-539 (registration)
    The getMyPlaylists tool is included in the exported readTools array for grouping read operations.
    export const readTools = [
      searchSpotify,
      getNowPlaying,
      getMyPlaylists,
      getPlaylistTracks,
      getRecentlyPlayed,
      getUsersSavedTracks,
      getQueue,
    ];
  • src/index.ts:12-14 (registration)
    Registration of all tools, including getMyPlaylists via readTools, to the MCP server using server.tool().
    [...readTools, ...playTools, ...albumTools].forEach((tool) => {
      server.tool(tool.name, tool.description, tool.schema, tool.handler);
    });
  • Utility function handleSpotifyRequest used in the getMyPlaylists handler to execute Spotify API calls with proper authentication and error handling.
    export async function handleSpotifyRequest<T>(
      action: (spotifyApi: SpotifyApi) => Promise<T>,
    ): Promise<T> {
      try {
        const spotifyApi = createSpotifyApi();
        return await action(spotifyApi);
      } catch (error) {
        // Skip JSON parsing errors as these are actually successful operations
        const errorMessage = error instanceof Error ? error.message : String(error);
        if (
          errorMessage.includes('Unexpected token') ||
          errorMessage.includes('Unexpected non-whitespace character') ||
          errorMessage.includes('Exponent part is missing a number in JSON')
        ) {
          return undefined as T;
        }
        // Rethrow other errors
        throw error;
      }
    }
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 it retrieves a list but doesn't mention authentication requirements (likely needed for Spotify API), rate limits, pagination behavior, or what happens if the user has no playlists. For a read operation with zero annotation coverage, this leaves significant gaps in understanding how the tool behaves beyond basic functionality.

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, clear sentence that efficiently conveys the core purpose without unnecessary words. It is front-loaded with the main action and resource, making it easy to parse quickly. Every part of the sentence earns its place by specifying the user context and platform.

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 moderate complexity (retrieving user-specific data from an external API), lack of annotations, and no output schema, the description is insufficient. It doesn't cover authentication needs, error handling, response format, or limitations like pagination, which are critical for an agent to use this tool effectively in real-world scenarios.

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 has 100% description coverage, with the 'limit' parameter fully documented in the schema itself. The description adds no additional parameter information beyond what the schema provides, such as default values or usage examples. According to the rules, with high schema coverage, the baseline is 3 even without param info in the description.

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 resource ('list of the current user's playlists on Spotify'), making the purpose specific and understandable. However, it doesn't explicitly differentiate from sibling tools like 'getPlaylistTracks' or 'getQueue', which also retrieve playlist-related data but with different scopes or contexts.

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

Usage Guidelines3/5

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

The description implies usage by specifying 'current user's playlists', suggesting it's for personal playlist retrieval. However, it lacks explicit guidance on when to use this tool versus alternatives like 'getPlaylistTracks' (which gets tracks within a playlist) or 'createPlaylist' (for creating new ones), leaving the agent to infer context without clear exclusions or comparisons.

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