add_to_playlist
Enables users to add one or multiple tracks to Spotify playlists they own or can edit. Returns confirmation, updated playlist details, and error information for failed additions. Ideal for playlist curation, collaboration, and dynamic updates.
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
| Name | Required | Description | Default |
|---|---|---|---|
| playlistId | Yes | Spotify playlist ID or URI | |
| token | Yes | Spotify access token for authentication | |
| trackUris | Yes | Array of Spotify track URIs |
Implementation Reference
- src/mcp/tools/playlists.ts:262-269 (handler)The handler function for the 'add_to_playlist' MCP tool. It extracts arguments (token, playlistId, trackUris) and delegates to SpotifyService.addTracksToPlaylist method.handler: async (args: any, spotifyService: SpotifyService) => { const { token, playlistId, trackUris } = args; return await spotifyService.addTracksToPlaylist( token, playlistId, trackUris ); },
- src/mcp/tools/playlists.ts:257-261 (schema)Input schema definition for the 'add_to_playlist' tool using createSchema and common schemas for token, playlist ID, and track URIs.schema: createSchema({ token: commonSchemas.token(), playlistId: commonSchemas.spotifyId("playlist"), trackUris: commonSchemas.trackUris(), }),
- src/spotify.ts:549-565 (helper)Core implementation in SpotifyService that performs the HTTP POST request to Spotify API endpoint /playlists/{id}/tracks to add the specified track URIs to the 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 ); }
- src/mcp/tools/index.ts:22-36 (registration)Registration of playlistTools (containing add_to_playlist) into the central allTools registry, which is used by ToolRegistrar to create MCP tool definitions and handlers.export const allTools: ToolsRegistry = { ...albumTools, ...artistTools, ...trackTools, ...playlistTools, ...playbackTools, ...userTools, ...searchTools, };