Skip to main content
Glama

create_playlist

Create a new Spotify playlist with specified tracks, name, description, and privacy settings using the Spotify Model Context Protocol.

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

Implementation Reference

  • spotify.py:34-34 (registration)
    Registration of the create_playlist tool using the @mcp.tool decorator
    @mcp.tool("create_playlist")
  • Handler function that performs authentication/refresh and calls the SpotifyClient to create the 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 )
  • Core implementation that makes Spotify API calls to create a playlist and add 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
  • Input schema defined by function signature and docstring describing parameters.
    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) """

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