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
| Name | Required | Description | Default |
|---|---|---|---|
| token | Yes | Spotify access token for authentication | |
| playlistId | Yes | Spotify playlist ID or URI | |
| trackUris | Yes | Array of Spotify track URIs |
Implementation Reference
- src/mcp/tools/playlists.ts:262-269 (handler)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 ); },
- src/mcp/tools/playlists.ts:257-261 (schema)The input schema defining parameters: token, playlistId, and trackUris.schema: createSchema({ token: commonSchemas.token(), playlistId: commonSchemas.spotifyId("playlist"), trackUris: commonSchemas.trackUris(), }),
- src/mcp/tools/playlists.ts:215-270 (registration)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 ); }, },
- src/spotify.ts:549-565 (helper)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 ); }
- src/mcp/tools/index.ts:22-36 (registration)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, };