Skip to main content
Glama

add_tracks_to_playlist

Add tracks to a Spotify playlist using track URIs and specify playlist ID. Insert tracks at a specific position if needed.

Instructions

Add one or more tracks to a playlist

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYesThe Spotify ID or URI of the playlist
urisYesArray of Spotify track URIs to add
positionNoOptional. The position to insert the tracks (zero-based)

Implementation Reference

  • The core handler function implementing add_tracks_to_playlist by extracting playlist ID, preparing data with URIs and optional position, and making a POST request to Spotify API endpoint /playlists/{id}/tracks.
    async addTracksToPlaylist(args: AddTracksToPlaylistArgs) { const playlistId = this.extractPlaylistId(args.id); const { uris, position } = args; const data = { uris, ...(position !== undefined && { position }) }; return this.api.makeRequest( `/playlists/${playlistId}/tracks`, 'POST', data ); }
  • TypeScript interface defining the input parameters for the addTracksToPlaylist handler: playlist ID, array of track URIs, and optional insert position.
    export interface AddTracksToPlaylistArgs { id: string; uris: string[]; position?: number; }
  • src/index.ts:557-580 (registration)
    MCP tool registration in listTools response, defining the name, description, and inputSchema matching the handler args.
    { name: 'add_tracks_to_playlist', description: 'Add one or more tracks to a playlist', inputSchema: { type: 'object', properties: { id: { type: 'string', description: 'The Spotify ID or URI of the playlist' }, uris: { type: 'array', items: { type: 'string' }, description: 'Array of Spotify track URIs to add' }, position: { type: 'number', description: 'Optional. The position to insert the tracks (zero-based)', minimum: 0 } }, required: ['id', 'uris'] }, },
  • src/index.ts:861-867 (registration)
    Dispatch logic in the main CallToolRequest handler switch statement: validates required args and delegates to playlistsHandler.addTracksToPlaylist
    case 'add_tracks_to_playlist': { const args = this.validateArgs<AddTracksToPlaylistArgs>(request.params.arguments, ['id', 'uris']); const result = await this.playlistsHandler.addTracksToPlaylist(args); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], }; }
  • Helper method used by addTracksToPlaylist (and others) to normalize playlist ID from Spotify URI or plain ID.
    private extractPlaylistId(id: string): string { return id.startsWith('spotify:playlist:') ? id.split(':')[2] : id; }

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/superseoworld/mcp-spotify'

If you have feedback or need assistance with the MCP directory API, please join our Discord server