spotify_current_playing
Retrieve information about the currently playing song on Spotify, including track details, artist, and playback status.
Instructions
Obtém informações sobre a música que está tocando
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/spotify-tools.ts:306-356 (handler)The core handler function that checks authentication, calls Spotify's getMyCurrentPlayingTrack API, formats the track info (name, artists, album, duration, progress, link), handles no track case, and returns formatted text content or error.async getCurrentPlaying() { try { await this.spotifyAuth.ensureValidToken(); const spotifyApi = this.spotifyAuth.getSpotifyApi(); const response = await spotifyApi.getMyCurrentPlayingTrack(); const track = response.body.item; if (!track) { return { content: [ { type: 'text', text: '❌ Nenhuma música está tocando no momento', }, ], }; } const artists = track.artists.map((a: any) => a.name).join(', '); const duration = Math.floor(track.duration_ms / 60000); const durationSeconds = Math.floor((track.duration_ms % 60000) / 1000); const progress = Math.floor((response.body.progress_ms || 0) / 60000); const progressSeconds = Math.floor(((response.body.progress_ms || 0) % 60000) / 1000); let content = `🎵 **Música atual:**\n\n`; content += `**${track.name}** - ${artists}\n`; content += `Álbum: ${track.album.name}\n`; content += `Duração: ${duration}:${String(durationSeconds).padStart(2, '0')}\n`; content += `Progresso: ${progress}:${String(progressSeconds).padStart(2, '0')}\n`; content += `Link: ${track.external_urls.spotify}\n`; return { content: [ { type: 'text', text: content, }, ], }; } catch (error) { return { content: [ { type: 'text', text: `❌ Erro ao obter música atual: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } }
- src/index.ts:161-168 (registration)Tool registration in the ListToolsRequestHandler response, defining the tool name, description, and empty input schema (no parameters required).{ name: 'spotify_current_playing', description: 'Obtém informações sobre a música que está tocando', inputSchema: { type: 'object', properties: {}, }, },
- src/index.ts:286-287 (registration)Dispatch registration in the CallToolRequestHandler switch statement, routing calls to this tool name to the spotifyTools.getCurrentPlaying() method.case 'spotify_current_playing': return await spotifyTools.getCurrentPlaying();
- src/index.ts:164-167 (schema)Input schema definition for the tool: an empty object (no input parameters required).inputSchema: { type: 'object', properties: {}, },