Skip to main content
Glama

add_to_playlist

Add tracks to a Spotify playlist by providing the playlist ID and track IDs. This tool enables playlist management through the Spotify MCP server.

Instructions

Add tracks to a playlist Args: playlist_id: Spotify playlist ID track_ids: List of track IDs to add

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
playlist_idYes
track_idsYes

Implementation Reference

  • main.py:188-196 (handler)
    MCP tool handler and registration for add_to_playlist. This is the entrypoint function executed when the tool is called, delegating to the SpotifyClient.
    @mcp.tool() async def add_to_playlist(playlist_id: str, track_ids: list[str]) -> str: """ Add tracks to a playlist Args: playlist_id: Spotify playlist ID track_ids: List of track IDs to add """ return await client.add_to_playlist(playlist_id, track_ids)
  • Core helper function in SpotifyClient that implements the logic: converts track IDs to Spotify URIs and adds items to the playlist using spotipy.Spotify.playlist_add_items.
    async def add_to_playlist(self, playlist_id: str, track_ids: list[str]) -> str: """ Add tracks to a playlist - playlist_id: Spotify playlist ID - track_ids: List of track IDs to add """ try: # Convert track IDs to full URIs track_uris = [f"spotify:track:{track_id}" for track_id in track_ids] self.sp.playlist_add_items(playlist_id, track_uris) return "Tracks added to playlist successfully" except Exception as e: return f"Error adding tracks to playlist: {str(e)}"
  • main.py:5-5 (helper)
    Instantiation of the global SpotifyClient instance used by all tool handlers.
    client = SpotifyClient()
  • main.py:4-4 (registration)
    Initialization of the FastMCP server instance where tools are registered.
    mcp = FastMCP("spotify")

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/ashwanth1109/mcp-spotify'

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