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
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | ||
| description | No | ||
| public | No |
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
- src/spotify_mcp/fastmcp_server.py:513-513 (registration)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