Skip to main content
Glama

update_playlist

Modify an existing Spotify playlist by changing its name, description, visibility, or track list using the Spotify Model Context Protocol.

Instructions

Update an existing Spotify playlist's details and/or tracks. Args: playlist_id: The Spotify ID of the playlist to update name: New name for the playlist (optional) track_uris: New list of track URIs to replace the playlist's tracks (optional) description: New description for the playlist (optional) public: New public/private status for the playlist (optional)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
playlist_idYes
nameNo
track_urisNo
descriptionNo
publicNo

Implementation Reference

  • Main handler function for the 'update_playlist' MCP tool. Handles user authentication, token refresh if needed, updates playlist details (name, description, public), and optionally replaces all tracks in the playlist.
    @mcp.tool("update_playlist") def update_playlist(playlist_id: str, name: str = None, track_uris: List[str] = None, description: str = None, public: bool = None) -> dict: """ Update an existing Spotify playlist's details and/or tracks. Args: playlist_id: The Spotify ID of the playlist to update name: New name for the playlist (optional) track_uris: New list of track URIs to replace the playlist's tracks (optional) description: New description for the playlist (optional) public: New public/private status for the playlist (optional) """ user_id = get_current_user_id() tokens = get_user_tokens(user_id) if not tokens: raise Exception("No tokens found for user") if tokens["token_expiry"] < time.time(): tokens = spotify_client.refresh_access_token(tokens["refresh_token"]) update_access_token(user_id, tokens["access_token"], tokens.get("expires_in", 3600)) result = {} # Update playlist details if any are provided if any([name, description, public is not None]): details_result = spotify_client.update_playlist_details( access_token=tokens["access_token"], playlist_id=playlist_id, name=name, description=description, public=public ) if details_result: result.update(details_result) else: return {"error": "Failed to update playlist details"} # Update tracks if provided if track_uris is not None: tracks_updated = spotify_client.replace_playlist_tracks( access_token=tokens["access_token"], playlist_id=playlist_id, track_uris=track_uris ) if not tracks_updated: return {"error": "Failed to update playlist tracks"} result["tracks_updated"] = True return result
  • Helper method in SpotifyClient class that performs the API call to update playlist metadata using Spotify's PUT /playlists/{playlist_id} endpoint.
    def update_playlist_details(self, access_token: str, playlist_id: str, name: str = None, description: str = None, public: bool = None) -> dict: """ Updates an existing playlist's details. Args: access_token: Spotify access token playlist_id: ID of the playlist to update name: New name for the playlist (optional) description: New description for the playlist (optional) public: New public/private status for the playlist (optional) Returns: Dictionary containing playlist details if successful, None otherwise """ headers = { "Authorization": f"Bearer {access_token}", "Content-Type": "application/json" } playlist_data = {} if name is not None: playlist_data["name"] = name if description is not None: playlist_data["description"] = description if public is not None: playlist_data["public"] = public response = requests.put( f"{self.base_url}/playlists/{playlist_id}", headers=headers, json=playlist_data ) if response.status_code == 200: return { "id": playlist_id, "name": name if name is not None else "", "description": description if description is not None else "", "public": public if public is not None else False, "tracks": {"total": 0}, "type": "playlist", "uri": f"spotify:playlist:{playlist_id}" } return None
  • Helper method in SpotifyClient class that replaces all tracks in a playlist using Spotify's PUT /playlists/{playlist_id}/tracks endpoint.
    def replace_playlist_tracks(self, access_token: str, playlist_id: str, track_uris: List[str]) -> bool: """ Replaces all tracks in a playlist with new ones. Args: access_token: Spotify access token playlist_id: ID of the playlist to update track_uris: New list of track URIs to replace existing tracks Returns: True if successful, False otherwise """ headers = { "Authorization": f"Bearer {access_token}", "Content-Type": "application/json" } tracks_data = { "uris": track_uris } response = requests.put( f"{self.base_url}/playlists/{playlist_id}/tracks", headers=headers, json=tracks_data ) return response.status_code == 200
  • spotify.py:97-97 (registration)
    MCP tool registration decorator that registers the update_playlist function with name 'update_playlist'.
    @mcp.tool("update_playlist")
  • Function signature with type annotations and docstring defining the input schema (parameters) and output type for the tool.
    def update_playlist(playlist_id: str, name: str = None, track_uris: List[str] = None, description: str = None, public: bool = None) -> dict: """ Update an existing Spotify playlist's details and/or tracks. Args: playlist_id: The Spotify ID of the playlist to update name: New name for the playlist (optional) track_uris: New list of track URIs to replace the playlist's tracks (optional) description: New description for the playlist (optional) public: New public/private status for the playlist (optional) """

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

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