Skip to main content
Glama

add_to_playlist

Add tracks to Spotify playlists for music curation, playlist growth, and collaborative music sharing. Supports single or multiple track additions to owned or collaborative playlists.

Instructions

Add one or more tracks to any existing playlist that the user owns or can modify.

🎯 USE CASES: β€’ Build and curate playlist collections with discovered music β€’ Add recommended tracks from discovery algorithms β€’ Collaborate on shared playlists with friends β€’ Create themed collections by adding related songs β€’ Maintain dynamic playlists that evolve with listening habits

πŸ“ WHAT IT RETURNS: β€’ Confirmation of successful track additions β€’ Updated playlist length and total duration β€’ New track positions within the playlist β€’ Snapshot ID for tracking playlist changes β€’ Error details for any tracks that couldn't be added

πŸ” EXAMPLES: β€’ "Add 'Bohemian Rhapsody' to my Rock Classics playlist" β€’ "Put these 5 songs into my workout playlist" β€’ "Add track spotify:track:4uLU6hMCjMI75M1A2tKUQC to favorites" β€’ "Include all these discovered songs in my new releases list"

🎡 ADDITION FEATURES: β€’ Add single tracks or multiple tracks at once β€’ Tracks appear at the end of existing playlist β€’ Maintains playlist order and structure β€’ Supports bulk additions for efficiency β€’ Perfect for playlist curation and growth

πŸ’‘ CURATION TIPS: β€’ Add tracks that fit the playlist theme or mood β€’ Consider track flow and transitions β€’ Test songs before adding to public playlists β€’ Use bulk additions for efficiency β€’ Regular playlist maintenance keeps content fresh

⚠️ REQUIREMENTS: β€’ Valid Spotify access token with playlist-modify scopes β€’ User must own playlist or have collaborative access β€’ Tracks must be available in user's market

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tokenYesSpotify access token for authentication
playlistIdYesSpotify playlist ID or URI
trackUrisYesArray of Spotify track URIs

Implementation Reference

  • The handler function that executes the tool logic by calling SpotifyService.addTracksToPlaylist with the provided arguments.
    handler: async (args: any, spotifyService: SpotifyService) => { const { token, playlistId, trackUris } = args; return await spotifyService.addTracksToPlaylist( token, playlistId, trackUris ); },
  • The input schema defining parameters: token, playlistId, and trackUris.
    schema: createSchema({ token: commonSchemas.token(), playlistId: commonSchemas.spotifyId("playlist"), trackUris: commonSchemas.trackUris(), }),
  • The tool definition object for 'add_to_playlist' exported as part of playlistTools, which is included in allTools.
    add_to_playlist: { title: "Add Tracks to Playlist", description: `Add one or more tracks to any existing playlist that the user owns or can modify. 🎯 USE CASES: β€’ Build and curate playlist collections with discovered music β€’ Add recommended tracks from discovery algorithms β€’ Collaborate on shared playlists with friends β€’ Create themed collections by adding related songs β€’ Maintain dynamic playlists that evolve with listening habits πŸ“ WHAT IT RETURNS: β€’ Confirmation of successful track additions β€’ Updated playlist length and total duration β€’ New track positions within the playlist β€’ Snapshot ID for tracking playlist changes β€’ Error details for any tracks that couldn't be added πŸ” EXAMPLES: β€’ "Add 'Bohemian Rhapsody' to my Rock Classics playlist" β€’ "Put these 5 songs into my workout playlist" β€’ "Add track spotify:track:4uLU6hMCjMI75M1A2tKUQC to favorites" β€’ "Include all these discovered songs in my new releases list" 🎡 ADDITION FEATURES: β€’ Add single tracks or multiple tracks at once β€’ Tracks appear at the end of existing playlist β€’ Maintains playlist order and structure β€’ Supports bulk additions for efficiency β€’ Perfect for playlist curation and growth πŸ’‘ CURATION TIPS: β€’ Add tracks that fit the playlist theme or mood β€’ Consider track flow and transitions β€’ Test songs before adding to public playlists β€’ Use bulk additions for efficiency β€’ Regular playlist maintenance keeps content fresh ⚠️ REQUIREMENTS: β€’ Valid Spotify access token with playlist-modify scopes β€’ User must own playlist or have collaborative access β€’ Tracks must be available in user's market`, schema: createSchema({ token: commonSchemas.token(), playlistId: commonSchemas.spotifyId("playlist"), trackUris: commonSchemas.trackUris(), }), handler: async (args: any, spotifyService: SpotifyService) => { const { token, playlistId, trackUris } = args; return await spotifyService.addTracksToPlaylist( token, playlistId, trackUris ); }, },
  • The SpotifyService method that makes the POST request to Spotify API to add tracks to the specified playlist.
    async addTracksToPlaylist( token: string, playlistId: string, trackUris: string | string[] ): Promise<{ snapshot_id: string }> { const id = this.extractId(playlistId); const data = { uris: Array.isArray(trackUris) ? trackUris : [trackUris], }; return await this.makeRequest<{ snapshot_id: string }>( `playlists/${id}/tracks`, token, {}, "POST", data ); }
  • Aggregation of all tools including playlistTools (containing add_to_playlist) into allTools used by ToolRegistrar for MCP registration.
    export const allTools: ToolsRegistry = { ...albumTools, ...artistTools, ...trackTools, ...playlistTools, ...playbackTools, ...userTools, ...searchTools, };

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/latiftplgu/Spotify-OAuth-MCP-server'

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