Skip to main content
Glama
belljustin

Spotify Model Context Protocol

by belljustin

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)
        """
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but offers minimal behavioral insight. It implies mutation ('update') but doesn't disclose critical traits like authentication requirements, rate limits, whether changes are reversible, or what happens to unspecified fields. This is inadequate for a mutation tool with zero annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded with a clear purpose statement. The parameter explanations are structured in a list format, making it easy to scan, though it could be slightly more concise by integrating the parameter details into the opening sentence.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (mutation with 5 parameters), lack of annotations, and no output schema, the description is incomplete. It misses critical context like authentication needs, error handling, return values, and usage scenarios, leaving significant gaps for an AI agent to operate effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds significant value beyond the input schema, which has 0% description coverage. It explains the meaning of all 5 parameters (e.g., 'playlist_id' as Spotify ID, 'track_uris' as replacement list) and clarifies optionality, compensating well for the schema's lack of descriptions.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'update' and resource 'Spotify playlist's details and/or tracks', making the purpose explicit. However, it doesn't distinguish this tool from its sibling 'create_playlist' beyond the obvious 'existing' vs 'new' difference, missing explicit differentiation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives like 'create_playlist' or 'get_track_uris'. The description lacks context about prerequisites, such as needing playlist ownership or specific permissions, and doesn't mention any exclusions or best practices.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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