Skip to main content
Glama
marcelmarais

Spotify MCP Server

by marcelmarais

addTracksToPlaylist

Add multiple tracks to a Spotify playlist using track IDs and specify insertion position for playlist management.

Instructions

Add tracks to a Spotify playlist

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
playlistIdYesThe Spotify ID of the playlist
trackIdsYesArray of Spotify track IDs to add
positionNoPosition to insert the tracks (0-based index)

Implementation Reference

  • The handler function implements the core logic: validates input, converts track IDs to URIs, calls Spotify API to add items to playlist, handles success/error responses.
    handler: async (args, _extra: SpotifyHandlerExtra) => {
      const { playlistId, trackIds, position } = args;
    
      if (trackIds.length === 0) {
        return {
          content: [
            {
              type: 'text',
              text: 'Error: No track IDs provided',
            },
          ],
        };
      }
    
      try {
        const trackUris = trackIds.map((id) => `spotify:track:${id}`);
    
        await handleSpotifyRequest(async (spotifyApi) => {
          await spotifyApi.playlists.addItemsToPlaylist(
            playlistId,
            trackUris,
            position,
          );
        });
    
        return {
          content: [
            {
              type: 'text',
              text: `Successfully added ${trackIds.length} track${
                trackIds.length === 1 ? '' : 's'
              } to playlist (ID: ${playlistId})`,
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: 'text',
              text: `Error adding tracks to playlist: ${
                error instanceof Error ? error.message : String(error)
              }`,
            },
          ],
        };
      }
    },
  • Input schema using Zod for validation: requires playlistId and trackIds array, optional position.
    name: 'addTracksToPlaylist',
    description: 'Add tracks to a Spotify playlist',
    schema: {
      playlistId: z.string().describe('The Spotify ID of the playlist'),
      trackIds: z.array(z.string()).describe('Array of Spotify track IDs to add'),
      position: z
        .number()
        .nonnegative()
        .optional()
        .describe('Position to insert the tracks (0-based index)'),
    },
  • src/play.ts:499-510 (registration)
    The addTracksToPlaylist tool is registered in the exported playTools array.
    export const playTools = [
      playMusic,
      pausePlayback,
      skipToNext,
      skipToPrevious,
      createPlaylist,
      addTracksToPlaylist,
      resumePlayback,
      addToQueue,
      setVolume,
      adjustVolume,
    ];
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but only states the basic action without behavioral details. It doesn't disclose rate limits, authentication needs, whether the operation is idempotent, or how errors are handled for invalid track IDs or playlist permissions.

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 function without unnecessary words. It's appropriately sized and front-loaded with the core action.

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?

For a mutation tool with no annotations and no output schema, the description is insufficient. It lacks information about return values, error conditions, side effects, or constraints like track limits, leaving significant gaps for an AI agent to use it correctly.

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 schema fully documents all three parameters (playlistId, trackIds, position). The description adds no additional parameter semantics beyond what's in the schema, meeting the baseline for high coverage.

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 action ('add tracks') and target resource ('to a Spotify playlist'), which is specific and unambiguous. It doesn't explicitly differentiate from sibling tools like 'addToQueue' or 'saveOrRemoveAlbumForUser', but the verb+resource combination makes the purpose evident.

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 'addToQueue' (for immediate playback) or 'createPlaylist' (for making new playlists). It also doesn't mention prerequisites such as needing an existing playlist or authentication requirements.

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