Skip to main content
Glama

create_playlist

Generate and customize Spotify playlists by specifying a name, track URIs, optional description, and privacy settings. Integrates with Spotify's API for streamlined playlist creation.

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
descriptionNo
nameYes
publicNo
track_urisYes

Implementation Reference

  • The main MCP tool handler function for 'create_playlist'. It handles user authentication, token refresh if expired, retrieves user tokens, and calls the SpotifyClient helper to create the playlist with tracks.
    @mcp.tool("create_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 )
  • spotify.py:34-34 (registration)
    The @mcp.tool decorator registers the 'create_playlist' function as an MCP tool.
    @mcp.tool("create_playlist")
  • Helper method in SpotifyClient class that implements the core logic: creates a new private Spotify playlist via API and adds the provided 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
  • Function signature with type annotations and docstring defining the input schema and parameters for the create_playlist tool.
    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) """

Other Tools

Related 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