Skip to main content
Glama

add_tracks_to_playlist

Add songs to a Spotify playlist using track URIs. This tool enables users to expand their music collections by inserting multiple tracks into existing playlists through the Multi-MCPs server.

Instructions

Add tracks to a playlist by URIs

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
playlist_idYes
tracksYes

Implementation Reference

  • The main handler function for the 'add_tracks_to_playlist' tool. It validates inputs and delegates to the SpotifyClient's addTracksToPlaylist method.
    async add_tracks_to_playlist(args: Record<string, unknown>) { if (!cfg.spotifyClientId || !cfg.spotifyClientSecret) throw new Error("SPOTIFY_CLIENT_ID/SECRET are not configured"); const playlistId = String(args.playlist_id || ""); const tracks = Array.isArray(args.tracks) ? (args.tracks as string[]) : []; if (!playlistId || tracks.length === 0) throw new Error("playlist_id and tracks are required"); return client.addTracksToPlaylist(playlistId, tracks); },
  • Input schema definition for the tool, specifying playlist_id as string and tracks as array of strings.
    inputSchema: { type: "object", properties: { playlist_id: { type: "string" }, tracks: { type: "array", items: { type: "string" } } }, required: ["playlist_id", "tracks"], },
  • Tool registration object defining name, description, and schema, returned as part of registerSpotify().
    { name: "add_tracks_to_playlist", description: "Add tracks to a playlist by URIs", inputSchema: { type: "object", properties: { playlist_id: { type: "string" }, tracks: { type: "array", items: { type: "string" } } }, required: ["playlist_id", "tracks"], }, },
  • Helper method in SpotifyClient class that makes the actual Spotify API request to add tracks to a playlist.
    async addTracksToPlaylist(playlistId: string, tracks: string[]) { return this.request(`/playlists/${playlistId}/tracks`, { method: "POST", headers: await this.authHeaders(), body: { uris: tracks }, }); }
  • Invocation of registerSpotify() in the central registerAllTools function, integrating the Spotify tools into the MCP server.
    registerSpotify(),

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/TaylorChen/muti-mcps'

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