getNowPlaying
Retrieve details of the currently playing Spotify track, including title, artist, and album information.
Instructions
Get information about the currently playing track on Spotify
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/read.ts:127-194 (handler)Full tool definition including name, description, empty schema (no inputs), and handler function. The handler fetches the currently playing track using Spotify API, validates it's a track, formats artist, album, progress, duration, and returns formatted text response.const getNowPlaying: tool<Record<string, never>> = { name: 'getNowPlaying', description: 'Get information about the currently playing track on Spotify', schema: {}, handler: async (args, extra: SpotifyHandlerExtra) => { try { const currentTrack = await handleSpotifyRequest(async (spotifyApi) => { return await spotifyApi.player.getCurrentlyPlayingTrack(); }); if (!currentTrack || !currentTrack.item) { return { content: [ { type: 'text', text: 'Nothing is currently playing on Spotify', }, ], }; } const item = currentTrack.item; if (!isTrack(item)) { return { content: [ { type: 'text', text: 'Currently playing item is not a track (might be a podcast episode)', }, ], }; } const artists = item.artists.map((a) => a.name).join(', '); const album = item.album.name; const duration = formatDuration(item.duration_ms); const progress = formatDuration(currentTrack.progress_ms || 0); const isPlaying = currentTrack.is_playing; return { content: [ { type: 'text', text: `# Currently ${isPlaying ? 'Playing' : 'Paused'}\n\n` + `**Track**: "${item.name}"\n` + `**Artist**: ${artists}\n` + `**Album**: ${album}\n` + `**Progress**: ${progress} / ${duration}\n` + `**ID**: ${item.id}`, }, ], }; } catch (error) { return { content: [ { type: 'text', text: `Error getting current track: ${ error instanceof Error ? error.message : String(error) }`, }, ], }; } }, };
- src/read.ts:521-529 (registration)getNowPlaying is included in the readTools array which groups read-related tools.export const readTools = [ searchSpotify, getNowPlaying, getUserPlaylists, getPlaylistTracks, getRecentlyPlayed, getFollowedArtists, getUserTopItems, ];
- src/index.ts:12-14 (registration)All tools from playTools, readTools, writeTools are registered on the MCP server using server.tool() in a loop.[...playTools, ...readTools, ...writeTools].forEach((tool) => { server.tool(tool.name, tool.description, tool.schema, tool.handler); });
- src/read.ts:6-14 (helper)Helper function used in getNowPlaying handler to validate if the playing item is a track.function isTrack(item: any): item is SpotifyTrack { return ( item && item.type === 'track' && Array.isArray(item.artists) && item.album && typeof item.album.name === 'string' ); }