Skip to main content
Glama
kylestratis

Spotify Playlist MCP Server

by kylestratis

spotify_create_playlist

Create a new empty Spotify playlist with custom name, description, and privacy settings. Build personalized music collections by specifying public/private visibility and collaborative options.

Instructions

Create a new empty Spotify playlist for the authenticated user.

Creates an empty playlist in the user's library. Use spotify_add_tracks_to_playlist
to add tracks after creation.

Args:
    - name: Playlist name, 1-100 characters
    - description: Optional description, max 300 characters
    - public: Whether playlist is public (default: True)
    - collaborative: Whether others can modify (default: False, cannot be True if public is True)

Returns:
    JSON: {"success": true, "playlist_id": "...", "name": "...", "url": "...", "message": "..."}

Examples:
    - "Create a new workout playlist" -> name="Workout Mix"
    - "Make a private playlist" -> name="My Mix", public=False
    - "Create collaborative playlist" -> collaborative=True, public=False

Errors: Returns error for collaborative+public, auth failure (401), missing scopes (403), rate limits (429).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
paramsYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Main handler function that executes the tool logic by calling the create_playlist_helper and formatting the JSON response.
    async def spotify_create_playlist(params: CreatePlaylistInput) -> str:
        """Create a new empty Spotify playlist for the authenticated user.
    
        Creates an empty playlist in the user's library. Use spotify_add_tracks_to_playlist
        to add tracks after creation.
    
        Args:
            - name: Playlist name, 1-100 characters
            - description: Optional description, max 300 characters
            - public: Whether playlist is public (default: True)
            - collaborative: Whether others can modify (default: False, cannot be True if public is True)
    
        Returns:
            JSON: {"success": true, "playlist_id": "...", "name": "...", "url": "...", "message": "..."}
    
        Examples:
            - "Create a new workout playlist" -> name="Workout Mix"
            - "Make a private playlist" -> name="My Mix", public=False
            - "Create collaborative playlist" -> collaborative=True, public=False
    
        Errors: Returns error for collaborative+public, auth failure (401), missing scopes (403), rate limits (429).
        """
        try:
            data = await create_playlist_helper(
                name=params.name,
                description=params.description,
                public=params.public,
                collaborative=params.collaborative,
            )
    
            return json.dumps(
                {
                    "success": True,
                    "playlist_id": data["id"],
                    "name": data["name"],
                    "url": data["external_urls"]["spotify"],
                    "message": f"Successfully created playlist '{data['name']}'",
                },
                indent=2,
            )
    
        except Exception as e:
            return handle_spotify_error(e)
  • Pydantic input schema defining parameters for creating a playlist: name, description, public, collaborative.
    class CreatePlaylistInput(BaseModel):
        """Input model for creating a playlist."""
    
        model_config = ConfigDict(str_strip_whitespace=True, validate_assignment=True)
    
        name: str = Field(
            ..., description="Name of the playlist", min_length=1, max_length=100
        )
        description: str | None = Field(
            default=None, description="Description of the playlist", max_length=300
        )
        public: bool = Field(
            default=True, description="Whether the playlist should be public"
        )
        collaborative: bool = Field(
            default=False,
            description="Whether others can modify the playlist (cannot be true if public is true)",
        )
  • server.py:169-178 (registration)
    MCP decorator registering the tool with name 'spotify_create_playlist' and metadata annotations.
    @mcp.tool(
        name="spotify_create_playlist",
        annotations={
            "title": "Create Spotify Playlist",
            "readOnlyHint": False,
            "destructiveHint": False,
            "idempotentHint": False,
            "openWorldHint": True,
        },
    )
  • Supporting helper function that makes the actual Spotify API POST request to create the user's playlist.
    async def create_playlist_helper(
        name: str,
        description: str | None = None,
        public: bool = True,
        collaborative: bool = False,
    ) -> dict[str, Any]:
        """Create a new Spotify playlist for the authenticated user.
    
        Args:
            name: Name of the playlist
            description: Optional description of the playlist
            public: Whether the playlist should be public
            collaborative: Whether others can modify the playlist
    
        Returns:
            Playlist data from Spotify API
    
        Raises:
            ValueError: If collaborative and public are both True
            httpx.HTTPStatusError: If the API request fails
        """
        if collaborative and public:
            raise ValueError("A playlist cannot be both collaborative and public")
    
        # Get current user ID
        user_data = await make_spotify_request("me")
        user_id = user_data["id"]
    
        # Create playlist
        payload = {
            "name": name,
            "public": public,
            "collaborative": collaborative,
        }
        if description:
            payload["description"] = description
    
        playlist_data = await make_spotify_request(
            f"users/{user_id}/playlists", method="POST", json=payload
        )
    
        return playlist_data
Behavior4/5

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

Annotations provide readOnlyHint=false and destructiveHint=false, but the description adds valuable behavioral context beyond this: it mentions auth failure (401), missing scopes (403), and rate limits (429) as potential errors, and clarifies the collaborative/public constraint. It doesn't contradict annotations, but could elaborate more on idempotency or open-world aspects.

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 well-structured and front-loaded with the core purpose, followed by usage guidance, parameter details, return format, examples, and errors. Every section adds value without redundancy, making it efficient and easy to parse.

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

Completeness5/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 auth and constraints), the description is complete: it covers purpose, usage, parameters, returns, examples, and errors. With an output schema present, it doesn't need to explain return values in depth, and annotations provide safety context, making this thorough.

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?

With 0% schema description coverage, the description fully compensates by detailing all parameters (name, description, public, collaborative) with constraints like character limits, defaults, and the collaborative/public rule. It adds meaning beyond the bare schema, though it doesn't explain the nested 'params' structure.

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

Purpose5/5

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

The description clearly states the specific action ('Create a new empty Spotify playlist') and resource ('for the authenticated user'), distinguishing it from siblings like spotify_add_tracks_to_playlist and spotify_get_user_playlists. It precisely defines what the tool does without being vague or tautological.

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

Usage Guidelines5/5

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

The description explicitly provides when-to-use guidance by stating 'Use spotify_add_tracks_to_playlist to add tracks after creation,' naming a specific alternative tool. It also clarifies that the playlist is created empty, setting clear expectations for usage.

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

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