Skip to main content
Glama
jamiew

Spotify MCP Server

create_playlist

Create a new Spotify playlist by specifying name, description, and privacy settings to organize your music collection.

Instructions

Create a new Spotify playlist.

Args:
    name: Playlist name
    description: Playlist description (default: empty)
    public: Whether playlist is public (default: True)

Returns:
    Dict with created playlist information

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYes
descriptionNo
publicNo

Implementation Reference

  • Primary handler function for the 'create_playlist' MCP tool. Decorated with @mcp.tool() which handles registration and automatic schema generation from type hints. Directly calls Spotify API to create and return structured playlist info.
    @mcp.tool()
    @log_tool_execution
    def create_playlist(
        name: str, description: str = "", public: bool = True
    ) -> dict[str, Any]:
        """Create a new Spotify playlist.
    
        Args:
            name: Playlist name
            description: Playlist description (default: empty)
            public: Whether playlist is public (default: True)
    
        Returns:
            Dict with created playlist information
        """
        try:
            logger.info(f"🎧 Creating playlist: '{name}' (public={public})")
            user = spotify_client.current_user()
            result = spotify_client.user_playlist_create(
                user["id"], name, public=public, description=description
            )
    
            playlist = Playlist(
                name=result["name"],
                id=result["id"],
                owner=result.get("owner", {}).get("display_name"),
                description=result.get("description"),
                tracks=[],
                total_tracks=0,
                public=result.get("public"),
            )
    
            return playlist.model_dump()
    
        except SpotifyException as e:
            raise convert_spotify_error(e) from e
  • Pydantic model defining the structured output schema for the create_playlist tool and other playlist-related tools.
    class Playlist(BaseModel):
        """A Spotify playlist."""
    
        name: str
        id: str
        owner: str | None = None
        description: str | None = None
        tracks: list[Track] | None = None
        total_tracks: int | None = None
        public: bool | None = None
  • FastMCP decorator @mcp.tool() that registers the create_playlist function as an MCP tool, inferring input schema from annotations.
    @mcp.tool()
  • Supporting helper method in SpotifyClient class for creating playlists, wrapping spotipy API call (not directly used by MCP handler).
    def create_playlist(
        self, user_id: str, name: str, description: str = "", public: bool = False
    ) -> dict[str, Any]:
        """Create a new playlist"""
        try:
            self.logger.info(f"Creating playlist '{name}' for user {user_id}")
            self.logger.info(f"Description: {description}, Public: {public}")
    
            playlist = self.sp.user_playlist_create(
                user_id, name, public=public, description=description
            )
            playlist_info = utils.parse_playlist(playlist, detailed=True)
    
            if playlist_info:
                self.logger.info(
                    f"Successfully created playlist. ID: {playlist_info.get('id', 'Unknown')}"
                )
            else:
                self.logger.warning("Created playlist but received empty playlist info")
    
            return playlist_info if playlist_info else {}
        except Exception as e:
            self.logger.error(f"Error creating playlist: {str(e)}", exc_info=True)
            raise

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

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