spotify_playlists
Retrieve your Spotify playlists to view and manage your music collections. Get a list of your saved playlists with customizable limits for easy organization and access.
Instructions
Lista playlists do usuário
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Número máximo de playlists (padrão: 20) |
Implementation Reference
- src/tools/spotify-tools.ts:412-459 (handler)The main handler function getPlaylists() that fetches user's playlists from Spotify API, formats them into a text response, and handles errors.async getPlaylists(limit: number = 20) { try { await this.spotifyAuth.ensureValidToken(); const spotifyApi = this.spotifyAuth.getSpotifyApi(); const response = await spotifyApi.getUserPlaylists({ limit }); const playlists = response.body.items; if (playlists.length === 0) { return { content: [ { type: 'text', text: '❌ Nenhuma playlist encontrada', }, ], }; } let content = `📋 **Suas playlists:**\n\n`; playlists.forEach((playlist: any, index: number) => { content += `${index + 1}. **${playlist.name}**\n`; content += ` ID: ${playlist.id}\n`; content += ` Descrição: ${playlist.description || 'Sem descrição'}\n`; content += ` Total de músicas: ${playlist.tracks.total}\n`; content += ` Pública: ${playlist.public ? 'Sim' : 'Não'}\n`; content += ` Link: ${playlist.external_urls.spotify}\n\n`; }); return { content: [ { type: 'text', text: content, }, ], }; } catch (error) { return { content: [ { type: 'text', text: `❌ Erro ao obter playlists: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } }
- src/index.ts:177-189 (schema)Input schema for the spotify_playlists tool, specifying an optional 'limit' parameter.{ name: 'spotify_playlists', description: 'Lista playlists do usuário', inputSchema: { type: 'object', properties: { limit: { type: 'number', description: 'Número máximo de playlists (padrão: 20)', }, }, }, },
- src/index.ts:292-294 (registration)Registers the tool handler in the CallToolRequestSchema switch statement, delegating to spotifyTools.getPlaylists().case 'spotify_playlists': return await spotifyTools.getPlaylists(args.limit);
- src/index.ts:30-32 (registration)Instantiates the SpotifyTools class which contains the tool implementations.const spotifyAuth = new SpotifyAuth(config); const spotifyTools = new SpotifyTools(spotifyAuth);
- src/types/index.ts:35-50 (schema)TypeScript interface defining the structure of a Spotify playlist, used in the codebase.export interface SpotifyPlaylist { id: string; name: string; description: string; owner: { display_name: string; }; tracks: { total: number; }; images: Array<{ url: string; width: number; height: number; }>; }