Skip to main content
Glama
playlists.ts2.25 kB
import type { SpotifyClient } from "../spotify-client.js"; import type { Playlist, UserPlaylistsResponse } from "../types.js"; export interface CreatePlaylistParams { name: string; description?: string; public?: boolean; } export interface AddTracksToPlaylistParams { playlist_id: string; track_uris: string[]; } /** * Get user's playlists */ export async function getUserPlaylists( client: SpotifyClient, limit: number = 20 ): Promise<UserPlaylistsResponse> { const response = await client.get<UserPlaylistsResponse>("/me/playlists", { limit, }); return response; } /** * Create a new playlist */ export async function createPlaylist( client: SpotifyClient, params: CreatePlaylistParams ): Promise<Playlist> { const { name, description, public: isPublic = true } = params; // First, get the current user's ID const user = await client.get<{ id: string }>("/me"); // Create the playlist const playlist = await client.post<Playlist>( `/users/${user.id}/playlists`, { name, description: description || "", public: isPublic, } ); return playlist; } /** * Add tracks to a playlist */ export async function addTracksToPlaylist( client: SpotifyClient, params: AddTracksToPlaylistParams ): Promise<{ snapshot_id: string }> { const { playlist_id, track_uris } = params; const response = await client.post<{ snapshot_id: string }>( `/playlists/${playlist_id}/tracks`, { uris: track_uris, } ); return response; } /** * Format playlists for display */ export function formatPlaylists(response: UserPlaylistsResponse): string { if (!response.items || response.items.length === 0) { return "No playlists found."; } const lines = ["**Your Playlists:**", ""]; response.items.forEach((playlist, i) => { lines.push(`${i + 1}. **${playlist.name}**`); if (playlist.description) { lines.push(` Description: ${playlist.description}`); } lines.push(` Tracks: ${playlist.tracks.total}`); lines.push(` Public: ${playlist.public ? "Yes" : "No"}`); lines.push(` URI: ${playlist.uri}`); lines.push(` Link: ${playlist.external_urls.spotify}`); lines.push(""); }); return lines.join("\n"); }

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

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