create_playlist
Create a new Spotify playlist by specifying a name, optional description, and privacy setting. Use this tool to organize and manage your music collection directly on Spotify.
Instructions
Create a new Spotify playlist.
Args:
name: Playlist name
description: Playlist description
public: Whether playlist is public
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| description | No | ||
| name | Yes | ||
| public | No |
Implementation Reference
- MCP tool handler for 'create_playlist'. Decorated with @mcp.tool() for automatic registration and schema inference from type hints. Implements playlist creation using spotipy.Spotify.user_playlist_create and returns structured data via Playlist model.@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 output schema for playlist data, used by create_playlist 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:424-424 (registration)FastMCP decorator @mcp.tool() that registers the create_playlist function as an MCP tool, inferring schema from type annotations.@mcp.tool()
- Helper method in SpotifyClient that wraps spotipy.user_playlist_create, providing logging and parsing (not directly called 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