removeTracksFromPlaylist
Remove specific tracks from a Spotify playlist by providing playlist and track IDs. This tool helps users manage playlist content by deleting unwanted songs.
Instructions
Remove tracks from a Spotify playlist
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| playlistId | Yes | The Spotify ID of the playlist | |
| trackIds | Yes | Array of Spotify track IDs to remove |
Implementation Reference
- src/write.ts:188-235 (handler)The async handler function that implements the tool logic: validates input, constructs track URIs, calls Spotify API to remove items from playlist, and returns success/error messages.handler: async (args, extra: SpotifyHandlerExtra) => { const { playlistId, trackIds } = args; if (trackIds.length === 0) { return { content: [ { type: 'text', text: 'Error: No track IDs provided', }, ], }; } try { const tracks = trackIds.map((id) => ({ uri: `spotify:track:${id}`, })); await handleSpotifyRequest(async (spotifyApi) => { await spotifyApi.playlists.removeItemsFromPlaylist(playlistId, { tracks, }); }); return { content: [ { type: 'text', text: `Successfully removed ${trackIds.length} track${ trackIds.length === 1 ? '' : 's' } from playlist (ID: ${playlistId})`, }, ], }; } catch (error) { return { content: [ { type: 'text', text: `Error removing tracks from playlist: ${ error instanceof Error ? error.message : String(error) }`, }, ], }; } },
- src/write.ts:182-187 (schema)Zod schema for input validation: requires playlistId (string) and trackIds (array of strings).schema: { playlistId: z.string().describe('The Spotify ID of the playlist'), trackIds: z .array(z.string()) .describe('Array of Spotify track IDs to remove'), },
- src/write.ts:238-243 (registration)Includes the removeTracksFromPlaylist tool in the exported writeTools array, which is imported and registered elsewhere.export const writeTools = [ addToQueue, addTracksToPlaylist, createPlaylist, removeTracksFromPlaylist, ];
- src/index.ts:12-14 (registration)Registers all tools from playTools, readTools, and writeTools arrays with the MCP server by calling server.tool() for each.[...playTools, ...readTools, ...writeTools].forEach((tool) => { server.tool(tool.name, tool.description, tool.schema, tool.handler); });