Skip to main content
Glama
belljustin

Spotify Model Context Protocol

by belljustin

create_playlist

Create a new Spotify playlist with specified tracks, name, description, and privacy settings using the Spotify Model Context Protocol.

Instructions

Create a new playlist on Spotify and add tracks to it.

Args:
    name: Name of the playlist
    track_uris: List of Spotify track URIs to add to the playlist
    description: Optional description for the playlist
    public: Whether the playlist should be public (default: False)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYes
track_urisYes
descriptionNo
publicNo

Implementation Reference

  • spotify.py:34-34 (registration)
    Registration of the create_playlist tool using the @mcp.tool decorator
    @mcp.tool("create_playlist")
  • Handler function that performs authentication/refresh and calls the SpotifyClient to create the playlist.
    def create_playlist(name: str, track_uris: List[str], description: str = "", public: bool = False) -> dict:
        """
        Create a new playlist on Spotify and add tracks to it.
    
        Args:
            name: Name of the playlist
            track_uris: List of Spotify track URIs to add to the playlist
            description: Optional description for the playlist
            public: Whether the playlist should be public (default: False)
        """
        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))
        
        return spotify_client.create_playlist_with_tracks(
            access_token=tokens["access_token"],
            user_id=user_id,
            name=name,
            track_uris=track_uris,
            description=description
        )
  • Core implementation that makes Spotify API calls to create a playlist and add tracks to it.
    def create_playlist_with_tracks(self, access_token: str, user_id: str, name: str, track_uris: List[str], description: str = "") -> dict:
        """
        Creates a private playlist and adds the specified tracks to it.
        
        Args:
            access_token: Spotify access token
            user_id: Spotify user ID
            name: Name of the playlist
            track_uris: List of Spotify track URIs to add
            description: Optional playlist description
            
        Returns:
            The created playlist data if successful, None otherwise
        """
        headers = {
            "Authorization": f"Bearer {access_token}",
            "Content-Type": "application/json"
        }
        
        # Create the playlist
        playlist_data = {
            "name": name,
            "description": description,
            "public": False
        }
        
        response = requests.post(
            f"{self.base_url}/users/{user_id}/playlists",
            headers=headers,
            json=playlist_data
        )
        
        if response.status_code != 201:
            return None
            
        playlist = response.json()
        
        # Add tracks to the playlist
        tracks_data = {
            "uris": track_uris
        }
        
        response = requests.post(
            f"{self.base_url}/playlists/{playlist['id']}/tracks",
            headers=headers,
            json=tracks_data
        )
        
        return playlist if response.status_code == 201 else None
  • Input schema defined by function signature and docstring describing parameters.
    def create_playlist(name: str, track_uris: List[str], description: str = "", public: bool = False) -> dict:
        """
        Create a new playlist on Spotify and add tracks to it.
    
        Args:
            name: Name of the playlist
            track_uris: List of Spotify track URIs to add to the playlist
            description: Optional description for the playlist
            public: Whether the playlist should be public (default: False)
        """
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 only states it 'creates a new playlist and adds tracks'. It lacks behavioral details such as authentication requirements, rate limits, error handling, or whether the operation is idempotent, which are critical for a mutation tool.

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

Conciseness5/5

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

The description is front-loaded with the core purpose in the first sentence, followed by a structured 'Args' list that efficiently details parameters. Every sentence adds value without redundancy, making it easy to scan and understand quickly.

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

Completeness3/5

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

For a mutation tool with no annotations and no output schema, the description covers the basic operation and parameters adequately but lacks critical context like return values, error cases, or side effects. It's minimally viable but has clear gaps in behavioral transparency.

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 includes an 'Args' section that explains each parameter's purpose (e.g., 'name: Name of the playlist', 'public: Whether the playlist should be public'), adding meaningful context beyond the schema's 0% description coverage. It clarifies defaults and optionality, compensating well for the schema gap.

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 'Create' and resource 'new playlist on Spotify', specifying that tracks are added to it. It distinguishes from siblings like 'update_playlist' by focusing on creation rather than modification, though it doesn't explicitly contrast with 'get_track_uris'.

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?

The description provides no guidance on when to use this tool versus alternatives like 'update_playlist' or 'get_track_uris'. It mentions adding tracks but doesn't specify prerequisites (e.g., needing track URIs first) or contextual constraints, leaving usage decisions ambiguous.

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